30秒到达战场
这是一个纯粹的sklearn答案:import numpy as npfrom sklearn.linear_model import Ridgealphas = np.logspace(-10, 10, 1000)solution_norm = []residual_norm = []for alpha in alphas: lm = Ridge(alpha=alpha) lm.fit(X, y) solution_norm += [(lm.coef_**2).sum()] residual_norm += [((lm.predict(X) - y)**2).sum()]plt.loglog(residual_norm, solution_norm, 'k-')plt.show()whereX和y分别是你的预测变量和目标。