Fork me on GitHub

sklearn.naive_bayes.GaussianNB

class sklearn.naive_bayes.GaussianNB

Gaussian Naive Bayes (GaussianNB)

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 per class
sigma_ array, shape = [n_classes, n_features] variance of each feature per class

Methods

fit(X, y) Fit Gaussian Naive Bayes according to X, y
get_params([deep]) Get parameters for this estimator.
predict(X) Perform classification on an array of test vectors X.
predict_log_proba(X) Return log-probability estimates for the test vector X.
predict_proba(X) Return probability estimates for the test vector X.
score(X, y[, sample_weight]) Returns the mean accuracy on the given test data and labels.
set_params(**params) Set the parameters of this estimator.
__init__()

x.__init__(...) initializes x; see help(type(x)) 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.

get_params(deep=True)

Get parameters for this estimator.

Parameters:

deep: boolean, optional :

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params : mapping of string to any

Parameter names mapped to their values.

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]

Predicted target values for X

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 samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.

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 samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.

score(X, y, sample_weight=None)

Returns the mean accuracy on the given test data and labels.

Parameters:

X : array-like, shape = (n_samples, n_features)

Test samples.

y : array-like, shape = (n_samples,)

True labels for X.

sample_weight : array-like, shape = [n_samples], optional

Sample weights.

Returns:

score : float

Mean accuracy of self.predict(X) wrt. y.

set_params(**params)

Set the parameters of this 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 :
Previous
Next