from IPython.display import Image
Image(filename='/home/deploy/pramit/h20_partial_plot.png')

"""
Explanation: Partial plot and variable importance in h20
``` r
library(h2o)
h2o.init(nthreads = -1)
prostate.path = system.file("extdata", "prostate.csv", package="h2o")
prostate.hex = h2o.uploadFile(path = prostate.path, destination_frame = "prostate.hex")
prostate.hex[, "CAPSULE"] <- as.factor(prostate.hex[, "CAPSULE"] )
prostate.hex[, "RACE"] <- as.factor(prostate.hex[,"RACE"] )
prostate.gbm = h2o.gbm(x = c("AGE","RACE", "DPROS", "DCAPS", "PSA", "VOL", "GLEASON"),
                       y = "CAPSULE",
                       training_frame = prostate.hex,
                       ntrees = 10,
                       max_depth = 5,
                       learn_rate = 0.1)
h2o.partialPlot(object = prostate.gbm, data = prostate.hex, cols = c("AGE", "RACE"))
Note: the above mentioned library is a REST interface to JVM based code base
the partial plot on gbm is only works in the global space, there is no option to get information at the for individual prediction.
Things to note:
1. The current implementation is supported for regression and binomial classification models.
Reference: https://github.com/h2oai/h2o-3/blob/master/h2o-core/src/main/java/hex/PartialDependence.java
2. Gritty details of thread-safety, algorithm parallelism, and node coherence on a network are concealed by simple-to-use REST calls
3. The level of support for R binding is different compared to that of python. Seems like the support in R could be language agnostic(need to check more). In python partial_plot and varimp is supported for the following mentioned model types: * gbm, distributed random forest(drf), deep-learning
Reference: https://a-ghorbani.github.io/2016/11/24/data-science-with-h2o#interpretation-of-the-model
4. No support for interpretation for individual prediction
5. Also, there seems to be activity and continuous development around interepretation on their end as well
Reference: https://github.com/h2oai/h2o-3/blob/907a9676aa81a2ce968e51d776a26f680f192f2b/h2o-py/h2o/model/model_base.py
```
End of explanation
"""


from IPython.display import Image
Image(filename='/home/deploy/pramit/var_importance.png')

Image(filename='/home/deploy/pramit/variable_importance_plot.png')

"""
Explanation: Variable importance in h20
r
h2o.varimp_plot(prostate.gbm)
h2o.varimp(prostate.gbm)
End of explanation
"""


import h2o
from h2o.estimators.gbm import H2OGradientBoostingEstimator
# Initializes the REST server(dumps the h2o.jar at the right location and starts the server)
h2o.init()

h2o.cluster().show_status()

df = h2o.import_file(path="/usr/local/lib/python2.7/dist-packages/h2o/h2o_data/prostate.csv")

model = H2OGradientBoostingEstimator(ntrees=10, max_depth=5)     # setup the gbm

df['CAPSULE'] = df['CAPSULE'].asfactor()
df['RACE'] = df['RACE'].asfactor()

# Describe the data
df.describe()

m = model.train(x=df.names[2:], y="CAPSULE", training_frame=df)

# 
model.partial_plot(data=df, cols=["AGE", "RACE", "DPROS"], destination_key=None, nbins=20, plot=True, figsize=(7, 10), 
                   server=False)

model.varimp_plot
#Reference: http://docs.h2o.ai/h2o/latest-stable/h2o-py/docs/_modules/h2o/model/model_base.html#ModelBase.varimp_plot

"""
Explanation: In python
End of explanation
"""


