<jupyter_start><jupyter_text>Importing all the required libraries<jupyter_code>import numpy as np
import requests
import io
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score
from sklearn.metrics import confusion_matrix
from sklearn.metrics import classification_report
import matplotlib.pyplot as plt
from sklearn.preprocessing import LabelEncoder<jupyter_output><empty_output><jupyter_text>**Reading the Balance-Scale Dataset**<jupyter_code>df = pd.read_csv(r"/content/balance-scale.data")
df.head(10)<jupyter_output><empty_output><jupyter_text>**Checking if any null value exists and if it does then replacing it**<jupyter_code>df.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 624 entries, 0 to 623
Data columns (total 5 columns):
 #   Column  Non-Null Count  Dtype 
---  ------  --------------  ----- 
 0   B       624 non-null    object
 1   1       624 non-null    int64 
 2   1.1     624 non-null    int64 
 3   1.2     624 non-null    int64 
 4   1.3     624 non-null    int64 
dtypes: int64(4), object(1)
memory usage: 24.5+ KB<jupyter_text>**Since no Null value exists, replacing isn't required.. moving further****Lets Replace the name of the columns for better understanding of the data.**<jupyter_code>df = df.rename(columns = {'B': 'Class', '1': 'LeftWeight','1.1':'LeftDistance','1.2':'RightWeight','1.3':'RightDistance'}, inplace = False)
df<jupyter_output><empty_output><jupyter_text>Seperating features as X and target value as y : - 'Class' in Y- 'LeftWeight', 'RightWeight', 'LeftDistance', 'RightDistance' in XSpliting the X and Y in four DataFrame :train_X, test_X, train_Y and test_Y using train_test_splitand keeping the test_size as 150 to check value for 150 values for better precision of the data.<jupyter_code>X=df[['LeftWeight','LeftDistance','RightWeight', 'RightDistance']].copy()
Y=df[['Class']]
train_X, test_X, train_Y, test_Y = train_test_split(X, Y, test_size = 150)<jupyter_output><empty_output><jupyter_text>Classification and prediction using **Desicion Tree** Classifier :<jupyter_code>clf = DecisionTreeClassifier()
clf.fit(train_X, train_Y)
pred = clf.predict(test_X)
print('Accuracy  = ',clf.score(test_X, test_Y)*100)<jupyter_output>Accuracy  =  74.66666666666667<jupyter_text>That ends Our Desicion tree classifying method.Lets see the **Confusion matrix** now Creating an array first for the formation of matrix<jupyter_code>x=np.array(X)
y=np.array(Y)<jupyter_output><empty_output><jupyter_text>Running the matrix data<jupyter_code>c_matrix= confusion_matrix(test_Y,pred,labels=['L','R','B'])
c_matrix<jupyter_output><empty_output><jupyter_text>Running the appropriate test and printing the report's<jupyter_code>matrix=classification_report(test_Y,pred,labels=['L','R','B'])
print('classification_report: \n',matrix)<jupyter_output>classification_report: 
               precision    recall  f1-score   support

           L       0.83      0.86      0.85        58
           R       0.86      0.79      0.83        78
           B       0.00      0.00      0.00        14

    accuracy                           0.75       150
   macro avg       0.56      0.55      0.56       150
weighted avg       0.77      0.75      0.76       150
{'fraction_non_alphanumeric': 0.11070998796630566, 'fraction_numerical': 0.04542719614921781, 'mean_word_length': 3.962686567164179, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '458697', 'license': 'MIT', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1075, 'n_words': 281, 'path': 'Keshav Project Submission/Desicion_tree.ipynb', 'repo_name': 'Neklaustares-tPtwP/SDS-Group-6-Final-Task', 'size': '3324'}