Random Forest Classifier using Scikit-learn

GeoSense ✅
2 min readMar 31, 2023

Random Forest is a popular ensemble learning method that can be used for classification and regression tasks. It builds multiple decision trees and aggregates their predictions to improve accuracy and reduce overfitting. Scikit-learn is a popular Python library for machine learning, including Random Forest Classifier.

Random Forest Classifier

Here’s an example of how to use Random Forest Classifier in Scikit-learn:

# importing required libraries 
# importing Scikit-learn library and datasets package
from sklearn import datasets

# Loading the iris plants dataset (classification)
iris = datasets.load_iris()
print(iris.target_names)
print(iris.feature_names)
['setosa' 'versicolor' 'virginica']
['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)']
# dividing the datasets into two parts i.e. training datasets and test datasets
X, y = datasets.load_iris( return_X_y = True)

# Splitting arrays or matrices into random train and test subsets
from sklearn.model_selection import train_test_split
# i.e. 70 % training dataset and 30 % test datasets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.30)
# importing random forest classifier from assemble module
from sklearn.ensemble import RandomForestClassifier
import…

--

--

GeoSense ✅
GeoSense ✅

Written by GeoSense ✅

🌏 Remote sensing | 🛰️ Geographic Information Systems (GIS) | ℹ️ https://www.tnmthai.com/medium

No responses yet