0% found this document useful (0 votes)
7 views1 page

Decision Tree Classifier for Cancer Data

Uploaded by

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

Decision Tree Classifier for Cancer Data

Uploaded by

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

# 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

# Load dataset
data = load_breast_cancer()
X = [Link]
y = [Link]

# Split data into training and testing sets


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

# Create and train decision tree classifier


clf = DecisionTreeClassifier(random_state=42)
[Link](X_train, y_train)

# Make predictions on test set


y_pred = [Link](X_test)

accuracy = accuracy_score(y_test, y_pred)


print(f"Model Accuracy: {accuracy * 100:.2f}%")

# Classify a new sample (using first test sample as example)


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}")

# Visualize the decision tree


[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]()

You might also like