andrewssobral's picture
Added gaussian_naive_bayes example
de41f58
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import joblib
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
# Load the model from disk
loaded_model = joblib.load('gaussian_nb.joblib')
# Set the random seed
random_seed = 0
# Load the dataset
dataset = load_iris()
X, y = dataset.data, dataset.target
# Split the dataset into training and testing sets
_, X_test, _, y_test = train_test_split(X, y, test_size=0.25, random_state=random_seed)
print(f'X_test:\n{X_test[0]}')
print(f'y_test:\n{y_test[0]}')
# Use the model to make predictions on the test data
y_pred = loaded_model.predict(X_test)
print(f'y_pred:\n{y_pred[0]}')
# Score the model using accuracy classification score
acc = accuracy_score(y_test, y_pred)
print(f'Accuracy classification score: {acc}')