Random Forest Regression Algorithm Explain with Project

In this ML Algorithms course tutorial, we are going to learn “Random Forest Regression in detail. we covered it by practically and theoretical intuition.

  1. What is Random Forest?
  2. What is Random Forest used for?
  3. How do Random Forest work?
  4. What is Random Forest Regression?
  5. What is Gini impurity, entropy, cost function for CART algorithm?
  6. What is Random Forest diagram?
  7. What is the difference between decision tree and random forest?
  8. How to implement Random Forest Regression in python using sklearn?

Random Forest Project Source Code

# -*- coding: utf-8 -*-
"""Random Forest Regression.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1X0LsHDOtyFeIN266qfVrOFXDrkJ5ESU3

## Business Problem - Predict the Price of Bangalore House

Using Randome Forest Regression - Supervised Machine Learning Algorithm

### Load Libraries
"""

import pandas as pd

"""### Load Data"""

path = r"https://drive.google.com/uc?export=download&id=1xxDtrZKfuWQfl-6KA9XEd_eatitNPnkB" 
df = pd.read_csv(path)

df.head()

"""## Split Data"""

X = df.drop('price', axis=1)
y = df['price']

print('Shape of X = ', X.shape)
print('Shape of y = ', y.shape)

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=51)

print('Shape of X_train = ', X_train.shape)
print('Shape of y_train = ', y_train.shape)
print('Shape of X_test = ', X_test.shape)
print('Shape of y_test = ', y_test.shape)

"""##Randome Forest Regression - ML Model Training"""

from sklearn.ensemble import RandomForestRegressor

regressor = RandomForestRegressor(n_estimators=100, criterion='mse')
regressor.fit(X_train, y_train)

regressor.score(X_test, y_test)

regressor_100 = RandomForestRegressor(n_estimators=500, criterion='mse')
regressor_100.fit(X_train, y_train)

regressor_100.score(X_test, y_test)

"""## Predict the value of Home"""

X_test.iloc[-1, :]

regressor.predict([X_test.iloc[-1, :]])

y_test.iloc[-1]

y_pred = regressor.predict(X_test)
y_pred

y_test

Leave a Reply

Top