Warning: Declaration of action_plugin_tablewidth::register(&$controller) should be compatible with DokuWiki_Action_Plugin::register(Doku_Event_Handler $controller) in /s/bach/b/class/cs545/public_html/fall16/lib/plugins/tablewidth/action.php on line 93
===== Naive Bayes in scikit-learn ====
Scikit-learn provides both Gaussian and multinomial/binomial flavors of Naive Bayes.
Here's a code snippet that uses the Gaussian version and shows the resulting decision boundary for toy 2-d data (it uses ''decision_boundary.py'' from a [[code:nearest_neighbors | previous demo]]):
import numpy as np
from sklearn.datasets import make_blobs
from sklearn.naive_bayes import GaussianNB
import decision_boundary
X, y = make_blobs(n_samples=1500, random_state=2)
classifier = GaussianNB()
decision_boundary.plot_boundary(classifier, X, y)
transformation = [[ 0.60834549, -0.63667341], [-0.40887718, 0.85253229]]
X, y = make_blobs(n_samples=1500, random_state=170)
X_aniso = np.dot(X, transformation)
decision_boundary.plot_boundary(classifier, X_aniso, y)
X_varied, y_varied = make_blobs(n_samples=1500,
cluster_std=[1.0, 2.5, 0.5],
random_state=170)
decision_boundary.plot_boundary(classifier, X_varied, y_varied)