Title: Random Forest Classifier
Slug: random_forest_classifier
Summary: Training a random forest classifier in scikit-learn.
Date: 2017-09-21 12:00
Category: Machine Learning
Tags: Trees And Forests
Authors: Chris Albon
In [1]:
# Load libraries
from sklearn.ensemble import RandomForestClassifier
from sklearn import datasets
In [2]:
# Load data
iris = datasets.load_iris()
X = iris.data
y = iris.target
In [3]:
# Create random forest classifer object that uses entropy
clf = RandomForestClassifier(criterion='entropy', random_state=0, n_jobs=-1)
In [4]:
# Train model
model = clf.fit(X, y)
In [5]:
# Make new observation
observation = [[ 5, 4, 3, 2]]
# Predict observation's class
model.predict(observation)
Out[5]: