Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100503
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
| Newsgroups | comp.lang.python |
| Subject | Re: Help on error " ValueError: For numerical factors, num_columns must be an int " |
| Date | Wed, 16 Dec 2015 11:33:39 +0000 |
| Lines | 93 |
| Message-ID | <mailman.7.1450265638.30845.python-list@python.org> (permalink) |
| References | <cb78beb6-7a28-4bb5-8215-8771f1f324e3@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de rkYRbben5C7/fmYctBGEQQsLn3fIDKXBzib7UC7pKI6w== |
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'skip:[ 20': 0.03; 'error:': 0.05; 'from:addr:yahoo.co.uk': 0.05; 'none:': 0.05; 'type,': 0.07; 'valueerror:': 0.07; 'int):': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'skip:[ 40': 0.09; 'skip:c 80': 0.09; 'type:': 0.09; 'valueerror': 0.09; 'subject:Help': 0.10; 'subject:error': 0.11; 'subject: \n ': 0.15; '153': 0.16; 'df,': 0.16; 'last)': 0.16; 'numpy': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'skip:3 30': 0.16; 'skip:[ 60': 0.16; 'wrote:': 0.16; 'numerical': 0.18; 'skip:= 10': 0.18; 'thanks.': 0.18; 'language': 0.19; 'lawrence': 0.22; 'skip:= 20': 0.22; 'code,': 0.23; 'import': 0.24; '(most': 0.24; 'skip:b 30': 0.24; 'header:In-Reply-To:1': 0.24; 'header :User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'figure': 0.27; 'error': 0.27; 'data,': 0.27; 'skip:e 30': 0.27; 'factor': 0.29; 'raise': 0.29; 'skip:_ 10': 0.32; 'language.': 0.32; 'run': 0.33; 'problem': 0.33; 'skip:_ 30': 0.33; 'int': 0.33; 'traceback': 0.33; 'me?': 0.34; 'skip:d 20': 0.34; 'robert': 0.35; 'skip:i 20': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'missing': 0.37; 'skip:p 20': 0.38; 'hi,': 0.38; 'to:addr:python.org': 0.40; 'where': 0.40; 'mark': 0.40; 'engine': 0.62; 'charset:windows-1252': 0.62; 'is.': 0.63; 'our': 0.64; 'state,': 0.66; 'subject:For': 0.81; '--->': 0.84; '..........': 0.84; '152': 0.84; '295': 0.84; '299': 0.84; 'patsy': 0.84; 'pythonistas,': 0.84; 'factors,': 0.91; '150': 0.93; 'outcome': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | 212.88.46.83 |
| User-Agent | Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 |
| In-Reply-To | <cb78beb6-7a28-4bb5-8215-8771f1f324e3@googlegroups.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:100503 |
Show key headers only | View raw
On 16/12/2015 10:44, Robert wrote:
> Hi,
>
> When I run the following code, there is an error:
>
> ValueError: For numerical factors, num_columns must be an int
>
>
> ================
> import numpy as np
> import pandas as pd
> from patsy import dmatrices
> from sklearn.linear_model import LogisticRegression
>
> X = [0.5,0.75,1.0,1.25,1.5,1.75,1.75,2.0,2.25,2.5,2.75,3.0,3.25,
> 3.5,4.0,4.25,4.5,4.75,5.0,5.5]
> y = [0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,1,1,1,1,1]
>
> zipped = list(zip(X,y))
> df = pd.DataFrame(zipped,columns = ['study_hrs','p_or_f'])
>
> y, X = dmatrices('p_or_f ~ study_hrs', df, return_type="dataframe")
> =======================
>
> I have check 'df' is this type:
> =============
> type(df)
> Out[25]: pandas.core.frame.DataFrame
> =============
>
> I cannot figure out where the problem is. Can you help me?
> Thanks.
>
> Error message:
> ..........
>
>
> ---------------------------------------------------------------------------
> ValueError Traceback (most recent call last)
> C:\Users\rj\pyprj\stackoverflow_logisticregression0.py in <module>()
> 17 df = pd.DataFrame(zipped,columns = ['study_hrs','p_or_f'])
> 18
> ---> 19 y, X = dmatrices('p_or_f ~ study_hrs', df, return_type="dataframe")
> 20
> 21 y = np.ravel(y)
>
> C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\highlevel.pyc in dmatrices(formula_like, data, eval_env, NA_action, return_type)
> 295 eval_env = EvalEnvironment.capture(eval_env, reference=1)
> 296 (lhs, rhs) = _do_highlevel_design(formula_like, data, eval_env,
> --> 297 NA_action, return_type)
> 298 if lhs.shape[1] == 0:
> 299 raise PatsyError("model is missing required outcome variables")
>
> C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\highlevel.pyc in _do_highlevel_design(formula_like, data, eval_env, NA_action, return_type)
> 150 return iter([data])
> 151 design_infos = _try_incr_builders(formula_like, data_iter_maker, eval_env,
> --> 152 NA_action)
> 153 if design_infos is not None:
> 154 return build_design_matrices(design_infos, data,
>
> C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\highlevel.pyc in _try_incr_builders(formula_like, data_iter_maker, eval_env, NA_action)
> 55 data_iter_maker,
> 56 eval_env,
> ---> 57 NA_action)
> 58 else:
> 59 return None
>
> C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\build.pyc in design_matrix_builders(termlists, data_iter_maker, eval_env, NA_action)
> 704 factor_states[factor],
> 705 num_columns=num_column_counts[factor],
> --> 706 categories=None)
> 707 else:
> 708 assert factor in cat_levels_contrasts
>
> C:\Users\rj\AppData\Local\Enthought\Canopy\User\lib\site-packages\patsy\design_info.pyc in __init__(self, factor, type, state, num_columns, categories)
> 86 if self.type == "numerical":
> 87 if not isinstance(num_columns, int):
> ---> 88 raise ValueError("For numerical factors, num_columns "
> 89 "must be an int")
> 90 if categories is not None:
>
> ValueError: For numerical factors, num_columns must be an int
>
Slap the ValueError into a search engine and the first hit is
https://groups.google.com/forum/#!topic/pystatsmodels/KcSzNqDxv-Q
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Help on error " ValueError: For numerical factors, num_columns must be an int " Robert <rxjwg98@gmail.com> - 2015-12-16 02:44 -0800
Re: Help on error " ValueError: For numerical factors, num_columns must be an int " Robert <rxjwg98@gmail.com> - 2015-12-16 02:56 -0800
Re: Help on error " ValueError: For numerical factors, num_columns must be an int " Robert <rxjwg98@gmail.com> - 2015-12-16 03:03 -0800
Re: Help on error " ValueError: For numerical factors, num_columns must be an int " Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-12-16 11:33 +0000
Re: Help on error " ValueError: For numerical factors, num_columns must be an int " Robert <rxjwg98@gmail.com> - 2015-12-16 06:50 -0800
Re: Help on error " ValueError: For numerical factors, num_columns must be an int " Josef Pktd <josef.pktd@gmail.com> - 2015-12-16 17:57 -0800
Re: Help on error " ValueError: For numerical factors, num_columns must be an int " Robert <rxjwg98@gmail.com> - 2015-12-16 18:37 -0800
csiph-web