autoqild.classifiers.bayes_predictorΒΆ

A Bayes-optimal classifier leveraging the underlying probability distribution of the dataset for predictions.

Classes

BayesPredictor(dataset_obj[, random_state])

A Bayes-optimal classifier that predicts on the given dataset using the defined joint and conditional distributions.

class autoqild.classifiers.bayes_predictor.BayesPredictor(dataset_obj, random_state=None, **kwargs)[source]ΒΆ

Bases: BaseEstimator, ClassifierMixin

A Bayes-optimal classifier that predicts on the given dataset using the defined joint and conditional distributions. This classifier leverages a dataset object, used to generate underlying data, which represents the best-performing classifier. This class stores the PDFs and predicts class probabilities and labels given the input features.

Parameters:
  • dataset_obj (object) – An object representing the dataset. This object should provide methods like generate_dataset, get_prob_y_given_x, and get_prob_flip_y_given_x.

  • random_state (int or None, optional, default=None) – Random state for reproducibility.

  • **kwargs (dict, optional) – Additional keyword arguments.

dataset_objΒΆ

The dataset object provided during initialization. Used for generating datasets and computing class probabilities.

Type:

object

random_stateΒΆ

Random state instance for reproducibility.

Type:

RandomState

loggerΒΆ

Logger instance for logging information.

Type:

logging.Logger

n_classesΒΆ

Number of classes in the classification data samples. Set during the fit method.

Type:

int or None

decision_function(X, verbose=0)[source]ΒΆ

Compute the decision function for the input samples.

The decision function returns the probability estimates of the positive class for binary classification problems.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – The input samples.

  • verbose (int, optional, default=0) – Verbosity level.

Returns:

scores – The decision function values.

Return type:

array-like of shape (n_samples,)

fit(X, y, **kwd)[source]ΒΆ

Fit the BayesPredictor model.

This method sets the number of classes in the training data but does not perform any actual fitting. It is intended to be overridden or expanded in a subclass.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – The training input samples.

  • y (array-like of shape (n_samples,)) – The target values (class labels).

  • **kwd (dict, optional) – Additional keyword arguments.

get_bayes_predictor_scores()[source]ΒΆ

Generate datasets and evaluate the accuracy of the Bayes predictor.

This method generates multiple datasets and evaluates the accuracy of the Bayes predictor on each one. It returns the true and predicted labels along with the prediction probabilities for the dataset that achieved the highest accuracy.

Returns:

  • y_true (array-like of shape (n_samples,)) – The true labels for the dataset with the highest accuracy.

  • y_pred (array-like of shape (n_samples,)) – The predicted labels for the dataset with the highest accuracy.

  • p_pred (array-like of shape (n_samples, n_classes)) – The predicted probabilities for the dataset with the highest accuracy.

predict(X, verbose=0)[source]ΒΆ

Predict class labels for the input samples.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – The input samples.

  • verbose (int, optional, default=0) – Verbosity level.

Returns:

y_pred – Predicted class labels.

Return type:

array-like of shape (n_samples,)

predict_proba(X, verbose=0)[source]ΒΆ

Predict class probabilities for the input samples.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – The input samples.

  • verbose (int, optional, default=0) – Verbosity level.

Returns:

p_pred – Predicted class probabilities.

Return type:

array-like of shape (n_samples, n_classes)

score(X, y, sample_weight=None, verbose=0)[source]ΒΆ

Compute the accuracy of the predictions.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – The input samples.

  • y (array-like of shape (n_samples,)) – The true labels.

  • sample_weight (array-like of shape (n_samples,), optional) – Sample weights.

  • verbose (int, optional, default=0) – Verbosity level.

Returns:

accuracy_score – The accuracy score.

Return type:

float