sklearndf.classification.GaussianNBDF#

class sklearndf.classification.GaussianNBDF(*, priors=None, var_smoothing=1e-09)[source]#

Gaussian Naive Bayes (GaussianNB).

Note

This class is a wrapper around class sklearn.naive_bayes.GaussianNB. It provides enhanced support for pandas data frames, and otherwise delegates all attribute access and method calls to an associated GaussianNB instance.

Bases

PartialFitClassifierWrapperDF [GaussianNB]

Metaclasses

EstimatorWrapperDFMeta, ABCMeta

Method summary

clone

Make an unfitted clone of this estimator.

decision_function

Compute the decision function for the given inputs.

fit

Fit this estimator using the given inputs.

from_fitted

Make a new wrapped DF estimator, delegating to a given native estimator that has already been fitted.

get_params

Get the parameters for this estimator.

partial_fit

Perform incremental fit on a batch of samples.

predict

Predict outputs for the given inputs.

predict_log_proba

Predict class log-probabilities for the given inputs.

predict_proba

Predict class probabilities for the given inputs.

score

Score this learner using the given inputs and outputs.

set_params

Set the parameters of this estimator.

to_expression

Render this object as an expression.

Attribute summary

COL_FEATURE

Name assigned to an Index or a Series with the names of the features used to fit a EstimatorDF.

COL_PREDICTION

Name of Series objects containing the predictions of single-output learners.

classes_

Get the classes predicted by this classifier as a numpy array of class labels for single-output problems, or a list of such arrays for multi-output problems

feature_names_in_

The pandas column index with the names of the features used to fit this estimator.

is_fitted

True if this object is fitted, False otherwise.

n_features_in_

The number of features used to fit this estimator.

n_outputs_

The number of outputs used to fit this estimator.

native_estimator

The native estimator that this wrapper delegates to.

output_names_

The name(s) of the output(s) this supervised learner was fitted to.

Definitions

clone()#

Make an unfitted clone of this estimator.

Return type

GaussianNBDF

Returns

the unfitted clone

decision_function(X, **predict_params)#

Compute the decision function for the given inputs.

The inputs must have the same features as the inputs used to fit this learner. The features can be provided in any order since they are identified by their column names.

Parameters
  • X (Union[Series, DataFrame]) – input data frame with observations as rows and features as columns

  • predict_params (Any) – optional keyword parameters as required by specific learner implementations

Return type

Union[Series, DataFrame]

Returns

a data frame with observations as rows and classes as columns, and values as the raw values predicted per observation and class; for multi-output classifiers, a list of one observation/class data frames per output

fit(X, y=None, **fit_params)#

Fit this estimator using the given inputs.

Parameters
  • X (Union[DataFrame, Series]) – input data frame with observations as rows and features as columns

  • y (Union[Series, DataFrame, None]) – an optional series or data frame with one or more outputs

  • fit_params (Any) – additional keyword parameters as required by specific estimator implementations

Return type

GaussianNBDF

Returns

self

classmethod from_fitted(estimator, features_in, n_outputs)#

Make a new wrapped DF estimator, delegating to a given native estimator that has already been fitted.

Parameters
  • estimator (GaussianNB) – the fitted native estimator to use as the delegate

  • features_in (Index) – the column names of X used for fitting the estimator

  • n_outputs (int) – the number of outputs in y used for fitting the estimator

Return type

GaussianNBDF

Returns

the wrapped data frame estimator

get_params(deep=True)#

Get the parameters for this estimator.

Parameters

deep (bool) – if True, return the parameters for this estimator, and for any sub-estimators contained in this estimator

Return type

Mapping[str, Any]

Returns

a mapping of parameter names to their values

partial_fit(X, y, classes=None, sample_weight=None)#

Perform incremental fit on a batch of samples.

This method is meant to be called multiple times for subsets of training data which, e.g., couldn’t fit in the required memory in full. It can be also used for online learning.

Parameters
  • X (Union[Series, DataFrame]) – data frame with observations as rows and features as columns

  • y (Union[Series, DataFrame]) – a series or data frame with one or more outputs per observation

  • classes (Optional[Sequence[Any]]) – all classes present across all calls to partial_fit; only required for the first call of this method

  • sample_weight (Optional[Series]) – optional weights applied to individual samples

Return type

GaussianNBDF

Returns

self

predict(X, **predict_params)#

Predict outputs for the given inputs.

The inputs must have the same features as the inputs used to fit this learner. The features can be provided in any order since they are identified by their column names.

Parameters
  • X (Union[Series, DataFrame]) – input data frame with observations as rows and features as columns

  • predict_params (Any) – optional keyword parameters as required by specific learner implementations

Return type

Union[Series, DataFrame]

Returns

predictions per observation as a series, or as a data frame in case of multiple outputs

predict_log_proba(X, **predict_params)#

Predict class log-probabilities for the given inputs.

The inputs must have the same features as the inputs used to fit this learner. The features can be provided in any order since they are identified by their column names.

Parameters
  • X (Union[Series, DataFrame]) – input data frame with observations as rows and features as columns

  • predict_params (Any) – optional keyword parameters as required by specific learner implementations

Return type

Union[DataFrame, List[DataFrame]]

Returns

a data frame with observations as rows and classes as columns, and values as log-probabilities per observation and class; for multi-output classifiers, a list of one observation/class data frames per output

predict_proba(X, **predict_params)#

Predict class probabilities for the given inputs.

The inputs must have the same features as the inputs used to fit this learner. The features can be provided in any order since they are identified by their column names.

Parameters
  • X (Union[Series, DataFrame]) – input data frame with observations as rows and features as columns

  • predict_params (Any) – optional keyword parameters as required by specific learner implementations

Return type

Union[DataFrame, List[DataFrame]]

Returns

a data frame with observations as rows and classes as columns, and values as probabilities per observation and class; for multi-output classifiers, a list of one observation/class data frames per output

score(X, y, sample_weight=None)#

Score this learner using the given inputs and outputs.

Parameters
  • X (Union[Series, DataFrame]) – data frame with observations as rows and features as columns

  • y (Series) – a series or data frame with the true outputs per observation

  • sample_weight (Optional[Series]) – optional series of scalar weights, for calculating the resulting score as the weighted mean of the scores for the individual predictions

Return type

float

Returns

the score

set_params(**params)#

Set the parameters of this estimator.

Valid parameter keys can be obtained by calling get_params().

Parameters

params (Any) – the estimator parameters to set

Return type

GaussianNBDF

Returns

self

to_expression()#

Render this object as an expression.

Return type

Expression

Returns

the expression representing this object

property classes_: Union[numpy.ndarray[Any, numpy.dtype[Any]], List[numpy.ndarray[Any, numpy.dtype[Any]]]]#

Get the classes predicted by this classifier as a numpy array of class labels for single-output problems, or a list of such arrays for multi-output problems

Raises

AttributeError – this classifier is not fitted

Return type

Union[ndarray[Any, dtype[Any]], List[ndarray[Any, dtype[Any]]]]

property feature_names_in_: pandas.Index#

The pandas column index with the names of the features used to fit this estimator.

Raises

AttributeError – this estimator is not fitted

Return type

Index

property is_fitted: bool#

True if this object is fitted, False otherwise.

Return type

bool

property n_features_in_: int#

The number of features used to fit this estimator.

Raises

AttributeError – this estimator is not fitted

Return type

int

property n_outputs_: int#

The number of outputs used to fit this estimator.

Raises

AttributeError – this estimator is not fitted

Return type

int

property native_estimator: sklearndf.wrapper.T_NativeEstimator#

The native estimator that this wrapper delegates to.

Return type

TypeVar(T_NativeEstimator, bound= BaseEstimator)

property output_names_: List[str]#

The name(s) of the output(s) this supervised learner was fitted to.

Raises

sklearn.exceptions.NotFittedError – this estimator is not fitted

Return type

List[str]