#importing libraries

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

#loading dataset

dataset = pd.read_csv('dataset.csv')

#summarizing dataset

print(dataset.shape)
print(dataset.head(5))

#Segregating Dataset into Input X & Output Y

X = dataset.iloc[:, :-1].values
X

Y = dataset.iloc[:, -1].values
Y

#Splitting Dataset for Testing our Model

from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test = train_test_split(X,Y,test_size=0.20,random_state=0)

#Training Dataset using Decision Tree

from sklearn.tree import DecisionTreeRegressor  
model = DecisionTreeRegressor()  
model.fit(x_train, y_train)

#Visualizing Graph

X_val = np.arange(min(x_train), max(x_train), 0.01) 
X_val = X_val.reshape((len(X_val), 1))
plt.scatter(x_train, y_train, color = 'green') 
plt.plot(X_val, model.predict(X_val), color = 'red')  
plt.title('Height prediction using DecisionTree') 
plt.xlabel('Age') 
plt.ylabel('Height') 
plt.figure()
plt.show()

#Prediction for all test data for validation

ypred = model.predict(x_test)

from sklearn.metrics import r2_score,mean_squared_error
mse = mean_squared_error(y_test,ypred)
rmse=np.sqrt(mse)
print("Root Mean Square Error:",rmse)
r2score = r2_score(y_test,ypred)
print("R2Score",r2score*100)