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

Decision Tree Classifier for Breast Cancer

The document outlines a program that implements a decision tree algorithm using the Breast Cancer dataset to classify samples. It includes steps for data loading, model training, prediction, and accuracy evaluation. Additionally, it visualizes the decision tree structure using matplotlib.

Uploaded by

sadiqhamuskan4
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 views2 pages

Decision Tree Classifier for Breast Cancer

The document outlines a program that implements a decision tree algorithm using the Breast Cancer dataset to classify samples. It includes steps for data loading, model training, prediction, and accuracy evaluation. Additionally, it visualizes the decision tree structure using matplotlib.

Uploaded by

sadiqhamuskan4
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

Program 8

8. Develop a program to demonstrate the working of the decision tree algorithm. Use Breast
Cancer Data set for building the decision tree and apply this knowledge to classify a new sample.

# Importing necessary libraries


import numpy as np
import [Link] as plt
from [Link] import load_breast_cancer
from sklearn.model_selection import train_test_split
from [Link] import DecisionTreeClassifier
from [Link] import accuracy_score
from sklearn import tree

data = load_breast_cancer()
X = [Link]
y = [Link]

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)
[Link](X_train, y_train)
y_pred = [Link](X_test)

accuracy = accuracy_score(y_test, y_pred)


print(f"Model Accuracy: {accuracy * 100:.2f}%")
new_sample = [Link]([X_test[0]])
prediction = [Link](new_sample)

prediction_class = "Benign" if prediction == 1 else "Malignant"


print(f"Predicted Class for the new sample: {prediction_class}")

[Link](figsize=(12,8))
tree.plot_tree(clf, filled=True, feature_names=data.feature_names, class_names=data.target_names)
[Link]("Decision Tree - Breast Cancer Dataset")
[Link]()

output:

You might also like