alphas_ 数组,形状 (n_alphas + 1,) 最大协方差(在绝对值)在每次迭代.n_alphas 要么是 max_iter,n_features,或路径中具有相关性的节点数大于 alpha,以较小者为准.所以我们以上面大小为 ndims+1(即 n_features+1)的 alphas_ 结尾是有道理的.附言用 sklearn 0.17.1 和 positive=True 测试,也用一些正负系数测试,结果相同:alphas_ 是 ndims+1 或更少.This is a scikit-learn error that I get when I domy_estimator = LassoLarsCV(fit_intercept=False, normalize=False, positive=True, max_n_alphas=1e5)Note that if I decrease max_n_alphas from 1e5 down to 1e4 I do not get this error any more.Anyone has an idea on what's going on?The error happens when I callmy_estimator.fit(x, y)I have 40k data points in 40 dimensions.The full stack trace looks like this 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. 解决方案 There must be something particular to your data. LassoLarsCV() seems to be working correctly with this synthetic example of fairly well-behaved data:import numpyimport sklearn.linear_model# create 40000 x 40 sample data from linear model with a bit of noisenpoints = 40000ndims = 40numpy.random.seed(1)X = numpy.random.random((npoints, ndims))w = numpy.random.random(ndims)y = X.dot(w) + numpy.random.random(npoints) * 0.1clf = 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.00377print max(abs( clf.coef_ - w ))# alphas actually used are 41 or ndims+1print clf.alphas_.shapeThis is in sklearn 0.16, I don't have positive=True option.I'm not sure why you would want to use a very large max_n_alphas anyway. While I don't know why 1e+4 works and 1e+5 doesn't in your case, I suspect the paths you get from max_n_alphas=ndims+1 and max_n_alphas=1e+4 or whatever would be identical for well behaved data. Also the optimal alpha that is estimated by cross-validation in clf.alpha_ is going to be identical. Check out Lasso path using LARS example for what alpha is trying to do.Also, from the LassoLars documentation alphas_ array, shape (n_alphas + 1,) Maximum of covariances (in absolute value) at each iteration. n_alphas is either max_iter, n_features, or the number of nodes in the path with correlation greater than alpha, whichever is smaller.so it makes sense that we end with alphas_ of size ndims+1 (ie n_features+1) above.P.S. Tested with sklearn 0.17.1 and positive=True as well, also tested with some positive and negative coefficients, same result: alphas_ is ndims+1 or less. 这篇关于ValueError:x_new 中的值低于插值范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-03 18:01
查看更多