Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

Students also viewed these Programming questions