Ridge 回归
还是上一小节的样本数据,用岭回归进行拟合
A |
|
1 |
[[1.1,1.1],[1.4,1.5],[1.7,1.8],[1.7,1.7],[1.8,1.9],[1.8,1.8],[1.9,1.8],[2.0,2.1],[2.3,2.4],[2.4,2.5]] |
2 |
[16.3,16.8,19.2,18,19.5,20.9,21.1,20.9,20.3,22] |
3 |
=ridge(A1,A2,0.01,10000) |
4 |
=ridge(A1,A3) |
5 |
=canvas() |
6 |
=A5.plot("NumericAxis","name":"y_pre","autoCalcValueRange":false,"autoRangeFromZero":false,"maxValue":25,"minValue":15,"title":"prediction data") |
7 |
=A5.plot("NumericAxis","name":"y","location":2,"autoCalcValueRange":false,"autoRangeFromZero":false,"maxValue":25,"minValue":15,"title":"observation data","titleAngle":270) |
8 |
=A5.plot("Dot","lineWeight":0,"lineColor":-16776961,"markerWeight":1,"axis1":"y_pre","data1":A4.conj(),"axis2":"y","data2": A2) |
9 |
=to(15:25) |
10 |
=A5.plot("Line","markerStyle":0,"axis1":"y_pre","data1":A9,"axis2":"y", "data2":A9) |
11 |
=A5.draw(600,600) |
A1 输入数据x
A2输入数据y
A3用ridge拟合数据,0.01 表示学习率,10000 表示迭代次数,返回模型信息。
A3(1)系数矩阵
A3(2)截距
A4 用A3拟合的模型在A1上进行预测,返回预测结果
A5-A11 画图对比预测值和真实值,评估模型效果。横轴表示每个样本数据的预测值,纵轴表示观测数据真实值。如果所有点都能在对角线附近均匀分布,则方程的拟合值与原值差异很小,方程的拟合效果就好。如效果不理想可通过调节学习率和迭代次数进行优化。
A5生成画布
A6绘制横轴,预测数据
A7绘制纵轴,观测数据真实值
A8绘制点图元,横轴取预测值,纵轴取真实值
A9取[15,25]的固定区间
A10绘制线图元,y=x
A11画图