Source code for mlinsights.sklapi.sklearn_base_learner

# -*- coding: utf-8 -*-
"""
Implements a *learner* which follows the same API
as every :epkg:`scikit-learn` learner.


:githublink:`%|py|7`
"""
from .sklearn_base import SkBase


[docs]class SkBaseLearner(SkBase): """ Pattern of a *learner* qui suit la même API que :epkg:`scikit-learn`. :githublink:`%|py|14` """
[docs] def __init__(self, **kwargs): """ constructor :githublink:`%|py|19` """ SkBase.__init__(self, **kwargs)
################### # API scikit-learn ###################
[docs] def fit(self, X, y=None, sample_weight=None): """ Trains a model. :param X: features :param y: targets :param sample_weight: weight :return: self :githublink:`%|py|34` """ raise NotImplementedError()
[docs] def predict(self, X): """ Predicts. :param X: features :return: prédictions :githublink:`%|py|43` """ raise NotImplementedError()
[docs] def decision_function(self, X): """ Output of the model in case of a regressor, matrix with a score for each class and each sample for a classifier. :param X: Samples, {array-like, sparse matrix}, shape = (n_samples, n_features) :return: array, shape = (n_samples,.), Returns predicted values. :githublink:`%|py|54` """ raise NotImplementedError()
[docs] def score(self, X, y=None, sample_weight=None): """ Returns the mean accuracy on the given test data and labels. :param X: Training data, numpy array or sparse matrix of shape [n_samples,n_features] :param y: Target values, numpy array of shape [n_samples, n_targets] (optional) :param sample_weight: Weight values, numpy array of shape [n_samples, n_targets] (optional) :return: score : float, Mean accuracy of self.predict(X) wrt. y. :githublink:`%|py|65` """ raise NotImplementedError()