我对sklearn.linear_model的RidgeCV中的normalized=
的确切功能感到困惑。
文档说:
normalize:bool,默认= False当
fit_intercept
设置为False时,将忽略此参数。如果为True,则回归变量X将在回归之前通过减去均值并除以l2-范数。如果您希望标准化,请使用:class:sklearn.preprocessing.StandardScaler
,然后再调用fit
在具有normalize=False
的估算器上。
If you wish to standardize, please use :class:`sklearn.preprocessing.StandardScaler` before calling ``fit`` on an estimator with ``normalize=False``.
总体上,我不确定我是否已遵循有关此normalize
参数的文档。
我将用其他语言测试类似的代码,然后看看能得到什么。
from sklearn.datasets import load_diabetes from sklearn.linear_model import RidgeCV X, y = load_diabetes(return_X_y=True)
未标准化
clf = RidgeCV(normalize=False,alphas=[1e-3, 1e-2, 1e-1, 1]).fit(X, y) clf.coef_ print(clf.alpha_) print(clf.score(X,y)) print(clf.coef_) 0.01 0.5166287840315846 [ -7.19945679 -234.55293001 520.58313622 320.52335582 -380.60706569 150.48375154 -78.59123221 130.31305868 592.34958662 71.1337681 ]
标准化并规范化为真
from sklearn.preprocessing import StandardScaler scaler = StandardScaler() scaler.fit(X) X_std = scaler.transform(X) clf = RidgeCV(normalize=True,alphas=[1e-3, 1e-2, 1e-1, 1]).fit(X_std, y) print("standardize and normalize=True") print(clf.alpha_) print(clf.score(X_std,y)) print(clf.coef_) standardize and normalize=True 0.01 0.5166287840315843 [ -0.34244324 -11.15654516 24.76161466 15.24574131 -18.10363195 7.15778213 -3.7382037 6.19836011 28.17519659 3.38348831]
standardize and normalize = False
clf = RidgeCV(normalize=False,alphas=[1e-3, 1e-2, 1e-1, 1]).fit(X_std, y)
print("standardize and normalize=False")
print(clf.alpha_)
print(clf.score(X_std,y))
print(clf.coef_)
standardize and normalize=False
1.0
0.5175831607267165
[ -0.43127609 -11.33381407 24.77096198 15.37375716 -30.08858903
16.65328714 1.46208255 7.5211415 32.84392268 3.26632702]
我对sklearn.linear_model在RidgeCV中所做的归一化=所做的事情感到困惑。文档说:normalize:bool,default = False当fit_intercept为...
[normalize]参数的作用与sklearn.preprocessing.normalizer相同,与标准定标器不同。