平均

Python 中的集成方法

Román de las Heras

Data Scientist, Appodeal

数果冻豆

果冻豆猜数活动

如何给出好的估计?

  • 直接猜(随机数)
  • 体积近似
  • 其他方法

实际值 ~ 平均(各估计)

Python 中的集成方法

平均(软投票)

属性

  • 分类与回归问题
  • 软投票:取平均
    • 回归: 预测值的平均
    • 分类: 预测概率的平均
  • 至少需要 2 个基学习器
Python 中的集成方法

用 scikit-learn 做平均集成

平均分类器

from sklearn.ensemble import VotingClassifier

clf_voting = VotingClassifier( estimators=[ ('label1', clf_1), ('label2', clf_2), ... ('labelN', clf_N)], voting='soft', weights=[w_1, w_2, ..., w_N] )

平均回归器

from sklearn.ensemble import VotingRegressor

reg_voting = VotingRegressor( estimators=[ ('label1', reg_1), ('label2', reg_2), ... ('labelN', reg_N)], weights=[w_1, w_2, ..., w_N] )
Python 中的集成方法

scikit-learn 示例

# Instantiate the individual models
clf_knn = KNeighborsClassifier(5)
clf_dt = DecisionTreeClassifier()
clf_lr = LogisticRegression()
# Create an averaging classifier
clf_voting = VotingClassifier(
    estimators=[
       ('knn', clf_knn), 
       ('dt', clf_dt), 
       ('lr', clf_lr)],
    voting='soft',
    weights=[1, 2, 1]
)
Python 中的集成方法

权力的游戏:角色死亡

目标:

  • 预测角色是否存活

特征:

  • 年龄
  • 性别
  • 出现的书卷
  • 热度
  • 亲属是否存活

shutterstock_1038048793.jpg

Python 中的集成方法

开始练习!

Python 中的集成方法

Preparing Video For Download...