Classification Demo
Classification Demo
[ ]: import pandas as pd
url = "https://raw.githubusercontent.com/LahiruTjay/
↪Machine-Learning-With-Python/master/datasets/diabetes.csv"
[ ]: data.head()
[5 rows x 9 columns]
[ ]: import numpy as np
data_array = np.asarray(data)
[ ]: data_array.shape
[ ]: (768, 9)
[ ]: feature = data_array[:,0:8 ]
[ ]: label = data_array[:,-1]
1
[ ]: print(x_train.shape, x_test.shape, y_train.shape, y_test.shape)
naive = GaussianNB()
naive.fit(x_train,y_train)
y_pred_naive = naive.predict(x_test)
print("Naive Bayes")
print("Accuracy score =", accuracy_score(y_test, y_pred_naive))
print(classification_report(y_test, y_pred_naive ))
plot_confusion_matrix(naive, x_test, y_test, normalize='true')
Naive Bayes
Accuracy score = 0.7662337662337663
precision recall f1-score support
/usr/local/lib/python3.7/dist-packages/sklearn/utils/deprecation.py:87:
FutureWarning: Function plot_confusion_matrix is deprecated; Function
`plot_confusion_matrix` is deprecated in 1.0 and will be removed in 1.2. Use one
of the class methods: ConfusionMatrixDisplay.from_predictions or
ConfusionMatrixDisplay.from_estimator.
warnings.warn(msg, category=FutureWarning)
[ ]: <sklearn.metrics._plot.confusion_matrix.ConfusionMatrixDisplay at
0x7f0983686c10>
2
[ ]: from sklearn.tree import DecisionTreeClassifier
decision = DecisionTreeClassifier()
decision.fit(x_train,y_train)
y_pred_decision = decision.predict(x_test)
print("Decision Tree")
print("Accuracy score =", accuracy_score(y_test, y_pred_decision))
print(classification_report(y_test, y_pred_decision ))
plot_confusion_matrix(decision, x_test, y_test, normalize='true')
Decision Tree
Accuracy score = 0.7467532467532467
precision recall f1-score support
/usr/local/lib/python3.7/dist-packages/sklearn/utils/deprecation.py:87:
FutureWarning: Function plot_confusion_matrix is deprecated; Function
`plot_confusion_matrix` is deprecated in 1.0 and will be removed in 1.2. Use one
of the class methods: ConfusionMatrixDisplay.from_predictions or
3
ConfusionMatrixDisplay.from_estimator.
warnings.warn(msg, category=FutureWarning)
[ ]: <sklearn.metrics._plot.confusion_matrix.ConfusionMatrixDisplay at
0x7f09836acbd0>
[ ]: