scikit-learn Classification RandomForestClassifier

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

A random forest is a meta estimator that fits a number of decision tree classifiers on various sub-samples of the dataset and use averaging to improve the predictive accuracy and control over-fitting.

A simple usage example:

Import:

from sklearn.ensemble import RandomForestClassifier

Define train data and target data:

train = [[1,2,3],[2,5,1],[2,1,7]]
target = [0,1,0]

The values in target represent the label you want to predict.

Initiate a RandomForest object and perform learn (fit):

rf = RandomForestClassifier(n_estimators=100)
rf.fit(train, target)

Predict:

test = [2,2,3]
predicted = rf.predict(test)


Got any scikit-learn Question?