集成模型-泰坦尼克号生还预测
2017-08-18 16:15
218 查看
集成模型(分类)(Ensemble)
集成分类模型综合考量多个分类器的预测结果,进而做出决策。
综合考量的方式大体分两种:
1.利用相同的训练数据同时搭建多个独立的分类模型,然后通过投票的方式,以少数服从多数的原则作为最终的分类决策。代表性的模型有:随机森林分类器(Random Forest Classifier),在相同的训练数据上同时搭建多棵决策树(Decision Tree)。一株标准的决策树会根据每维特征对预测结果的影响程度进行排序,进而决定不同特征从上至下构建分裂节点的顺序;这样,所有在随机森林中的决策树都会受这一策略影响
而构建得完全一致,丧失了多样性。随机森林分类器在构建过程中,每一棵决策树都会放弃这一固定的排序算法,转而随机选取特征。
2.另一种是按照一定次序搭建多个分类模型。这些模型彼此之间存在依赖关系。一般而言,每一个后续模型的加入都需要对现有集成模型的综合性能有所贡献,进而不断提升更新过后的集成模型的性能,并最终期望借助整合多个分类能力较弱的分类器,搭建出具有更强分类能力的模型。具有代表性的是梯度提升决策树(Gradient Tree Boosting)。与构建随机森林分类器模型不同,这里每一棵决策树在生成的过程中都会尽可能降低整体集成模型在训练集上的拟合误差。
为了对比单一决策树(Decision Tree)与集成模型中随机森林分类器(Random Forest Classifier)以及梯度提升决策树(Gradient Tree Boosting)的性能差异,本文依旧使用泰坦尼克号的乘客数据。
Python 源码:
Result:
The Accuracy DT is 0.781155015198
precision recall f1-score support
died 0.78 0.91 0.84 202
survived 0.80 0.58 0.67 127
avg / total 0.78 0.78 0.77 329
The Accuracy RFC is 0.784194528875
precision recall f1-score support
died 0.78 0.91 0.84 202
survived 0.80 0.58 0.68 127
avg / total 0.79 0.78 0.78 329
The Accuracy GBC is 0.790273556231
precision recall f1-score support
died 0.78 0.92 0.84 202
survived 0.82 0.58 0.68 127
avg / total 0.80 0.79 0.78 329
输出表明,仅仅使用模型的默认配置,梯度上升决策树具有最佳的预测性能,其次是随机森林分类器,最后是单一决策树。大量的其它数据上面的模型实践也证明了上述结论的普适性。一般工业界为了追求更好的预测性能,经常使用随机森林分类模型作为基线系统(Baseline System)。
基线系统通常指使用经典模型搭建的机器学习系统,研发人员每提出一个新模型,都需要和基线系统在多个具有代表性的数据集上进行性能比较的测试。随机森林分类模型就经常以基线系统的身份出现在科研论文,甚至公开的数据竞赛中。
模型特点:集成模型是实战应用中最为常见的,相比于其他单一的学习模型,集成模型可以整合多种模型,或者多次就一种类型的模型进行建模。由于模型估计参数的过程同样受到概率的影响,具有一定的不确定性。因此集成模型虽然在训练过程中耗费更多的时间,但是得到的综合模型往往具有更高的表现性能和更好的稳定性。
集成分类模型综合考量多个分类器的预测结果,进而做出决策。
综合考量的方式大体分两种:
1.利用相同的训练数据同时搭建多个独立的分类模型,然后通过投票的方式,以少数服从多数的原则作为最终的分类决策。代表性的模型有:随机森林分类器(Random Forest Classifier),在相同的训练数据上同时搭建多棵决策树(Decision Tree)。一株标准的决策树会根据每维特征对预测结果的影响程度进行排序,进而决定不同特征从上至下构建分裂节点的顺序;这样,所有在随机森林中的决策树都会受这一策略影响
而构建得完全一致,丧失了多样性。随机森林分类器在构建过程中,每一棵决策树都会放弃这一固定的排序算法,转而随机选取特征。
2.另一种是按照一定次序搭建多个分类模型。这些模型彼此之间存在依赖关系。一般而言,每一个后续模型的加入都需要对现有集成模型的综合性能有所贡献,进而不断提升更新过后的集成模型的性能,并最终期望借助整合多个分类能力较弱的分类器,搭建出具有更强分类能力的模型。具有代表性的是梯度提升决策树(Gradient Tree Boosting)。与构建随机森林分类器模型不同,这里每一棵决策树在生成的过程中都会尽可能降低整体集成模型在训练集上的拟合误差。
为了对比单一决策树(Decision Tree)与集成模型中随机森林分类器(Random Forest Classifier)以及梯度提升决策树(Gradient Tree Boosting)的性能差异,本文依旧使用泰坦尼克号的乘客数据。
Python 源码:
#coding=utf-8 import pandas as pd #-------------data split from sklearn.cross_validation import train_test_split #-------------feature transfer from sklearn.feature_extraction import DictVectorizer #------------- from sklearn.tree import DecisionTreeClassifier from sklearn.ensemble import RandomForestClassifier from sklearn.ensemble import GradientBoostingClassifier #------------- from sklearn.metrics import classification_report #-------------download data titanic=pd.read_csv('http://biostat.mc.vanderbilt.edu/wiki/pub/Main/DataSets/titanic.txt') print titanic.head() #transfer to dataFrame format by pandas,use info() to show statistics of data print titanic.info() #-------------feature selection X=titanic[['pclass','age','sex']] y=titanic['survived'] print 'bf processing\n',X.info() #-------------feature processing X['age'].fillna(X['age'].mean(),inplace=True) print 'af processing\n',X.info #-------------data split #75% training set,25% testing set X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.25,random_state=33) #-------------feature transfer from String to int vec=DictVectorizer(sparse=False) X_train=vec.fit_transform(X_train.to_dict(orient='record')) print vec.get_feature_names() X_test=vec.transform(X_test.to_dict(orient='record')) #-------------training DT #initialize dtc=DecisionTreeClassifier() dtc.fit(X_train,y_train) dtc_y_predict=dtc.predict(X_test) #-------------training RFC rfc=RandomForestClassifier() rfc.fit(X_train,y_train) rfc_y_predict=rfc.predict(X_test) #-------------training GBC gbc=GradientBoostingClassifier() gbc.fit(X_train,y_train) gbc_y_predict=gbc.predict(X_test) #-------------performance DT print 'The Accuracy DT is',dtc.score(X_test,y_test) print classification_report(y_test,dtc_y_predict,target_names=['died','survived']) #-------------performance RFC print 'The Accuracy RFC is',rfc.score(X_test,y_test) print classification_report(y_test,rfc_y_predict,target_names=['died','survived']) #-------------performance GBC print 'The Accuracy GBC is',gbc.score(X_test,y_test) print classification_report(y_test,gbc_y_predict,target_names=['died','survived'])
Result:
The Accuracy DT is 0.781155015198
precision recall f1-score support
died 0.78 0.91 0.84 202
survived 0.80 0.58 0.67 127
avg / total 0.78 0.78 0.77 329
The Accuracy RFC is 0.784194528875
precision recall f1-score support
died 0.78 0.91 0.84 202
survived 0.80 0.58 0.68 127
avg / total 0.79 0.78 0.78 329
The Accuracy GBC is 0.790273556231
precision recall f1-score support
died 0.78 0.92 0.84 202
survived 0.82 0.58 0.68 127
avg / total 0.80 0.79 0.78 329
输出表明,仅仅使用模型的默认配置,梯度上升决策树具有最佳的预测性能,其次是随机森林分类器,最后是单一决策树。大量的其它数据上面的模型实践也证明了上述结论的普适性。一般工业界为了追求更好的预测性能,经常使用随机森林分类模型作为基线系统(Baseline System)。
基线系统通常指使用经典模型搭建的机器学习系统,研发人员每提出一个新模型,都需要和基线系统在多个具有代表性的数据集上进行性能比较的测试。随机森林分类模型就经常以基线系统的身份出现在科研论文,甚至公开的数据竞赛中。
模型特点:集成模型是实战应用中最为常见的,相比于其他单一的学习模型,集成模型可以整合多种模型,或者多次就一种类型的模型进行建模。由于模型估计参数的过程同样受到概率的影响,具有一定的不确定性。因此集成模型虽然在训练过程中耗费更多的时间,但是得到的综合模型往往具有更高的表现性能和更好的稳定性。
相关文章推荐
- 集成模型(回归)对Boston数据进行训练并对数据做出预测
- kaggle 泰坦尼克号生存预测——六种算法模型实现与比较
- 利用树的集成回归模型RandomForestRegressor/ExtraTreesRegressor/GradientBoostingRegressor进行回归预测(复习11)
- 使用skflow内置的LR,DNN,Scikit-learn中的集成回归模型对“美国波士顿房价”进行预测
- Python 决策树 泰坦尼克号乘客是否生还决策模型
- SVM模型预测
- 机器学习中的特征选择——决策树模型预测泰坦尼克号乘客获救实例
- 用ARIMA模型做需求预测
- [PAL编程规范]SAP HANA PAL双变量自然对数回归预测分析Bi-Variate Natural Logarithmic Regression编程规范LNREGRESSION(模型)
- [PAL编程规范]SAP HANA PAL指数回归预测分析Exponential Regression编程规范EXPREGRESSION(模型)
- BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第11章节--为Office和SP解决方案开发集成Apps Office新的App模型
- mxnet使用预训练模型预测
- 模型与模式4预测模型1回归
- medrank算法配合B+树实现一个简单预测模型
- R语言 决策树--预测模型
- 评分模型的检验方法和标准通常有:K-S指标、交换曲线、AR值、Gini数等。例如,K-S指标是用来衡量验证结果是否优于期望值,具体标准为:如果K-S大于40%,模型具有较好的预测功能,发展的模型具有成功的应用价值。K-S值越大,表示评分模型能够将“好客户”、“坏客户”区分开来的程度越大。
- 灰色预测模型
- 预测模型的意义和方法
- R: 学习Gradient Boosting算法,提高预测模型准确率
- 信用卡违约客户的预测模型的选择(二)验证过程