Applying AutoML (Part-4) using H2O

Also, Check out our Article on:


Python Implementation

→ Installing H2O AutoML

!pip install h2o

→ Importing Packages

import h2o 
from h2o.automl import H2OAutoML

→ Initializing the H2O Cluster


→ Reading the data

crime = h2o.import_file("")

→ Checking data statistics

crime['Criminal'] = crime['Criminal'].asfactor()

→ Splitting the data

train, valid, test = crime.split_frame(ratios=[0.7,0.2], seed=1234)print("Number of rows in train : ", train.shape[0])
print("Number of rows in test : ", test.shape[0])
print("Number of rows in Validation : ", valid.shape[0])

→ fitting the data

aml = H2OAutoML(max_models = 10, max_runtime_secs=300,exclude_algos=
['StackedEnsemble','DeepLearning'], seed = 1)

→ Training H2O AutoML

aml.train(x = independent_features, y = dependent_features,
training_frame = train, validation_frame=valid)

→ Checking the Leaderboard

lb = aml.leaderboardlb.head(10)

→ getting model explanation

explain_model = aml.leader.explain(train)

→ Predicting on test data

preds = aml.predict(test)

→ Checking model performance on test data


Also, Check out our Article on:

Visit us on



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store



One of India’s leading institutions providing world-class Data Science & AI programs for working professionals with a mission to groom Data leaders of tomorrow!