我想得到这些情节: http://scikit-learn.org/stable/auto_examples/linear_model/plot_lasso_coordinate_descent_path.html
来自我已经训练过的弹性网。 这个例子是
from sklearn.linear_model import lasso_path, enet_path
from sklearn import datasets
diabetes = datasets.load_diabetes()
X = diabetes.data
print("Computing regularization path using the elastic net...")
alphas_enet, coefs_enet, _ = enet_path(
X, y, eps=eps, l1_ratio=0.8, fit_intercept=False)
基本上需要从X,y
整个模型重新计算。
不幸的是,我没有X,y
。
在培训中,我使用sklearn.linear_model.ElasticNetCV
返回:
coef_ : array, shape (n_features,) | (n_targets, n_features)
parameter vector (w in the cost function formula)
mse_path_ : array, shape (n_l1_ratio, n_alpha, n_folds)
Mean square error for the test set on each fold, varying l1_ratio and alpha.
虽然我需要参数向量变化l1_ratio和alpha。
这可以在没有重新计算的情况下完成吗?由于那些coef_paths实际上已经计算过,这将是一个巨大的浪费时间
答案 0 :(得分:1)
不适合。
如果您查看ElasticNetCV
的源代码,您会看到该类在fit方法中调用enet_path
,但alphas
设置为初始化的alpha值ElasticNet
(默认值1.0),由ElasticNetCV
中的alpha值设置,最终为单个值。因此,不是计算允许您创建路径图的默认100 alpha值的系数,而是只为您在CV中设置的每个alpha值获得一个。话虽这么说你可以初始化你的CV中的alphas来模仿enet_path
中的100默认值然后合并每个折叠的系数,但这将是相当长的运行。如你所说,你已经适合了CV,这不是一个选择。