# Random Forest Regression

#### Latest posts by Renuka Joshi (see all)

- Image Classification Using CNN - May 13, 2018
- Convolutional Neural Networks - May 12, 2018
- Hierarchical Clustering - March 15, 2018

What comes to mind when we think of a forest after knowing about a tree ? In previous article we learned about decision tree regression and now will learn about random forest regression.

# Random Forest Regression:

It uses ensemble learning. It either takes multiple algorithms or one algorithm multiple times and calculates predictions by taking average of predictions of algorithms. Random forest regression takes an input parameter to tell the number of decision trees.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# Importing the libraries import numpy as np import matplotlib.pyplot as plt import pandas as pd # Importing the dataset dataset = pd.read_csv('Position_Salaries.csv') X = dataset.iloc[:, 1:2].values y = dataset.iloc[:, 2].values # Fitting Random Forest Regression to the dataset from sklearn.ensemble import RandomForestRegressor regressor = RandomForestRegressor(n_estimators = 10000, random_state = 0) regressor.fit(X, y) # Predicting a new result y_pred = regressor.predict(8.3) |

- We imported RandomForestRegressor.
- Created regressor object with 1000 estimators. It is like creating 1000 decision trees for random forest.
- fit X and y in regressor.

After fitting data in RandomForestRegressor, we simply predicted value of y_pred and it came to be 193113 which is a quite close prediction to actual value 190000.

Pingback:Random Forest Classification - theJavaGeek

Dear Rnuka,

Great article, thanks for sharing your knowledge.