from sklearn.datasets import load_digits
digits = load_digits()

from sklearn.naive_bayes import GaussianNB
from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(digits.data, digits.target)

print(len(X_train), len(X_test), y_train, y_test)

clf = GaussianNB()
clf.fit(X_train, y_train)

predicted = clf.predict(X_test)
expected = y_test
print(predicted)
print(expected)

"""
Explanation: Gaussian Naive Bayes Classification
For most classification problems, it’s nice to have a simple, fast method to provide a quick baseline classification. If the simple and fast method is sufficient, then we don’t have to waste CPU cycles on more complex models. If not, we can use the results of the simple method to give us clues about our data.
One good method to keep in mind is Gaussian Naive Bayes (sklearn.naive_bayes.GaussianNB).
Gaussian Naive Bayes fits a Gaussian distribution to each training label independantly on each feature, and uses this to quickly give a rough classification. It is generally not sufficiently accurate for real-world data, but can perform surprisingly well, for instance on text data.
End of explanation
"""


matches = (predicted == expected)
print(matches)

print(matches.sum())
print(len(matches))
qmp = matches.sum() / float(len(matches))
print(qmp)

"""
Explanation: Quantitative Measurement of Performance
End of explanation
"""


from sklearn import metrics
print(metrics.classification_report(expected, predicted))

"""
Explanation: We see that more than 80% of the 450 predictions match the input. But there are other more sophisticated metrics that can be used to judge the performance of a classifier: several are available in the sklearn.metrics submodule.
One of the most useful metrics is the classification_report, which combines several measures and prints a table with the results:
End of explanation
"""


print(metrics.confusion_matrix(expected, predicted))

"""
Explanation: Another enlightening metric for this sort of multi-label classification is a confusion matrix: it helps us visualize which labels are being interchanged in the classification errors:
End of explanation
"""


