from
sklearn.datasets
import
load_breast_cancer
from
sklearn.model_selection
import
train_test_split
from
sklearn.tree
import
DecisionTreeClassifier
from
sklearn.metrics
import
confusion_matrix
import
seaborn as sns
import
matplotlib.pyplot as plt
from
sklearn.metrics
import
accuracy_score, precision_score, recall_score, f1_score
X, y
=
load_breast_cancer(return_X_y
=
True
)
X_train, X_test, y_train, y_test
=
train_test_split(X, y,test_size
=
0.25
)
tree
=
DecisionTreeClassifier(random_state
=
23
)
tree.fit(X_train, y_train)
y_pred
=
tree.predict(X_test)
cm
=
confusion_matrix(y_test,y_pred)
sns.heatmap(cm,
annot
=
True
,
fmt
=
'g'
,
xticklabels
=
[
'malignant'
,
'benign'
],
yticklabels
=
[
'malignant'
,
'benign'
])
plt.ylabel(
'Prediction'
,fontsize
=
13
)
plt.xlabel(
'Actual'
,fontsize
=
13
)
plt.title(
'Confusion Matrix'
,fontsize
=
17
)
plt.show()
accuracy
=
accuracy_score(y_test, y_pred)
print
(
"Accuracy :"
, accuracy)
precision
=
precision_score(y_test, y_pred)
print
(
"Precision :"
, precision)
recall
=
recall_score(y_test, y_pred)
print
(
"Recall :"
, recall)
F1_score
=
f1_score(y_test, y_pred)
print
(
"F1-score :"
, F1_score)