Lab 8: Random Forest Classification

CILO: 2
Weeks: 30–32
Lab #8

Aim

Build a random forest classifier and evaluate predictions on a toy sample.

Objectives

Algorithm / Procedure

  1. Define X, y.
  2. Instantiate RandomForestClassifier(n_estimators=50).
  3. Fit, then predict [1,2].

Python Code

from sklearn.ensemble import RandomForestClassifier

X = [[0,0],[1,1],[2,2],[3,3]]
y = [0,1,1,0]

clf = RandomForestClassifier(n_estimators=50, random_state=0).fit(X, y)
print("Prediction for [1,2]:", clf.predict([[1,2]])[0])

Sample Output (expected)

Prediction for [1,2]: 1