Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 在scikit learn Isotonic Regression.score中,有限浮点数被误认为nan/inf_Python 2.7_Scikit Learn - Fatal编程技术网

Python 2.7 在scikit learn Isotonic Regression.score中,有限浮点数被误认为nan/inf

Python 2.7 在scikit learn Isotonic Regression.score中,有限浮点数被误认为nan/inf,python-2.7,scikit-learn,Python 2.7,Scikit Learn,scikit学习等渗回归类的评分方法似乎出现故障 我给它输入了非常精细的浮点数数组,fit方法不会引发任何异常,然后score方法会引发以下错误: .../anaconda/lib/python2.7/site-packages/scipy/interpolate/interpolate.py:445: RuntimeWarning: invalid value encountered in true_divide slope = (y_hi - y_lo) / (x_hi - x_lo)[:,

scikit学习等渗回归类的评分方法似乎出现故障

我给它输入了非常精细的浮点数数组,fit方法不会引发任何异常,然后score方法会引发以下错误:

.../anaconda/lib/python2.7/site-packages/scipy/interpolate/interpolate.py:445: RuntimeWarning: invalid value encountered in true_divide
slope = (y_hi - y_lo) / (x_hi - x_lo)[:, None]
Traceback (most recent call last):
File "iostonic_error.py", line 20, in <module>
print model.score(x_1d,y_1d)
File ".../anaconda/lib/python2.7/site-packages/sklearn/base.py", line 324, in score
return r2_score(y, self.predict(X), sample_weight=sample_weight)
File ".../anaconda/lib/python2.7/site-packages/sklearn/metrics/metrics.py", line 2324, in r2_score
y_type, y_true, y_pred = _check_reg_targets(y_true, y_pred)
File ".../anaconda/lib/python2.7/site-packages/sklearn/metrics/metrics.py", line 65, in _check_reg_targets
y_true, y_pred = check_arrays(y_true, y_pred)
File ".../anaconda/lib/python2.7/site-packages/sklearn/utils/validation.py", line 283, in check_arrays
_assert_all_finite(array)
File ".../anaconda/lib/python2.7/site-packages/sklearn/utils/validation.py", line 43, 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').
我查看了源代码,发现此错误消息来自sklearn.utils.validations.\u assert\u all\u finite 作为测试,在输入数据(x_1d和y_1d)上使用该函数的精确代码,我正在为回归类提供数据。它没有引发任何异常,这让我相信,在某种程度上,score方法操纵数据的方式会破坏数据,并引入缺失值或np.inf值


有人知道是什么导致了这种情况吗?

您使用的是哪个版本的scikit learn?我想这个问题最近已经解决了。你能检查一下“model.predict(x_1d)”是否也给出inf或nan吗?这个问题在scikit learn(0.16)的“beta”版本中得到了修复,但在0.15中没有
from sklearn.isotonic import IsotonicRegression

x_1d = [ 3.97948718,4.,2.,2.97948718,4.48974359,4.46923077, 2.,3.46923077,4.46923077,4.46923077,3.97948718,3.97948718, 5.46923077,3.,2.48974359]
y_1d = [ 19.,9.,27.,27.,12.,17.,34.,30.,23.,25.,18.,21.,11.,24.,33.]

model = IsotonicRegression(y_min=0, increasing=False, out_of_bounds='clip')

model.fit(x_1d,y_1d)

print model.score(x_1d,y_1d)