9.3.2. sklearn.naive_bayes.GaussianNB¶
- class sklearn.naive_bayes.GaussianNB¶
Gaussian Naive Bayes (GaussianNB)
Parameters : X : array-like, shape = [n_samples, n_features]
Training vector, where n_samples in the number of samples and n_features is the number of features.
y : array, shape = [n_samples]
Target vector relative to X
Examples
>>> import numpy as np >>> X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]]) >>> Y = np.array([1, 1, 1, 2, 2, 2]) >>> from sklearn.naive_bayes import GaussianNB >>> clf = GaussianNB() >>> clf.fit(X, Y) GaussianNB() >>> print clf.predict([[-0.8, -1]]) [1]
Attributes
class_prior array, shape = [n_classes] probability of each class. theta array, shape [n_classes * n_features] mean of each feature for the different class sigma array, shape [n_classes * n_features] variance of each feature for the different class Methods
fit(X, y) self Fit the model predict(X) array Predict using the model. predict_proba(X) array Predict the probability of each class using the model. predict_log_proba(X) array Predict the log-probability of each class using the model. - __init__()¶
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
- fit(X, y)¶
Fit Gaussian Naive Bayes according to X, y
Parameters : X : array-like, shape = [n_samples, n_features]
Training vectors, where n_samples is the number of samples and n_features is the number of features.
y : array-like, shape = [n_samples]
Target values.
Returns : self : object
Returns self.
- predict(X)¶
Perform classification on an array of test vectors X.
Parameters : X : array-like, shape = [n_samples, n_features] Returns : C : array, shape = [n_samples]
- predict_log_proba(X)¶
Return log-probability estimates for the test vector X.
Parameters : X : array-like, shape = [n_samples, n_features]
Returns : C : array-like, shape = [n_samples, n_classes]
Returns the log-probability of the sample for each class in the model, where classes are ordered by arithmetical order.
- predict_proba(X)¶
Return probability estimates for the test vector X.
Parameters : X : array-like, shape = [n_samples, n_features]
Returns : C : array-like, shape = [n_samples, n_classes]
Returns the probability of the sample for each class in the model, where classes are ordered by arithmetical order.
- score(X, y)¶
Returns the mean error rate on the given test data and labels.
Parameters : X : array-like, shape = [n_samples, n_features]
Training set.
y : array-like, shape = [n_samples]
Labels for X.
Returns : z : float
- set_params(**params)¶
Set the parameters of the estimator.
The method works on simple estimators as well as on nested objects (such as pipelines). The former have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Returns : self :