<jupyter_start><jupyter_text>Random Forest Regression1.   Create a model to predict the previous salary based on the position level.2.   **Input** = Position_Salaries.csv  Importing the libraries<jupyter_code>import numpy as np
import matplotlib.pyplot as plt       #graphs
import pandas as pd<jupyter_output><empty_output><jupyter_text>Importing the dataset<jupyter_code>dataset = pd.read_csv('Position_Salaries.csv')
x = dataset.iloc[:, 1:-1].values      #There is no need to use the column Position
y = dataset.iloc[:,-1].values<jupyter_output><empty_output><jupyter_text>Training the RFR model on the whole dataset<jupyter_code>from sklearn.ensemble import RandomForestRegressor
regressor = RandomForestRegressor(random_state = 0, n_estimators = 10) #n_estimators = max number of trees for the predictions
regressor.fit(x,y)                                                     #For n <10, it is not so accurate... Yet, n>10 is almost the same..<jupyter_output><empty_output><jupyter_text>Predicting a new result<jupyter_code>regressor.predict([[6.5]])<jupyter_output><empty_output><jupyter_text>Visualising the SVR results<jupyter_code>plt.scatter(x, y, color = 'red', label='Real Data')
plt.plot(x,regressor.predict(x), color = 'green', label='Predicted Regression' )
plt.title('Position x Salary')
plt.xlabel('Position')
plt.ylabel('Salary')
plt.legend()
plt.show()      #It seems ok, but...<jupyter_output><empty_output><jupyter_text>Visualising the VSR  results HD<jupyter_code>x_grid = np.arange(min(x), max(x), 0.1)
x_grid = x_grid.reshape((len(x_grid),1))
plt.scatter(x,y,color='red')
plt.plot(x_grid, regressor.predict(x_grid),color='black')
plt.title('Random Forest Regression Graph HD')
plt.xlabel('Position level')
plt.ylabel('Salary')
plt.show()    #As for Decision Trees, this model is not an ideal method for simpler datasets!!!<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12366737739872068, 'fraction_numerical': 0.00906183368869936, 'mean_word_length': 5.6325088339222615, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '659213', 'license': 'MIT', 'n_tokens_mistral': 663, 'n_tokens_neox': 633, 'n_words': 150, 'path': 'Part 2 - Regression/Sec11- Random Forest Regression/ML_AZ_Sec11_Random_Forest_Regression.ipynb', 'repo_name': 'ThiagoBuen/Machine-Learning-A-Z', 'size': '1876'}