Rajiv Shah commited on
Commit
e87dc49
1 Parent(s): ceefbb2

add py script

Browse files
Files changed (1) hide show
  1. H2O_Example.py +47 -0
H2O_Example.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # %%
2
+ import h2o
3
+
4
+ # %%
5
+ h2o.__version__
6
+
7
+ # %%
8
+ h2o.init()
9
+
10
+ # %%
11
+ from h2o.estimators import H2OGradientBoostingEstimator
12
+ h2o.init(jvm_custom_args=["sys.ai.h2o.debug.allowJavaVersions", "18"])
13
+
14
+ # Import the prostate dataset into H2O:
15
+ prostate = h2o.import_file("http://s3.amazonaws.com/h2o-public-test-data/smalldata/prostate/prostate.csv")
16
+
17
+ # Set the predictors and response; set the factors:
18
+ prostate["CAPSULE"] = prostate["CAPSULE"].asfactor()
19
+ predictors = ["ID","AGE","RACE","DPROS","DCAPS","PSA","VOL","GLEASON"]
20
+ response = "CAPSULE"
21
+
22
+ # Build and train the model:
23
+ pros_gbm = H2OGradientBoostingEstimator(nfolds=5,
24
+ seed=1111,
25
+ keep_cross_validation_predictions = True)
26
+ pros_gbm.train(x=predictors, y=response, training_frame=prostate)
27
+
28
+ # Eval performance:
29
+ perf = pros_gbm.model_performance()
30
+
31
+ # Generate predictions on a test set (if necessary):
32
+ pred = pros_gbm.predict(prostate)
33
+
34
+ # Extract feature interactions:
35
+ feature_interactions = pros_gbm.feature_interaction()
36
+
37
+ # %%
38
+ feature_interactions
39
+
40
+ # %%
41
+ #save model
42
+ h2o.save_model(model=pros_gbm, force=True)
43
+
44
+ # %%
45
+ pros_gbm.save_mojo('mojo')
46
+
47
+