Skip to content

Instantly share code, notes, and snippets.

@ashokc
Created January 16, 2019 15:25
Show Gist options
  • Save ashokc/baead23da3140974ff2fae31a33c85e2 to your computer and use it in GitHub Desktop.
Save ashokc/baead23da3140974ff2fae31a33c85e2 to your computer and use it in GitHub Desktop.
Naive Bayes Implementation with SciKit
from sklearn.naive_bayes import MultinomialNB
model = MultinomialNB()
train_x = Xencoded[train_indices]
test_x = Xencoded[test_indices]
train_labels = labels[train_indices]
test_labels = labels[test_indices]
model.fit(train_x, train_labels)
predicted_labels = model.predict(test_x)
print (confusion_matrix(labels[test_indices], predicted_labels))
print (classification_report(labels[test_indices], predicted_labels, digits=4, target_names=namesInLabelOrder))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment