<jupyter_start><jupyter_text><NAME> CS 2nd Year | Section : "I" | Roll no.: 01 Enrollment No.: 12019009001127 Advanced Artificial Intelligence and Machine Learning Lab 5 Faculty : PKB, MB, BM | Date : 23.03.2021  Decision Tree for Regression : Importing the Regressor Decision Tree Model : `from sklearn.tree import DecisionTreeRegressor`<jupyter_code>from sklearn.datasets import load_boston
import numpy as np
import pandas as pd
boston = load_boston()
data = pd.DataFrame(boston.data, columns = boston.feature_names)
data['MEDV'] = pd.DataFrame(boston.target)<jupyter_output><empty_output><jupyter_text>**Working with two attributes of the `boston dataset`, they are `RM` and `ZN`**<jupyter_code>x = data[['RM','ZN']]
y = data['MEDV']
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeRegressor
dt = DecisionTreeRegressor()
x_train1, x_test1, y_train1, y_test1 = train_test_split(x,y, test_size = 0.2)
dt.fit(x_train1, y_train1)
yTestPredict = dt.predict(x_test1)
from sklearn.metrics import mean_squared_error
np.sqrt(mean_squared_error(y_test1, yTestPredict))<jupyter_output><empty_output><jupyter_text>**Working with three attributes of `boston dataset`, they are `RM`, `ZN` and `LSTAT`**<jupyter_code>x = data[['RM','ZN', 'LSTAT']]
y = data['MEDV']
dt = DecisionTreeRegressor()
x_train1, x_test1, y_train1, y_test1 = train_test_split(x,y, test_size = 0.2)
dt.fit(x_train1, y_train1)
yTestPredict = dt.predict(x_test1)
np.sqrt(mean_squared_error(y_test1, yTestPredict))<jupyter_output><empty_output><jupyter_text>Two attribute model V/S Three attribute model using the Decision Tree regressor :| Model Type | Mean Squared Error Value ||:---:|:---:|| Two Attribute Model | 7.54 || Three Attribute Model | 5.29|  Decision Tree Classifier Model :Importing the Decision Tree Classifier Model from the sklearn package : `from sklearn.tree import DecisionTreeClassifier`<jupyter_code>from sklearn.tree import DecisionTreeClassifier
from sklearn.datasets import load_digits
import matplotlib.pyplot as plt
digits = load_digits()
x_train, x_test, y_train, y_test = train_test_split(digits.data,digits.target, test_size = 0.2)
dtc = DecisionTreeClassifier()
dtc.fit(x_train, y_train)
dtc.score(x_test, y_test)<jupyter_output><empty_output><jupyter_text>Here it means that **85.28%** values of the ```test dataset``` matched with the ```train dataset``` during the fitting operation with 80-20 dataset division<jupyter_code>x_train, x_test, y_train, y_test = train_test_split(digits.data,digits.target, test_size = 0.1)
dtc.fit(x_train, y_train)
dtc.score(x_test, y_test)<jupyter_output><empty_output><jupyter_text>Here it means that **89.44%** values of the ```test dataset``` matched with the ```train dataset``` during the fitting operation with 90-10 dataset division  Decision Tree Classifier Model Score with various division of data :| Model Type | Model Score ||:---:|:---:|| 80 - 20 Division | 85.28% || 90 - 10 Division | 89.44% |<jupyter_code>dtce = DecisionTreeClassifier(criterion = 'entropy')
dtce.fit(x_train, y_train)
dtce.score(x_test, y_test)
x_train, x_test, y_train, y_test = train_test_split(digits.data,digits.target, test_size = 0.2)
dtce.fit(x_train, y_train)
dtce.score(x_test, y_test)
x_train, x_test, y_train, y_test = train_test_split(digits.data,digits.target, test_size = 0.3)
dtce.fit(x_train, y_train)
dtce.score(x_test, y_test)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11967308814944541, 'fraction_numerical': 0.026853473438412143, 'mean_word_length': 6.951276102088167, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '244430', 'license': 'Apache-2.0', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1215, 'n_words': 306, 'path': 'Advanced AIML Lab/Advanced AI-ML Lab 5 23.03.2021.ipynb', 'repo_name': 'abhisheks008/Design-and-Analysis-Algorithm-Lab-4th-Semester', 'size': '3435'}