autoqild.automl.automl_coreΒΆ
Abstract base class for AutoML classifiers.
Classes
Abstract base class for AutoML classifiers. |
- class autoqild.automl.automl_core.AutomlClassifier[source]ΒΆ
Bases:
BaseEstimator,ClassifierMixinAbstract base class for AutoML classifiers.
This class serves as a base for implementing various AutoML classifiers. It inherits from sklearn.base.BaseEstimator and sklearn.base.ClassifierMixin, providing standard interfaces for scikit-learn estimators and classifiers.
The class is abstract, meaning it cannot be instantiated directly. Subclasses must implement the βfitβ method to provide functionality for training the classifier.
Examples
To create a custom AutoML classifier, you can subclass AutomlClassifier and implement the required methods, such as βfitβ, βfitβ, and βfitβ. Below is an example of how you might implement a simple custom classifier.
First, create a subclass of AutomlClassifier:
>>> from sklearn.pipeline import Pipeline >>> class CustomClassifier(AutomlClassifier): >>> def fit(self, X, y, **kwd): >>> # Implement your fitting logic here >>> # For instance, you might train a model using the training data X and labels y >>> self.model_ = Pipeline([("scaler", StandardScaler()), ("custom_classifier", CustomClassifier())]) >>> return self >>> >>> def predict(self, X, verbose=0): >>> # Implement your prediction logic here >>> # For example, use the trained model to make predictions on new data X >>> return self.model_.predict(X) >>> >>> def score(self, X, y, sample_weight=None, verbose=0): >>> # Implement your scoring logic here >>> # For instance, calculate the accuracy of predictions compared to true labels y >>> predictions = self.predict(X) >>> return accuracy_score(y, predictions) >>> >>> def predict_proba(self, X, verbose=0): >>> # Implement your probability prediction logic here >>> # For example, return the predicted probabilities for each class >>> return self.model_.predict_proba(X) >>> >>> def decision_function(self, X, verbose=0): >>> # Implement your decision function logic here >>> # For instance, return the decision function values (e.g., distances to decision boundary) >>> return self.model_.decision_function(X)
After defining your custom classifier, you can use it like any other scikit-learn estimator:
>>> clf = CustomClassifier() >>> clf.fit(X_train, y_train) >>> predictions = clf.predict(X_test) >>> accuracy = clf.score(X_test, y_test)
- abstract decision_function(X, verbose=0)[source]ΒΆ
Predict confidence scores for samples, sometimes coinciding with the probability scores in X. The confidence score for a sample is proportional to the signed distance of that sample to the hyperplane.
- Parameters:
X (array-like of shape (n_samples, n_features)) β Input samples.
verbose (int, optional, default=0) β Verbosity level.
- Returns:
decision β Predicted confidence scores.
- Return type:
array-like of shape (n_samples,)
- Raises:
NotImplementedError β If the method is not implemented by the subclass.
- abstract fit(X, y, **kwd)[source]ΒΆ
Fit the AutoML classifier on the provided dataset.
- Parameters:
X (array-like of shape (n_samples, n_features)) β Training data.
y (array-like of shape (n_samples,)) β Target values.
**kwd (keyword arguments) β Additional parameters for the fit method.
- Returns:
self β Returns the instance itself.
- Return type:
object
- Raises:
NotImplementedError β If the method is not implemented by the subclass.
Notes
This method must be implemented by subclasses. It should contain the logic for training the classifier on the dataset provided in X and y.
- get_params(deep=True)[source]ΒΆ
Get parameters for this estimator.
- Parameters:
deep (bool, default=True) β If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns:
params β Parameter names mapped to their values.
- Return type:
dict
- abstract predict(X, verbose=0)[source]ΒΆ
Predict class labels for samples in X.
- Parameters:
X (array-like of shape (n_samples, n_features)) β Input samples.
verbose (int, optional, default=0) β Verbosity level.
- Returns:
y_pred β Predicted class labels.
- Return type:
array-like of shape (n_samples,)
- Raises:
NotImplementedError β If the method is not implemented by the subclass.
- abstract predict_proba(X, verbose=0)[source]ΒΆ
Predict class probabilities for samples in X.
- Parameters:
X (array-like of shape (n_samples, n_features)) β Input samples.
verbose (int, optional, default=0) β Verbosity level.
- Returns:
y_proba β Predicted class probabilities.
- Return type:
array-like of shape (n_samples, n_classes)
- Raises:
NotImplementedError β If the method is not implemented by the subclass.
- abstract score(X, y, sample_weight=None, verbose=0)[source]ΒΆ
Return the score based on the metric on the given test data and labels.
- Parameters:
X (array-like of shape (n_samples, n_features)) β Test samples.
y (array-like of shape (n_samples,) or (n_samples, n_outputs)) β True labels for X.
sample_weight (array-like of shape (n_samples,), default=None) β Sample weights.
verbose (int, optional, default=0) β Verbosity level.
- Returns:
score β Mean accuracy of self.predict(X) with respect to y.
- Return type:
float
- Raises:
NotImplementedError β If the method is not implemented by the subclass.
- set_params(**parameters)[source]ΒΆ
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as sklearn.pipeline.Pipeline). The latter have parameters of the form <component>__<parameter> so that it`s possible to update each component of a nested object.
- Parameters:
**params (dict) β Estimator parameters.
- Returns:
self β Estimator instance.
- Return type:
estimator instance