7

这是我在执行时遇到的 scikit-learn 错误

my_estimator = LassoLarsCV(fit_intercept=False, normalize=False, positive=True, max_n_alphas=1e5)

请注意,如果我将 max_n_alphas 从 1e5 降低到 1e4,我将不再收到此错误。

有人知道发生了什么吗?

当我打电话时发生错误

my_estimator.fit(x, y)

我有维度的40k数据点。40

完整的堆栈跟踪如下所示

  File "/usr/lib64/python2.7/site-packages/sklearn/linear_model/least_angle.py", line 1113, in fit
    axis=0)(all_alphas)
  File "/usr/lib64/python2.7/site-packages/scipy/interpolate/polyint.py", line 79, in __call__
    y = self._evaluate(x)
  File "/usr/lib64/python2.7/site-packages/scipy/interpolate/interpolate.py", line 498, in _evaluate
    out_of_bounds = self._check_bounds(x_new)
  File "/usr/lib64/python2.7/site-packages/scipy/interpolate/interpolate.py", line 525, in _check_bounds
    raise ValueError("A value in x_new is below the interpolation "
ValueError: A value in x_new is below the interpolation range.
4

1 回答 1

5

您的数据必须有一些特殊的东西。 LassoLarsCV()似乎可以正常使用这个表现良好的数据的综合示例:

import numpy
import sklearn.linear_model

# create 40000 x 40 sample data from linear model with a bit of noise
npoints = 40000
ndims = 40
numpy.random.seed(1)
X = numpy.random.random((npoints, ndims))
w = numpy.random.random(ndims)
y = X.dot(w) + numpy.random.random(npoints) * 0.1

clf = sklearn.linear_model.LassoLarsCV(fit_intercept=False, normalize=False, max_n_alphas=1e6)
clf.fit(X, y)

# coefficients are almost exactly recovered, this prints 0.00377
print max(abs( clf.coef_ - w ))

# alphas actually used are 41 or ndims+1
print clf.alphas_.shape

这是 sklearn 0.16,我没有positive=True选择。

我不确定你为什么要使用非常大的 max_n_alphas 。虽然我不知道为什么 1e+4 有效而 1e+5 在您的情况下无效,但我怀疑您从 max_n_alphas=ndims+1 和 max_n_alphas=1e+4 获得的路径或对于表现良好的数据而言是相同的路径。此外,通过交叉验证估计的最佳 alpha 将clf.alpha_是相同的。查看使用 LARS 示例的套索路径,了解 alpha 正在尝试做什么。

此外,来自 LassoLars文档

alphas_ 数组,形状 (n_alphas + 1,)

每次迭代的最大协方差(绝对值)。n_alphas 是 max_iter、n_features 或路径中相关性大于 alpha 的节点数,以较小者为准。

因此,我们以上面大小为 ndims+1(即 n_features+1)的 alphas_ 结尾是有道理的。

PS 用 sklearn 0.17.1 和 positive=True 测试,也用一些正负系数测试,结果相同:alphas_ 是 ndims+1 或更少。

于 2016-04-04T10:41:18.437 回答