0% found this document useful (0 votes)
6 views3 pages

NitinKumar 12112147 DecisionTreeAssignment

Uploaded by

12112147
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

NitinKumar 12112147 DecisionTreeAssignment

Uploaded by

12112147
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

ML Assignment

Name: Nitin Kumar


Class: CS-B-07
Roll Number: 12112147

Decision Tree
Code:
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score, classification_report
from sklearn.preprocessing import LabelEncoder

file_path = './data.csv'
data = pd.read_csv(file_path)

data = data.drop(['id', 'Unnamed: 32'], axis=1)

le = LabelEncoder()
data['diagnosis'] = le.fit_transform(data['diagnosis'])

X = data.drop('diagnosis', axis=1)
y = data['diagnosis']

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2,


random_state=42)

clf = DecisionTreeClassifier(random_state=42)
clf.fit(X_train, y_train)

y_pred = clf.predict(X_test)

accuracy = accuracy_score(y_test, y_pred)


print(f"Decision Tree Classifier Accuracy: {accuracy:.2f}")
classification_rep = classification_report(y_test, y_pred,
target_names=['Benign', 'Malignant'])
print(classification_rep)

Output:

Code:
import matplotlib.pyplot as plt
from sklearn.tree import plot_tree

# Plot the decision tree


plt.figure(figsize=(20,10))
plot_tree(clf, feature_names=X.columns, class_names=['Benign', 'Malignant'],
filled=True, rounded=True)
plt.show()

Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy