In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
In [2]:
dataset = pd.read_csv('Position_Salaries.csv')
dataset.head(2)
Out[2]:
In [3]:
x = dataset.iloc[:,1:2].values
y = dataset.iloc[:,2].values
In [4]:
from sklearn.tree import DecisionTreeRegressor
reg = DecisionTreeRegressor()
reg.fit(x,y)
plt.scatter(x,y)
plt.plot(x,reg.predict(x))
reg.predict(6.5)
Out[4]:
In [5]:
x_grid = np.arange(min(x),max(x),0.01)
x_grid = x_grid.reshape(len(x_grid),1)
plt.scatter(x,y)
plt.plot(x_grid,reg.predict(x_grid))
Out[5]:
In [ ]:
Comments
Post a Comment