Mun*_*ong 3 python machine-learning linear-regression scikit-learn
我正在使用线性回归和 Scikit-learn 包中实现的 Lasso。
linear_regress = linear_model.Lasso(alpha = 2)
linear_regress.fit(X, Y)
Run Code Online (Sandbox Code Playgroud)
对于 X,有 7827 个示例和 758 个特征。但是我收到了警告:
Objective did not converge for target 0, you might want to increase the number of iterations ' to increase the number of iterations')
Run Code Online (Sandbox Code Playgroud)
同时,交叉验证的MAE为0.00304247702091
然后,我按照它的建议增加了迭代次数。(我假设我做得正确):
linear_regress = linear_model.Lasso(alpha = 2, max_iter = 100000, tol = 1e-20)
Run Code Online (Sandbox Code Playgroud)
但警告仍然存在,MAE 增加到 0.0191056040626,这更糟。
那么有谁知道如何解决这个问题?
顺便说一句,对于交叉验证的结果,训练数据的 MAE 远小于测试数据的 MAE,例如(alpha=2):
The MAE on the TRAINING data is 6.3462754706e-14
The MAE on the TEST data is 0.238521024414
Run Code Online (Sandbox Code Playgroud)
我假设存在过度拟合。但增加 alpha 并没有多大帮助,例如(alpha=5)
The MAE on the TRAINING data is 1.29613883816e-13
The MAE on the TEST data is 0.0677816327262
Run Code Online (Sandbox Code Playgroud)
增加 alpha 也会使平均 MAE 增加。
提前致谢!
我猜警告'not converge'可能是由于欠拟合造成的,但您需要验证(可能不需要将值设置tol得太小)。我建议您在拟合中迭代,alpha并绘制学习曲线来观察训练和测试数据(交叉验证)的性能,并选择最佳正则化参数以最好地避免欠拟合和过度拟合。2^(-5)2^3