File size: 1,168 Bytes
e87dc49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# %%
import h2o

# %%
h2o.__version__

# %%
h2o.init()

# %%
from h2o.estimators import H2OGradientBoostingEstimator
h2o.init(jvm_custom_args=["sys.ai.h2o.debug.allowJavaVersions", "18"])

# Import the prostate dataset into H2O:
prostate = h2o.import_file("http://s3.amazonaws.com/h2o-public-test-data/smalldata/prostate/prostate.csv")

# Set the predictors and response; set the factors:
prostate["CAPSULE"] = prostate["CAPSULE"].asfactor()
predictors = ["ID","AGE","RACE","DPROS","DCAPS","PSA","VOL","GLEASON"]
response = "CAPSULE"

# Build and train the model:
pros_gbm = H2OGradientBoostingEstimator(nfolds=5,
                                        seed=1111,
                                        keep_cross_validation_predictions = True)
pros_gbm.train(x=predictors, y=response, training_frame=prostate)

# Eval performance:
perf = pros_gbm.model_performance()

# Generate predictions on a test set (if necessary):
pred = pros_gbm.predict(prostate)

# Extract feature interactions:
feature_interactions = pros_gbm.feature_interaction()

# %%
feature_interactions

# %%
#save model
h2o.save_model(model=pros_gbm, force=True)

# %%
pros_gbm.save_mojo('mojo')