Machine Learning - Random Forest Regression (Part 7)

It can be called as Ensemble Learning

Ensemble learning is basically using same algorithms multiple times.

Here in random forest, we use Decision tree multiple times and take the average.

Again , if you have 100 numbers and 100 people to predict, you can let others predict and once a person predicts , you can write that down. Once 50 or some good number of prediction is done, if you choose the average value of prediction, you might win.

Let's code and learn

Problem statement: We want to appoint a regional manager and in the interview, he said that he was a regional manager for 2 years at XYZ company.

We have collected the data sheet and found out the salary of a regional manager is 150k in a year. As the person worked for 2 years, the salary can be in the range between level 6 & 7. Surely, it will be less than Partner 200k.

So, we can guess it 6.5 level to get an approximate idea and offer him the salary according to experience

Coding time:

Let's import library & dataset

Then

from sklearn.ensemble import RandomForestRegressor

regressor = RandomForestRegressor(n_estimators=10, random_state=0)

n_estimators means number of trees & random_state is fixed so that, we get same output

regressor.fit(X,y)

Predicting a new result

regressor.predict([[6.5]])

we know why we used 6.5 here

if we see it visually

Done!

Check out the code

The dataset

Great!!