<gh_stars>1-10
# -*- coding: utf-8 -*-
"""ML-M5-DTR.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1FtFGOHqGlYJnaBFV42ZcQJ4EPQWhXzGq
"""

#importing libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#dataset 
dataset = pd.read_csv('Position_Salaries.csv')
x=dataset.iloc[:,1:-1].values
y=dataset.iloc[:,-1].values
#print(x)
#print(y)

#model
from sklearn.tree import DecisionTreeRegressor
regressor = DecisionTreeRegressor(random_state=0)
regressor.fit(x,y)
#predicing value
print(regressor.predict([[6.5]]))


#visualising the result
x_grid = np.arange(min(x), max(x), 0.01)
x_grid = x_grid.reshape((len(x_grid), 1))
plt.scatter(x, y, color = 'red')
plt.plot(x_grid, regressor.predict(x_grid), color = 'blue')
plt.title('Decision Tree Regression')
plt.xlabel('Position level')
plt.ylabel('Salary')
plt.show()