Q:

example of Random Forest Regression in Python

0

write a code in python to apply the Random Forest Technique 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np

import matplotlib.pyplot as plt

import pandas as pd

data = pd.read_csv('Salaries.csv')


from sklearn.ensemble import RandomForestRegressor


regressor = RandomForestRegressor(n_estimators = 100, random_state = 0)
 
regressor.fit(x, y) 
Y_pred = regressor.predict(np.array([6.5]).reshape(1, 1))
X_grid = np.arrange(min(x), max(x), 0.01)               

X_grid = X_grid.reshape((len(X_grid), 1)) 

plt.scatter(x, y, color = 'blue')  
 
plt.plot(X_grid, regressor.predict(X_grid),   color = 'green') 

plt.title('Random Forest Regression')

plt.xlabel('Position level')

plt.ylabel('Salary')
plt.show()

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now