Random Forest
Random Forest
Random Forest
Random Forest is an extension over bagging. This algorithm takes the random selection of features rather
than using all features to grow trees along with taking the random subset of data. Decision trees, being prone
to overfit, have been transformed to random forest by training many trees over various subsamples of the
data. Random forest works well on large datasets, but might be time consuming and can be parallelized
across multicore processor. Random forest works pretty well for classification problems.
DATASET:
The objective is to identify each of a large number of black-and-white rectangular pixel displays as one of the
26 capital letters in the English alphabet. The character images were based on 20 different fonts and each
letter within these 20 fonts was randomly distorted to produce a file of 20,000 unique stimuli. Each stimulus
was converted into 16 primitive numerical attributes (statistical moments and edge counts) which were then
scaled to fit into a range of integer values from 0 through 15. We typically train on the first 16000 items and
then use the resulting model to predict the letter category for the remaining 4000. See the article cited above
for more details.
Attribute Information:
PYTHON CODE:
# importing libraries
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import classification_report
from sklearn.metrics import accuracy_score
from sklearn.metrics import confusion_matrix
import numpy
import pandas
# Reading dataset
letterdata = pandas.read_csv(‘ …….csv’)
print(“Dimension of dataset: “, letterdata.shape)
print(“Names of the variables:\n”, letterdata.columns)