投票

Python 中的集成方法

Román de las Heras

Data Scientist, Appodeal

请观众作答

请观众帮忙.gif

群体智慧

  • 集体智能
  • 大规模个体群体 ≥ 单一专家
  • 解决问题
  • 决策制定
  • 创新
  • 预测
Python 中的集成方法

多数投票

性质

  • 分类问题
  • 多数投票:众数
  • 分类器数量为奇数(≥3)

多峰预测.png

明智群体特征:

  • 多样性:不同算法或数据集
  • 独立、低相关
  • 利用各自知识
  • 汇总个体预测
Python 中的集成方法

使用 scikit-learn 的投票集成

from sklearn.ensemble import VotingClassifier

clf_voting = VotingClassifier( estimators=[ ('label1', clf_1), ('label2', clf_2), ('labelN', clf_N)])

评估性能

# Get the accuracy score 
acc = accuracy_score(y_test, y_pred)
print("Accuracy: {:0.3f}".format(acc))
Accuracy: 0.938
# Create the individual models
clf_knn = KNeighborsClassifier(5)
clf_dt = DecisionTreeClassifier()
clf_lr = LogisticRegression()

# Create voting classifier clf_voting = VotingClassifier( estimators=[ ('knn', clf_knn), ('dt', clf_dt), ('lr', clf_lr)])
# Fit it to the training set and predict clf_voting.fit(X_train, y_train) y_pred = clf_voting.predict(X_test)
Python 中的集成方法

让我们试试看!

Python 中的集成方法

Preparing Video For Download...