pandas Python 3 statsmodels Logit ValueError:在进入 DLASCL 参数编号 5 时有一个非法值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39843179/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python 3 statsmodels Logit ValueError: On entry to DLASCL parameter number 5 had an illegal value
提问by JMH
Working through a logistic regression example and encountering some difficulties when approaching the statsmodels portion. I have difficulties in the past with Python 3 and pandas dataframes where the df returns an iterator not a list. I have tried adjusting the same with 'logit' however still receiving a ValueError
通过逻辑回归示例并在接近 statsmodels 部分时遇到一些困难。过去我在使用 Python 3 和 Pandas 数据帧时遇到困难,其中 df 返回迭代器而不是列表。我已经尝试使用“logit”进行相同的调整,但仍然收到 ValueError
import numpy as np
import pandas as pd
import os
import statsmodels.api as sm
import pylab as pl
df = pd.read_csv('admissions.csv')
df.head(n=5)
df.columns = ['admit', 'gre', 'gpa', 'prestige']
dummy_ranks = pd.get_dummies(df['prestige'], prefix='prestige')
cols_to_keep = ['admit', 'gre', 'gpa']
data = df[cols_to_keep].join(dummy_ranks.ix[:, 'prestige_2':])
data['intercept'] = 1.0
train_cols = data.columns[1:]
logit = sm.Logit(data['admit'], data[train_cols])
result = logit.fit()
ValueError: On entry to DLASCL parameter number 5 had an illegal value
ValueError: 在进入 DLASCL 参数 5 时有一个非法值
回答by Michael Williams
Your 'admissions.csv' has a blank value in it.
您的“admissions.csv”中有一个空白值。
Using the data from http://www.ats.ucla.edu/stat/data/binary.csvas per the blog http://blog.yhat.com/posts/logistic-regression-python-rodeo.htmlworks. Try deleting a value in the data and you will get the illegal value error.
根据博客http://blog.yhat.com/posts/logistic-regression-python-rodeo.html使用来自http://www.ats.ucla.edu/stat/data/binary.csv的数据有效。尝试删除数据中的值,您将收到非法值错误。
Correct:
正确的:
admit gre gpa rank
0 380 3.61 3
1 520 2.93 4
Incorrect:
不正确:
admit gre gpa rank
0 3.61 3
1 520 2.93 4