楼主: ReneeBK
2457 12

【GitHub】Practical Machine Learning with H2O [推广有奖]

  • 1关注
  • 62粉丝

VIP

学术权威

14%

还不是VIP/贵宾

-

TA的文库  其他...

R资源总汇

Panel Data Analysis

Experimental Design

威望
1
论坛币
49407 个
通用积分
51.8704
学术水平
370 点
热心指数
273 点
信用等级
335 点
经验
57815 点
帖子
4006
精华
21
在线时间
582 小时
注册时间
2005-5-8
最后登录
2023-11-26

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
h2o
This is the code and data repository for the "Practical Machine Learning with H2O" book, published by O'Reilly.
As well as direct from O'Reilly, it is also available in places like Amazon US and Amazon UK  ( Print ISBN: 978-1-4919-6460-6;   Ebook ISBN: 978-1-4919-6454-5 )
If you find any errors in the code found here, please file a bug report here. For mistakes or typos in the text of the book, use the book's errata page
If you have written your own code that gets a better result on one of the data sets in the book, and want to share, please submit a pull request by putting your contrib folder. Please make all contributions as public domain, or under the MIT or BSD open source license. Remember to include any additional data sets used (or links to them if they are already open and online somewhere stable).

本帖隐藏的内容

Practical Machine Learning with H2O-Master.zip (42.12 MB)


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Practical Learning practic machine earning available published mistakes written please

本帖被以下文库推荐

沙发
ReneeBK 发表于 2017-4-23 04:04:05 |只看作者 |坛友微信交流群
Files by book chapter

###chapter 1
iris_deeplearning.py
iris_deeplearning.R
iris_deeplearning.reproducible.py
iris_deeplearning.reproducible.R


###chapter 2
drop_and_assign.py
drop_and_assign.R
load_from_dictionary.py
modify_columns.R


###chapter 3
analyze_football_bet_correlations.R
building_energy_correlations.py
load.building_energy.py
load.building_energy.R
load.building_energy.reproducible.py
load.building_energy.reproducible.R
load.football_2013_2014.py
load.football_2013_2014.R
load.football2.py
load.football2.R
load.football.py
load.football.R
load.mnist.py
load.mnist.R
load.mnist.reproducible.py
load.mnist.reproducible.R
mnist_manipulation.py


###chapter 4
early_stopping_example.py
early_stopping_example.reproducible.py
misbalanced_classes.example.R
misbalanced_classes.reproducible.R
using_checkpoints.py
using_checkpoints.R


###chapter 5
compare_models.R
random_forest.building_energy.default.py
random_forest.building_energy.default.R
random_forest.building_energy.default.reproducible.py
random_forest.building_energy.grid1.py
random_forest.building_energy.grid1.R
random_forest.building_energy.grid2.R
random_forest.building_energy.lapply_seed.R
random_forest.football.default.py
random_forest.football.default.reproducible.py
random_forest.mnist.default.py
random_forest.mnist.default.R
random_forest.mnist.default.reproducible.py


###chapter 6
gbm.building_energy.default.R
gbm.building_energy.default.reproducible.py
gbm.building_energy.default.reproducible.R


###chapter 9
autoencoder.tfidf.py
autoencoder.tfidf.R
glrm.tfidf.R
kmeans.tfidf.py
kmeans.tfidf.R
prcomp.tfidf.R


###chapter 11
epilogue_comparison.building_energy.R
epilogue_comparison.football.R
epilogue_comparison.mnist.R

使用道具

藤椅
ReneeBK 发表于 2017-4-23 04:05:46 |只看作者 |坛友微信交流群
  1. #Run the load.building_energy.py script, to set `train`

  2. import pandas as pd
  3. import numpy as np
  4. import matplotlib.pyplot as plt

  5. #Make the correlations and download to a Pandas frame
  6. res = train[x].cor(train[y]).as_data_frame()
  7. res.index = x

  8. #res.plot.barh();plt.show() is enough to draw the bar chart.
  9. #All the rest of this code is making it pretty, with labels on each bar.

  10. ax = res.plot.barh(xlim=[-1.1,+1.15])
  11. for p in ax.patches:
  12.   if p.get_x() < 0:
  13.       ax.annotate("-%.2f" % p.get_width(), (p.get_x() -0.05 , p.get_y()), ha="right", va="center", xytext=(5, 10), textcoords='offset points')
  14.   else:        
  15.       ax.annotate("%.2f" % p.get_width(), (p.get_x() + p.get_width() +0.03, p.get_y()), va="center", xytext=(5, 10), textcoords='offset points')

  16. plt.show()
复制代码

使用道具

板凳
ReneeBK 发表于 2017-4-23 04:07:13 |只看作者 |坛友微信交流群
  1. import h2o
  2. h2o.init()

  3. ###############
  4. # From dictionary

  5. patients = {
  6.   'height':[188, 157, 175],
  7.   'age':[29, 33, 65],
  8.   'risk':['A', 'B', 'B']
  9.   }
  10. df = h2o.H2OFrame(patients)

  11. ###############
  12. # From dictionary, with customization

  13. patients = {
  14.   'height':[188, 157, 175.1],
  15.   'age':[29, 33, 65],
  16.   'risk':['A', 'B', 'B']
  17.   }
  18. df = h2o.H2OFrame.from_python(
  19.   patients,
  20.   column_types=['enum', None, None],
  21.   destination_frame="patients"
  22.   )

  23. df.types
  24. df.frame_id


  25. ###################
  26. import pandas as pd
  27. patients = pd.DataFrame({
  28.   'height':[188, 157, 175.1],
  29.   'age':[29, 33, 65],
  30.   'risk':['A', 'B', 'B']
  31.   }
  32. df = h2o.H2OFrame(patients)
  33. df.types
  34. df.frame_id

  35. #############
  36. patients = pd.DataFrame({
  37.   'height':[188, 157, 175.1],
  38.   'age':[29, 33, 65],
  39.   'risk':['A', 'B', 'B']
  40.   })
  41. df = h2o.H2OFrame.from_python(
  42.   patients,
  43.   column_names=patients.columns.tolist()
  44.   )
  45. df.types
  46. df.frame_id
复制代码

使用道具

报纸
ReneeBK 发表于 2017-4-23 04:09:21 |只看作者 |坛友微信交流群
  1. import h2o.grid

  2. g = h2o.grid.H2OGridSearch(
  3.   h2o.estimators.H2ORandomForestEstimator(
  4.     nfolds=10
  5.     ),
  6.   hyper_params = {
  7.     "ntrees": [50, 100, 120],
  8.     "max_depth": [40, 60],
  9.     "min_rows": [1, 2]
  10.     }
  11.   )
  12. g.train(x, y, train)
复制代码

使用道具

地板
ReneeBK 发表于 2017-4-23 04:10:18 |只看作者 |坛友微信交流群
  1. #seed = 999
  2. #source("load.building_energy.R")
  3. #source("makeplot.building_energy_results.R")

  4. seeds <- c(101, 109, 373, 571, 619, 999)

  5. defaultModels <- lapply(seeds, function(seed){
  6.   h2o.randomForest(x, y, train, nfolds = 10, seed = seed)
  7.   })

  8. tunedModels <- lapply(seeds, function(seed){
  9.   h2o.randomForest(x, y, train, nfolds = 10, seed = seed,
  10.     max_depth = 40, ntrees = 200, sample_rate = 0.7,
  11.     mtries = 4, col_sample_rate_per_tree = 0.9,
  12.     stopping_metric = "deviance",
  13.     stopping_tolerance = 0,
  14.     stopping_rounds = 5,
  15.     score_tree_interval = 3)
  16.   })


  17. def <- sapply(defaultModels, h2o.rmse, xval = TRUE)
  18. tuned <- sapply(tunedModels, h2o.rmse, xval = TRUE)

  19. defT <- sapply(defaultModels, h2o.rmse)
  20. tunedT <- sapply(tunedModels, h2o.rmse)

  21. #The box plot on RMSE, cross-validation data
  22. boxplot(c(def,tuned) ~ c(rep(1,6),rep(2,6)) )

  23. #Compare with RMSE on training data
  24. boxplot(c(def,tuned,defT,tunedT) ~ c(rep(1,6),rep(2,6),rep(3,6),rep(4,6)) )

  25. # Here is same example with labels (also showing how to force factor order!)
  26. f <- factor(c(rep("Default Model",6),rep("Tuned Model",6)), c("Default Model","Tuned Model"))
  27. boxplot(c(def,tuned) ~ f, ylim=c(1.75, 1.85), ylab="RMSE")

  28. #Exported as 900x500


  29. #Repeat but with MAE instead of RMSE
  30. def2 <- sapply(defaultModels, h2o.mae, xval = TRUE)
  31. tuned2 <- sapply(tunedModels, h2o.mae, xval = TRUE)

  32. defT2 <- sapply(defaultModels, h2o.mae)
  33. tunedT2 <- sapply(tunedModels, h2o.mae)

  34. boxplot(c(def2,tuned2,defT2,tunedT2) ~ c(rep(5,6),rep(6,6),rep(7,6),rep(8,6)) )

  35. #And both RMSE and MAE
  36. boxplot(c(def,tuned,defT,tunedT,def2,tuned2,defT2,tunedT2) ~ c(rep(1,6),rep(2,6),rep(3,6),rep(4,6),rep(5,6),rep(6,6),rep(7,6),rep(8,6)) )

  37. # Make the results plot
  38. mBest <- tunedModels[[1]]  #Choose first one, arbitrarily
  39. p = h2o.predict(mBest, test, seed = seed)
  40. p

  41. plotBuildingEnergy(p, test, forPrint = T, "../chapters/images/", "randomforest.tuned")
复制代码

使用道具

7
军旗飞扬 发表于 2017-4-23 07:24:38 |只看作者 |坛友微信交流群
谢谢分享

使用道具

8
w-long 发表于 2017-4-23 08:18:07 |只看作者 |坛友微信交流群
谢谢分享。

使用道具

9
jiandong4388 学生认证  发表于 2017-4-23 09:52:35 |只看作者 |坛友微信交流群
谢谢分享

使用道具

10
nieqiang110 学生认证  发表于 2017-4-23 19:06:18 |只看作者 |坛友微信交流群
h2o
This is the code and data repository for the "Practical Machine Learning with H2O" book, published by O'Reilly.
本文来自: 人大经济论坛 winbugs及其他软件专版 版,详细出处参考: https://bbs.pinggu.org/forum.php?mod=viewthread&tid=5552343&page=1&from^^uid=341570

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-27 05:19