Loading…
DS · Classification · Program 20 · In the record
Naive Bayes classification.
1from sklearn.datasets import load_iris2from sklearn.model_selection import train_test_split3from sklearn.naive_bayes import GaussianNB4from sklearn.metrics import accuracy_score5 6X, y = load_iris(return_X_y=True)7X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)8 9nb = GaussianNB().fit(X_train, y_train)10print("Naive Bayes Accuracy:", accuracy_score(y_test, nb.predict(X_test)))Naive Bayes Accuracy: 0.9777777777777777

Run program 20 in your browser
Python 3.14 · Pyodide. Change the code or the input, run it, break it, and see what happens.