forked from h2oai/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request h2oai#271 from h2oai/fv-h2o3-tutorials-code
Added a folder with the R and Python codes for the H2O-3 Tutorials
- Loading branch information
Showing
72 changed files
with
14,760 additions
and
2,762 deletions.
There are no files selected for viewing
1,235 changes: 0 additions & 1,235 deletions
1,235
...earning-with-h2o-3-part-1/introduction-to-machine-learning-with-h2o-3-part-1.md
This file was deleted.
Oops, something went wrong.
951 changes: 0 additions & 951 deletions
951
...earning-with-h2o-3-part-2/introduction-to-machine-learning-with-h2o-3-part-2.md
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-196 KB
...roduction-to-machine-learning-with-h2o-3-part-3/assets/aml-cl-leaderboard-1.jpg
Binary file not shown.
Binary file removed
BIN
-221 KB
...roduction-to-machine-learning-with-h2o-3-part-3/assets/aml-cl-leaderboard-2.jpg
Binary file not shown.
Binary file removed
BIN
-96.6 KB
...ntroduction-to-machine-learning-with-h2o-3-part-3/assets/aml-cl-leaderboard.jpg
Binary file not shown.
Binary file removed
BIN
-65.6 KB
...ersion/introduction-to-machine-learning-with-h2o-3-part-3/assets/auto-ml-11.jpg
Binary file not shown.
Binary file removed
BIN
-69.8 KB
...ersion/introduction-to-machine-learning-with-h2o-3-part-3/assets/auto-ml-66.jpg
Binary file not shown.
Binary file removed
BIN
-128 KB
...ion/introduction-to-machine-learning-with-h2o-3-part-3/assets/auto-ml-cl-75.jpg
Binary file not shown.
Binary file removed
BIN
-145 KB
.../introduction-to-machine-learning-with-h2o-3-part-3/assets/automl-cl-output.jpg
Binary file not shown.
Binary file removed
BIN
-58.1 KB
.../introduction-to-machine-learning-with-h2o-3-part-3/assets/automl-cl-perf-1.jpg
Binary file not shown.
Binary file removed
BIN
-59.4 KB
.../introduction-to-machine-learning-with-h2o-3-part-3/assets/automl-cl-perf-2.jpg
Binary file not shown.
Binary file removed
BIN
-38 KB
...on/introduction-to-machine-learning-with-h2o-3-part-3/assets/automl-cl-pred.jpg
Binary file not shown.
Binary file removed
BIN
-24.4 KB
...n/introduction-to-machine-learning-with-h2o-3-part-3/assets/automl-cl-preds.jpg
Binary file not shown.
Binary file removed
BIN
-14.8 KB
...ion/introduction-to-machine-learning-with-h2o-3-part-3/assets/automl-cl-roc.jpg
Binary file not shown.
Binary file removed
BIN
-14.7 KB
.../introduction-to-machine-learning-with-h2o-3-part-3/assets/automl-preds-reg.jpg
Binary file not shown.
Binary file removed
BIN
-189 KB
...duction-to-machine-learning-with-h2o-3-part-3/assets/automl-reg-leaderboard.jpg
Binary file not shown.
Binary file removed
BIN
-160 KB
...ction-to-machine-learning-with-h2o-3-part-3/assets/automl-reg-leaderboard_1.jpg
Binary file not shown.
Binary file removed
BIN
-172 KB
...ction-to-machine-learning-with-h2o-3-part-3/assets/automl-reg-leaderboard_2.jpg
Binary file not shown.
Binary file removed
BIN
-67.4 KB
...roduction-to-machine-learning-with-h2o-3-part-3/assets/automl-reg-summary-1.jpg
Binary file not shown.
Binary file removed
BIN
-127 KB
...roduction-to-machine-learning-with-h2o-3-part-3/assets/automl-reg-summary-2.jpg
Binary file not shown.
Binary file removed
BIN
-79.9 KB
...roduction-to-machine-learning-with-h2o-3-part-3/assets/automl-reg-summary-3.jpg
Binary file not shown.
Binary file removed
BIN
-144 KB
...ersion/introduction-to-machine-learning-with-h2o-3-part-3/assets/cl-predict.jpg
Binary file not shown.
Binary file removed
BIN
-65.3 KB
...duction-to-machine-learning-with-h2o-3-part-3/assets/cl-predictions-outputs.jpg
Binary file not shown.
Binary file removed
BIN
-76.3 KB
...n/introduction-to-machine-learning-with-h2o-3-part-3/assets/cl-training-auc.jpg
Binary file not shown.
Binary file removed
BIN
-40.1 KB
...sion/introduction-to-machine-learning-with-h2o-3-part-3/assets/cluster-info.jpg
Binary file not shown.
Binary file removed
BIN
-8.63 KB
...n/introduction-to-machine-learning-with-h2o-3-part-3/assets/delinquent-dist.jpg
Binary file not shown.
Binary file removed
BIN
-120 KB
...roduction-to-machine-learning-with-h2o-3-part-3/assets/flow-automl-build-cl.jpg
Binary file not shown.
Binary file removed
BIN
-61 KB
...introduction-to-machine-learning-with-h2o-3-part-3/assets/flow-automl-build.jpg
Diff not rendered.
Binary file removed
BIN
-94.9 KB
...introduction-to-machine-learning-with-h2o-3-part-3/assets/flow-automl-reg-1.jpg
Diff not rendered.
Binary file removed
BIN
-87.6 KB
...introduction-to-machine-learning-with-h2o-3-part-3/assets/flow-automl-reg-2.jpg
Diff not rendered.
Binary file removed
BIN
-91.5 KB
...introduction-to-machine-learning-with-h2o-3-part-3/assets/flow-automl-reg-3.jpg
Diff not rendered.
Binary file removed
BIN
-79.5 KB
...n/introduction-to-machine-learning-with-h2o-3-part-3/assets/flow-automl-reg.jpg
Diff not rendered.
Binary file removed
BIN
-279 KB
...achine-learning-with-h2o-3-part-3/assets/flow-automl-regression-leaderboard.jpg
Diff not rendered.
Binary file removed
BIN
-53.1 KB
...introduction-to-machine-learning-with-h2o-3-part-3/assets/flow-choose-frame.jpg
Diff not rendered.
Binary file removed
BIN
-100 KB
.../introduction-to-machine-learning-with-h2o-3-part-3/assets/flow-cl-automl-1.jpg
Diff not rendered.
Binary file removed
BIN
-98.8 KB
.../introduction-to-machine-learning-with-h2o-3-part-3/assets/flow-cl-automl-2.jpg
Diff not rendered.
Binary file removed
BIN
-114 KB
.../introduction-to-machine-learning-with-h2o-3-part-3/assets/flow-cl-automl-3.jpg
Diff not rendered.
Binary file removed
BIN
-187 KB
...troduction-to-machine-learning-with-h2o-3-part-3/assets/flow-cl-leaderboard.jpg
Diff not rendered.
Binary file removed
BIN
-92.4 KB
...rsion/introduction-to-machine-learning-with-h2o-3-part-3/assets/flow-frames.jpg
Diff not rendered.
Binary file removed
BIN
-22.9 KB
...roduction-to-machine-learning-with-h2o-3-part-3/assets/flow-gbm-predictions.jpg
Diff not rendered.
Binary file removed
BIN
-135 KB
...ion/introduction-to-machine-learning-with-h2o-3-part-3/assets/flow-instance.jpg
Diff not rendered.
Binary file removed
BIN
-27.1 KB
...tion-to-machine-learning-with-h2o-3-part-3/assets/flow-reg-view-leaderboard.jpg
Diff not rendered.
Binary file removed
BIN
-73.2 KB
...n/introduction-to-machine-learning-with-h2o-3-part-3/assets/flow-run-automl.jpg
Diff not rendered.
Binary file removed
BIN
-29.1 KB
...troduction-to-machine-learning-with-h2o-3-part-3/assets/flow-view-cl-automl.jpg
Diff not rendered.
Binary file removed
BIN
-34.4 KB
...ntroduction-to-machine-learning-with-h2o-3-part-3/assets/flow-xgb-predict-2.jpg
Diff not rendered.
Binary file removed
BIN
-51.6 KB
...on/introduction-to-machine-learning-with-h2o-3-part-3/assets/flow-xgb-preds.jpg
Diff not rendered.
Binary file removed
BIN
-45.2 KB
.../introduction-to-machine-learning-with-h2o-3-part-3/assets/gbm-actual-preds.jpg
Diff not rendered.
Binary file removed
BIN
-81.2 KB
...rsion/introduction-to-machine-learning-with-h2o-3-part-3/assets/gbm-predict.jpg
Diff not rendered.
Binary file removed
BIN
-21.7 KB
...sion/introduction-to-machine-learning-with-h2o-3-part-3/assets/gbm-test-per.jpg
Diff not rendered.
Binary file removed
BIN
-79.2 KB
...on/introduction-to-machine-learning-with-h2o-3-part-3/assets/gbm-view-preds.jpg
Diff not rendered.
Binary file removed
BIN
-71.1 KB
...ersion/introduction-to-machine-learning-with-h2o-3-part-3/assets/get-frames.jpg
Diff not rendered.
Binary file removed
BIN
-172 KB
...introduction-to-machine-learning-with-h2o-3-part-3/assets/leader-automl-reg.jpg
Diff not rendered.
Binary file removed
BIN
-15.3 KB
...version/introduction-to-machine-learning-with-h2o-3-part-3/assets/rate-dist.jpg
Diff not rendered.
Binary file removed
BIN
-2.07 MB
...rsion/introduction-to-machine-learning-with-h2o-3-part-3/assets/split-frame.gif
Diff not rendered.
Binary file removed
BIN
-44.4 KB
...ion/introduction-to-machine-learning-with-h2o-3-part-3/assets/std_coef_plot.jpg
Diff not rendered.
Binary file removed
BIN
-57.5 KB
...sion/introduction-to-machine-learning-with-h2o-3-part-3/assets/training-auc.jpg
Diff not rendered.
Binary file removed
BIN
-35.8 KB
.../introduction-to-machine-learning-with-h2o-3-part-3/assets/xgb-actual-preds.jpg
Diff not rendered.
Binary file removed
BIN
-116 KB
...rsion/introduction-to-machine-learning-with-h2o-3-part-3/assets/xgb-predict.jpg
Diff not rendered.
Binary file removed
BIN
-54.1 KB
...on/introduction-to-machine-learning-with-h2o-3-part-3/assets/xgb-view-preds.jpg
Diff not rendered.
576 changes: 0 additions & 576 deletions
576
...earning-with-h2o-3-part-3/introduction-to-machine-learning-with-h2o-3-part-3.md
This file was deleted.
Oops, something went wrong.
490 changes: 490 additions & 0 deletions
490
...on/.ipynb_checkpoints/introduction-to-machine-learning-with-h2o-3-automl-checkpoint.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
1,012 changes: 1,012 additions & 0 deletions
1,012
...b_checkpoints/introduction-to-machine-learning-with-h2o-3-classification-checkpoint.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
808 changes: 808 additions & 0 deletions
808
...ipynb_checkpoints/introduction-to-machine-learning-with-h2o-3-regression-checkpoint.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
490 changes: 490 additions & 0 deletions
490
H2O-3/h2o-3-tutorials-code /Python/introduction-to-machine-learning-with-h2o-3-automl.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
1,012 changes: 1,012 additions & 0 deletions
1,012
...3-tutorials-code /Python/introduction-to-machine-learning-with-h2o-3-classification.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
808 changes: 808 additions & 0 deletions
808
...h2o-3-tutorials-code /Python/introduction-to-machine-learning-with-h2o-3-regression.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
193 changes: 193 additions & 0 deletions
193
H2O-3/h2o-3-tutorials-code /R/RMD-files/AutoML Tutorial with H2O-3 with R.Rmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
--- | ||
title: "AutoML Tutorial with H2O-3 Using R" | ||
output: html_notebook | ||
--- | ||
|
||
This is an [R Markdown](http://rmarkdown.rstudio.com) Notebook. When you execute code within the notebook, the results appear beneath the code. To execute a code chunk, click *Run* (play) button within the chunk or by placing your cursor inside it and pressing *Cmd+Shift+Enter*. | ||
|
||
## Task 1: Initial Setup | ||
|
||
```{r} | ||
library(h2o) | ||
library(tidyverse) | ||
library(DT) | ||
h2o.init(bind_to_localhost = FALSE, context_path = "h2o") | ||
``` | ||
|
||
```{r} | ||
h2o.no_progress() | ||
``` | ||
|
||
```{r} | ||
loan_level <- h2o.importFile(path = "https://s3.amazonaws.com/data.h2o.ai/H2O-3-Tutorials/loan_level_50k.csv") | ||
``` | ||
|
||
## Task 2: Machine Learning Concepts - See Tutorial | ||
|
||
## Task 3: Start Experiment | ||
|
||
```{r} | ||
h2o.head(loan_level) %>% as_tibble() | ||
h2o.describe(loan_level) %>% as_tibble() | ||
``` | ||
|
||
```{r} | ||
h2o.table(loan_level[, c("DELINQUENT")]) | ||
``` | ||
|
||
```{r} | ||
h2o.hist(loan_level[, c("ORIGINAL_INTEREST_RATE")]) | ||
``` | ||
|
||
```{r} | ||
splits <- h2o.splitFrame(loan_level, c(0.8), seed = 42) | ||
train <- splits[[1]] | ||
test <- splits[[2]] | ||
dim(train) | ||
dim(test) | ||
``` | ||
|
||
## Task 4: H2O AutoML Classification | ||
|
||
```{r} | ||
ignore <- c("DELINQUENT", "PREPAID", "PREPAYMENT_PENALTY_MORTGAGE_FLAG", "PRODUCT_TYPE") | ||
y <- "DELINQUENT" | ||
x <- setdiff(colnames(train), ignore) | ||
x | ||
``` | ||
|
||
```{r} | ||
aml_cl <- h2o.automl(max_models = 25, max_runtime_secs_per_model = 30, | ||
seed = 42, project_name = "classification", | ||
balance_classes = TRUE, class_sampling_factors = c(0.5, 1.25), | ||
x = x, | ||
y = y, | ||
training_frame = train | ||
) | ||
``` | ||
|
||
```{r} | ||
lb <- h2o.get_leaderboard(aml_cl) | ||
h2o.head(lb, n = 25) | ||
``` | ||
|
||
```{r} | ||
lb2 <- h2o.get_leaderboard(aml_cl, extra_columns = "ALL") | ||
h2o.head(lb2, n = 25) | ||
``` | ||
|
||
```{r} | ||
# Get model ids for all models in the AutoML Leaderboard | ||
model_ids <- as.data.frame(aml_cl@leaderboard$model_id)[,1] | ||
# Get the "All Models" Stacked Ensemble model | ||
se <- h2o.getModel(grep("StackedEnsemble_AllModels", model_ids, value = TRUE)[1]) | ||
# Get the Stacked Ensemble metalearner model | ||
metalearner <- h2o.getModel(se@model$metalearner$name) | ||
``` | ||
|
||
```{r} | ||
h2o.coef(metalearner) | ||
h2o.coef_norm(metalearner) | ||
h2o.std_coef_plot(metalearner) | ||
``` | ||
|
||
```{r} | ||
aml_cl@leader | ||
``` | ||
|
||
```{r} | ||
aml_leader <- aml_cl@leader | ||
aml_leader_test_perf <- h2o.performance(aml_leader, test) | ||
``` | ||
|
||
```{r} | ||
h2o.auc(aml_leader_test_perf) | ||
plot(aml_leader_test_perf) | ||
``` | ||
|
||
```{r} | ||
aml_leader_pred <- h2o.predict(aml_leader, test) | ||
h2o.head(aml_leader_pred, n=10) | ||
``` | ||
|
||
## Task 5: h2O AutoML Regression | ||
|
||
```{r} | ||
ignore_reg <- c("ORIGINAL_INTEREST_RATE", "FIRST_PAYMENT_DATE", "MATURITY_DATE", "MORTGAGE_INSURANCE_PERCENTAGE", | ||
"PREPAYMENT_PENALTY_MORTGAGE_FLAG", "LOAN_SEQUENCE_NUMBER", "PREPAID", | ||
"DELINQUENT", "PRODUCT_TYPE") | ||
y_reg <- "ORIGINAL_INTEREST_RATE" | ||
x_reg <- setdiff(colnames(train), ignore_reg) | ||
x_reg | ||
``` | ||
|
||
```{r} | ||
aml_reg <- h2o.automl(max_runtime_secs = 900, max_runtime_secs_per_model = 30, seed = 42, | ||
project_name = "regression", stopping_metric = 'RMSE', sort_metric = 'RMSE', | ||
x = x_reg, | ||
y = y_reg, | ||
training_frame = train | ||
) | ||
``` | ||
|
||
```{r} | ||
lb <- h2o.get_leaderboard(aml_reg) | ||
h2o.head(lb, n = -1) | ||
``` | ||
|
||
To get specific models, you have two options | ||
|
||
```{r} | ||
# Get model ids for all models in the AutoML Leaderboard | ||
model_ids <- as.data.frame(aml_reg@leaderboard$model_id)[,1] | ||
# Get the "All Models" Stacked Ensemble model | ||
gbm <- h2o.getModel(grep("GBM_2", model_ids, value = TRUE)[1]) | ||
gbm | ||
``` | ||
|
||
And you can just get the model id and place it inside the parenthesis | ||
```{r} | ||
#gbm <- h2o.getModel("model_id") | ||
``` | ||
|
||
```{r} | ||
gbm@allparameters[["ntrees"]] | ||
gbm@allparameters[["max_depth"]] | ||
gbm@allparameters[["learn_rate"]] | ||
gbm@allparameters[["sample_rate"]] | ||
``` | ||
|
||
```{r} | ||
gbm | ||
``` | ||
|
||
```{r} | ||
gbm_test_perf <- h2o.performance(gbm, test) | ||
h2o.rmse(gbm_test_perf) | ||
h2o.mae(gbm_test_perf) | ||
``` | ||
|
||
```{r} | ||
gbm_pred <- h2o.predict(gbm, test) | ||
preds <- h2o.cbind(test[, c("ORIGINAL_INTEREST_RATE")], gbm_pred) | ||
h2o.head(preds, n=10) | ||
``` | ||
|
||
## For Task 6-8 please refer to md file ---- | ||
```{r} | ||
h2o.shutdown() | ||
``` |
Oops, something went wrong.