Random Forest Classification with H2O [Python][for Beginners]

Roshan Alwis
Oct 27, 2016 · 3 min read
Image for post
Image for post

H2O is an opensource machine learning platform that facilitates you to build models based on data that you have. This article will let you discover how H2O machine learning can apply for simple classification problem.

Note : For this tutorial, you need to setup H2O in your python environment.

To create a Random Forest Classification model H2ORandomForestEstimator will instantiate you a model object.

Check whether if it is possible to connect to an existing H2O instance. If it fails, attempt to create a local H2O instance at localhost:54321.

Copy ‘iris.csvfile into your project folder. This file contains the data that required to train your model. You need to add headers to the data set manually.

Image for post
Image for post
Figure 1 : Adding headers to the data set

Read the iris.csv file and load the data as an H2O frame.

Based on sepal length, sepal width, petal length and petal width data it is required to identify the class that each iris flower belongs to.

Define the training parameters, input and target parameters.

Split the data set into train and test. The testing data will help you to verify the validity of your model after creating it. And it will also prevent model over fitting to the given data.

Define the model with required parameters and train it.

Finally, it is time to see the performance of the model.

Image for post
Image for post
Figure 2: Test Results

You can see that the model identifies the class of iris flowers correctly without having any misprediction. When you run this program, the answers can be slightly varied. Because random forest algorithm uses randomly created trees for ensemble learning. And also when splitting data for training and testing, H2O is using a random splitting which can change the data in each frame.

Full Project

Tech Vision

Things I have learned :)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

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