scikit-learn
if you haven’t already: pip install scikit-learn
from sklearn.naive_bayes import GaussianNB
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_iris
# Load the Iris dataset
data = load_iris()
X = data.data
y = data.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
# Initialize the model
model = GaussianNB()
# Train the model
model.fit(X_train, y_train)
# Make predictions on the test set
y_pred = model.predict(X_test)
# Evaluate the model
from sklearn.metrics import accuracy_score
accuracy = accuracy_score(y_test, y_pred)
print(f"Accuracy: {accuracy}")
That’s it! This code will train a Gaussian Naive Bayes model on the Iris dataset and evaluate its accuracy. You can, of course, replace the Iris dataset with your own data.
Source: ChatGPT
You need to login in order to like this post: click here
YOU MIGHT ALSO LIKE