I have a rather simple question, but have not been able to find a documented solution anywhere.
I'm currently building a pipeline with H2O models and as part of the process I need to write some basic information about each trained model into a table.
Let's say I have something like:
model = H2ODeepLearningEstimator(...)
model.train(...)
After doing this, I want to pull the type of model from the model
object. I.e, I am looking for something like:
model.getType()
which then returns a string "H2ODeepLearningEstimator"
or equivalently "deeplearning"
which H2O appears to use internally as the model type identifier. I would also like to get other details, such as whether it was a regression or classification model. I don't see a parameter where this information is exposed.
if I run model.save_model_details
for example, I get:
H2ODeepLearningEstimator : Deep Learning
Model Key: Grid_DeepLearning_py_4_sid_a02a_model_python_1502450758585_2_model_0
ModelMetricsRegression: deeplearning
** Reported on train data. **
MSE: 19.5334650304
RMSE: 4.4196679774
MAE: 1.44489752843
RMSLE: NaN
Mean Residual Deviance: 19.5334650304
ModelMetricsRegression: deeplearning
** Reported on validation data. **
...
...
Presumably model.save_model_details
builds up this summary from individual parameters. I would like to access these (and similar) parameters directly via the model
object (for performance metrics this is possible via model.mse()
, model.mae()
etc.)
You can see all the methods for a model by typing model. then the tab key in the IPython terminal. They are printed alphabetically and that's a good way to find what you're looking for (even if you don't know the exact method name).
save_model (Python) function . This function accepts the model object and the file path. If no path is specified, then the model will be saved to the current working directory. After the model is saved, you can load it using the h2o. loadModel (R) or h2o.
What is a MOJO? ¶ A MOJO (Model Object, Optimized) is an alternative to H2O's POJO. As with POJOs, H2O allows you to convert models that you build to MOJOs, which can then be deployed for scoring in real time.
a quick way to see the model's corresponding h2o version number (if you used h2o. saveModel() to save the model) is to open the model's file - you should be able to see the version number within the first line (in the form 3.10. 4.2).
You can get some of the individual model metrics for your model based on training and/or validation data. Here is the code snippet:
import h2o
h2o.init(strict_version_check= False , port = 54345)
from h2o.estimators.deeplearning import H2ODeepLearningEstimator
model = H2ODeepLearningEstimator()
rows = [[1,2,3,4,0], [2,1,2,4,1], [2,1,4,2,1], [0,1,2,34,1], [2,3,4,1,0]] * 50
fr = h2o.H2OFrame(rows)
X = fr.col_names[0:4]
## Classification Model
fr[4] = fr[4].asfactor()
model.train(x=X, y="C5", training_frame=fr)
print('Model Type:', model.type)
print('logloss', model.logloss(valid = False))
print('Accuracy', model.accuracy(valid = False))
print('AUC', model.auc(valid = False))
print('R2', model.r2(valid = False))
print('RMSE', model.rmse(valid = False))
print('Error', model.error(valid = False))
print('MCC', model.mcc(valid = False))
## Regression Model
fr = h2o.H2OFrame(rows)
model.train(x=X, y="C5", training_frame=fr)
print('Model Type:', model.type)
print('R2', model.r2(valid = False))
print('RMSE', model.rmse(valid = False))
Note: As I did not pass validation frame thats why I set valid = False to get training metrics. If you have passed validation metrics then you can set valid = True to get validation metrics as well.
If you want to see what is inside model object you can look at the json object as below:
model.get_params()
h2o.algo gives you the model type. as for regression or classification, I don't know off the top of my head but it's their somewhere. Look on flow as its easier to see the parameter names their or do model. and scroll through until you see something that looks like it might have it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With