<jupyter_start><jupyter_text>模型导出与部署  连接h2o<jupyter_code>import h2o
from h2o.estimators.gbm import H2OGradientBoostingEstimator as gbm
import os
os.getcwd()
h2o.connect(url="http://localhost:54321")
df = h2o.import_file("./data/prostate.csv")
df.describe<jupyter_output>Parse progress: |█████████████████████████████████████████████████████████| 100%<jupyter_text>训练模型<jupyter_code># build gbm model
df["CAPSULE"] = df["CAPSULE"].asfactor()
model = gbm(distribution="bernoulli",
                   ntrees=100,
                   max_depth=4,
                   learn_rate=0.1)
model.train(y="CAPSULE",
    x=["AGE","RACE","PSA","GLEASON"],
    training_frame=df)
model.summary<jupyter_output>Model Details
=============
H2OGradientBoostingEstimator :  Gradient Boosting Machine
Model Key:  GBM_model_python_1536024753790_205


ModelMetricsBinomial: gbm
** Reported on train data. **

MSE: 0.09537207826782426
RMSE: 0.30882370094897876
LogLoss: 0.31983456503030233
Mean Per-Class Error: 0.12241225418214274
AUC: 0.9538308715556708
Gini: 0.9076617431113416
Confusion Matrix (Act/Pred) for max f1 @ threshold = 0.4595432309334924:<jupyter_text>模型结果导出<jupyter_code># mojo
# 已经下载过h2o-genmodel.jar了
info = model.download_mojo(path="./experiments",get_genmodel_jar=False)
print("Model saved to " + info)
# pojo
model.download_pojo(path="./experiments/")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16715116279069767, 'fraction_numerical': 0.11773255813953488, 'mean_word_length': 5.919597989949748, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '561600', 'license': 'MIT', 'n_tokens_mistral': 698, 'n_tokens_neox': 568, 'n_words': 79, 'path': 'codes/mojo-Python.ipynb', 'repo_name': 'BruceZhaoR/h2o-model-deploy', 'size': '1376'}