我正在练习贷款预测练习问题并尝试填充数据中的缺失值。我从here获得数据。为了完成这个问题,我正在关注这个tutorial。ValueError:输入包含NaN,无穷大或者对于dtype('float64')来说值太大
您可以找到我使用的整个代码(文件名称model.py)和关于GitHub的数据。
数据框看起来是这样的:
执行的最后一行后(相当于在model.py文件到线122)
/home/user/.local/lib/python2.7/site-packages/numpy/lib/arraysetops.py:216: FutureWarning: numpy not_equal will not check object identity in the future. The comparison did not return the same result as suggested by the identity (`is`)) and will change.
flag = np.concatenate(([True], aux[1:] != aux[:-1]))
/usr/local/lib/python2.7/dist-packages/sklearn/cross_validation.py:44: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.
"This module will be removed in 0.20.", DeprecationWarning)
Traceback (most recent call last):
File "model.py", line 123, in <module>
classification_model(model, df,predictor_var,outcome_var)
File "model.py", line 89, in classification_model
model.fit(data[predictors],data[outcome])
File "/usr/local/lib/python2.7/dist-packages/sklearn/linear_model/logistic.py", line 1173, in fit
order="C")
File "/usr/local/lib/python2.7/dist-packages/sklearn/utils/validation.py", line 521, in check_X_y
ensure_min_features, warn_on_dtype, estimator)
File "/usr/local/lib/python2.7/dist-packages/sklearn/utils/validation.py", line 407, in check_array
_assert_all_finite(array)
File "/usr/local/lib/python2.7/dist-packages/sklearn/utils/validation.py", line 58, in _assert_all_finite
" or a value too large for %r." % X.dtype)
ValueError: Input contains NaN, infinity or a value too large for dtype('float64').
我得到这个错误,因为的缺失值。我如何填写这些缺失的值?
缺少的值Self_Employed和LoanAmount充满我怎么填rest.Thank你的帮助。
是否要用标量值替换'NaN'?然后使用'df ['colname']。fillna(val,inplace = True)' – jezrael
@jezrael关于性别和结婚等对象类型怎么样 – Aniruddh
我认为最好的方法是将其重新赋值给'df ['Gender']。 fillna('no data',inplace = True)'和'df [Married']。fillna('no data',inplace = True)' – jezrael