7-8-NaiveBayesian-recognise-images.py 548 B

12345678910111213141516171819
  1. from sklearn.naive_bayes import GaussianNB
  2. from sklearn.model_selection import cross_val_score, train_test_split
  3. from datasets import Datasets
  4. def main():
  5. train_data, vaild_data, test_data = Datasets.load_mnist()
  6. x_train, y_train = train_data
  7. x_test, y_test = test_data
  8. gnb = GaussianNB()
  9. gnb.fit(x_train, y_train)
  10. print(gnb.score(x_test, y_test)) # 0.5544
  11. scores = cross_val_score(gnb, x_test, y_test, cv=3, scoring="accuracy")
  12. print(scores.mean()) # 0.5752038611179655
  13. if __name__ == "__main__":
  14. main()