使用H2O机器学习"十分钟"提交天池练习赛--工业蒸汽量预测,超过86%的队伍

试用一下H2O全自动机器学习

 

下载数据集

天池练习赛"工业蒸汽量预测",下个数据集:https://tianchi.aliyun.com/competition/entrance/231693/introduction

 

安装H2O

H2O requirements:

pip install requests
pip install tabulate
pip install "colorama>=0.3.8"
pip install future

install H2O:

pip install -f http://h2o-release.s3.amazonaws.com/h2o/latest_stable_Py.html h2o

 

训练模型并预测

import h2o

from h2o.estimators.random_forest import H2ORandomForestEstimator
from h2o.estimators.gbm import H2OGradientBoostingEstimator
from h2o.estimators.stackedensemble import H2OStackedEnsembleEstimator

# 初始化H2O
h2o.init()

# 读数据集
col_types = ["numeric"]*39 # 列数
data = h2o.import_file('zhengqi_train.txt',sep='\t', col_types=col_types)
out = h2o.import_file('zhengqi_test.txt',sep='\t')

#切分数据集用以训练模型
train, test = data.split_frame(ratios=[.7], seed=1) 

# 列名赋值
x = train.columns
y = "target"
x.remove(y)

# 训练模型
nfolds = 7
gbm = H2OGradientBoostingEstimator(nfolds=nfolds,
                                   fold_assignment="Modulo",
                                   keep_cross_validation_predictions=True)
gbm.train(x=x, y=y, training_frame=train)
rf = H2ORandomForestEstimator(nfolds=nfolds,
                              fold_assignment="Modulo",
                              keep_cross_validation_predictions=True)
rf.train(x=x, y=y, training_frame=train)
stack = H2OStackedEnsembleEstimator(model_id="ensemble",
                                    training_frame=train,
                                    validation_frame=test,
                                    base_models=[gbm.model_id, rf.model_id])
stack.train(x=x, y=y, training_frame=train, validation_frame=test)
stack.model_performance()


# 预测并保存待提交结果
result = stack.predict(out)
result = result.as_data_frame()['predict'].to_list()

with open('result_h2o.txt', 'w') as f:
    for i in result:
        f.write("{}\n".format(i))

# h2o.export_file(result,'result_h2o.txt',sep = "\n",parts = 1)

h2o.shutdown()

提交结果

直接不做任何特征工程,超过了这个练习赛86%的队伍!

 

看来H2O还是可以的,接下来用Spark结合H2O跑大数据试试

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值