Question: Question : The question has 2 task, the 1 task i have completed and now I am stuck in 2 task. - the 2 task

Question : The question has 2 task, the 1 task i have completed and now I am stuck in 2 task.

- the 2 task question is mention below:

  • Import required module fromsklearn.tree.
  • Build a Decision tree Regressor model fromX_trainset andY_trainlabels, with default parameters. Name the model asdt_reg.
  • Evaluate the model accuracy on training data set and print it's score.
  • Evaluate the model accuracy on testing data set and print it's score.
  • Predict the housing price for first two samples ofX_testset and print them.(Hint : Use predict() function)

The program which I have written is mentioned below which is wrong kindly correct me

import sklearn.datasets as datasets

from sklearn.model_selection import train_test_split

from sklearn.datasets import load_boston

import sklearn.model_selection as model_selection

from sklearn.tree import DecisionTreeRegressor

from sklearn import metrics

import pandas as pd

import numpy as np

# task 1

np.random.seed(100)

boston = datasets.load_boston()

X_train, X_test, Y_train, Y_test = model_selection.train_test_split(boston.data, boston.target,random_state = 30)

print(X_train.shape)

print(X_test.shape)

#task 2

dt_reg = DecisionTreeRegressor()

dt_reg = dt_reg.fit(X_train, Y_train)

print('Accuracy of Train Data :', dt_reg.score(X_train,Y_train))

print('Accuracy of Test Data :', dt_reg.score(X_test,Y_test))

y_pred = dt_reg.predict(X_test)

print(y_pred[0:2])

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!