集成学习-幸福感预测

Posted GoAl的博客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了集成学习-幸福感预测相关的知识,希望对你有一定的参考价值。

本次案例来源于天池的一个比赛,赛题使用 139 维的特征,使用 8000 余组数据进行对于个人幸福感的预测(预测值为1,2,3,4,5,其中1代表幸福感最低,5代
表幸福感最高)。以均方误差MSE为评价标准,因为评价标准为均方误差,所以使用回归问题的思路解决该问.

Blending集成学习方式:

(1) 将数据划分为训练集和测试集(test_set),其中训练集需要再次划分为训练集(train_set)和验证集(val_set);
(2) 创建第一层的多个模型,这些模型可以使同质的也可以是异质的;
(3) 使用train_set训练步骤2中的多个模型,然后用训练好的模型预测val_set和test_set得到val_predict, test_predict1;
(4) 创建第二层的模型,使用val_predict作为训练集训练第二层的模型;
(5) 使用第二层训练好的模型对第二层测试集test_predict1进行预测,该结果为整个测试集的结果。

导入相关库

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use(“ggplot”)
%matplotlib inline
import seaborn as sns

引入数据

from sklearn import datasets
from sklearn.datasets import make_blobs
from sklearn.model_selection import train_test_split
data, target = make_blobs(n_samples=10000, centers=2, random_state=1, cluster_std=1.0 )

创建训练集和测试集

X_train1,X_test,y_train1,y_test = train_test_split(data, target, test_size=0.2, random_state=1)

创建训练集和验证集

X_train,X_val,y_train,y_val = train_test_split(X_train1, y_train1, test_size=0.3, random_state=1)
print(“The shape of training X:”,X_train.shape)
print(“The shape of training y:”,y_train.shape)
print(“The shape of test X:”,X_test.shape)
print(“The shape of test y:”,y_test.shape)
print(“The shape of validation X:”,X_val.shape)
print(“The shape of validation y:”,

后续未完成,待更新

以上是关于集成学习-幸福感预测的主要内容,如果未能解决你的问题,请参考以下文章

机器学习之集成学习算法

猿创征文|机器学习实战——集成学习

集成学习-蒸汽量预测案例

机器学习-集成学习GBDT

Python机器学习:7.1 集成学习

集成学习