本学习笔记为阿里云天池龙珠计划Docker训练营的学习内容,学习链接为:https://github.com/datawhalechina/team-learning-data-mining/tree/master/FinancialRiskControl
模型融合是一种有效提升机器学习效果的方法,通过构建并融合多个模型来完成学习任务。
引用来源:https://www.jianshu.com/p/820f3ce58a60
一、学习知识概要
- 平均:
- 简单平均法
- 加权平均法
- 投票:
- 简单投票法
- 加权投票法
- stacking:
- 构建多层模型,并利用预测结果再拟合预测。
- blending:
- 选取部分数据预测训练得到预测结果作为新特征,带入剩下的数据中预测。
二、学习内容
本篇文章大部分参考:https://blog.csdn.net/wuzhongqiang/article/details/105012739
2.1 平均
简单加权平均,结果直接融合,求多个预测结果的平均值
pre = (pre1 + pre2 + pre3 +…+pren )/n
加权平均法,一般根据之前预测模型的准确率,进行加权融合,将准确性高的模型赋予更高的权重。
pre = 0.3pre1 + 0.3pre2 + 0.4pre3
#生成一些简单的样本数据, test_prei代表第i个模型的预测值
test_pre1 = [1.2, 3.2, 2.1, 6.2]
test_pre2 = [0.9, 3.1, 2.0, 5.9]
test_pre3 = [1.1, 2.9, 2.2, 6.0]
# y_test_true 代表模型的真实值
y_test_true = [1, 3, 2, 6]
# 可以先看一下各个模型的预测结果
print('Pred1 MAE:',mean_absolute_error(y_test_true, test_pre1))
print('Pred2 MAE:',mean_absolute_error(y_test_true, test_pre2))
print('Pred3 MAE:',mean_absolute_error(y_test_true, test_pre3))
## 结果: 结果越小表示越好
Pred1 MAE: 0.1750000000000001
Pred2 MAE: 0.07499999999999993
Pred3 MAE: 0.10000000000000009
# 下面我们进行加权融合
def Weighted_method