## How to use Classification Metrics in Python
## DataSet: skleran.load_breast_cancer()
def Snippet_181():
print()
print(format('How to use Classification Metrics in Python','*^82'))
import warnings
warnings.filterwarnings("ignore")
# load libraries
from sklearn import datasets
from sklearn import tree, model_selection, metrics
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
plt.style.use('ggplot')
# load the datasets
seed = 42
dataset = datasets.load_breast_cancer()
X = dataset.data; y = dataset.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25)
kfold = model_selection.KFold(n_splits=10, random_state=seed)
# fit a tree.DecisionTreeClassifier() model to the data
model = tree.DecisionTreeClassifier()
# metrics -> Accuracy
scoring = 'accuracy'
results = model_selection.cross_val_score(model, X_train, y_train, cv=kfold, scoring=scoring)
print(); print("Accuracy: ", results.mean()); print("Standard Deviation: ", results.std())
# metrics -> Logarithmic loss
scoring = 'neg_log_loss'
results = model_selection.cross_val_score(model, X_train, y_train, cv=kfold, scoring=scoring)
print(); print("Logloss: ", results.mean()); print("Standard Deviation: ", results.std())
# metrics -> Area Under ROC Curve
scoring = 'roc_auc'
results = model_selection.cross_val_score(model, X_train, y_train, cv=kfold, scoring=scoring)
print(); print("AUC: ", results.mean()); print("Standard Deviation: ", results.std())
# make predictions with fitted model
model.fit(X_train, y_train)
expected_y = y_test
predicted_y = model.predict(X_test)
# summarize the fit of the model
print(); print('tree.DecisionTreeClassifier(): ')
print(); print(metrics.classification_report(expected_y, predicted_y,
target_names=dataset.target_names))
print(); print(metrics.confusion_matrix(expected_y, predicted_y))
Snippet_181()