# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="8WFDwPtP-vS0"
# Importing the necessary libraries

# + id="grQqCwTK1nFq"
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# + [markdown] id="JY8cs54mAde3"
# Importing the dataset

# + id="lTxcW8sh18iF"
dataset=pd.read_csv("Salaries.csv")
X=dataset.iloc[:,1:-1].values
y=dataset.iloc[:,-1].values

# + id="NyTF_mkW3Rci"
print(X)

# + id="BhF-bRLoAid6"
print(y)

# + [markdown] id="Ng-pD-RvAk37"
# Importing the Random Forest Regression Model

# + id="vVupFrjx2PzH"
from sklearn.ensemble import RandomForestRegressor
rfr=RandomForestRegressor(n_estimators=100000,random_state=0)
rfr.fit(X,y)

# + [markdown] id="sLmKmJS5_EnS"
# Predicting a value from the built model

# + id="NelK3WL92P6j"
rfr.predict([[6.5]])

# + [markdown] id="ZzE6Q9lx_Bmh"
# Visualising the predictions

# + id="q05mKyRa2P_S"
X_grid = np.arange(min(X),max(X),0.1)  # makes a horizontal array
X_grid= X_grid.reshape((len(X_grid),1))    #To make it a vertical array
plt.scatter(X,y,color='red')
plt.plot(X_grid,rfr.predict(X_grid),color='blue')
plt.title("Truth vs Bluff (Random Forest Regression)")
plt.xlabel("Level")
plt.ylabel("Salary")
plt.show()

# + id="pwMRL5uX3aOL"
# print(X_grid)

StarcoderdataJupyterScriptsDedupFiltered