Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# -*- coding: utf-8 -*-
2"""
3@file
4@brief Implements a *learner* which follows the same API
5as every :epkg:`scikit-learn` learner.
6"""
7from .sklearn_base import SkBase
10class SkBaseLearner(SkBase):
12 """
13 Pattern of a *learner* qui suit la même API que :epkg:`scikit-learn`.
14 """
16 def __init__(self, **kwargs):
17 """
18 constructor
19 """
20 SkBase.__init__(self, **kwargs)
22 ###################
23 # API scikit-learn
24 ###################
26 def fit(self, X, y=None, sample_weight=None):
27 """
28 Trains a model.
30 @param X features
31 @param y targets
32 @param sample_weight weight
33 @return self
34 """
35 raise NotImplementedError() # pragma: no cover
37 def predict(self, X):
38 """
39 Predicts.
41 @param X features
42 @return prédictions
43 """
44 raise NotImplementedError() # pragma: no cover
46 def decision_function(self, X):
47 """
48 Output of the model in case of a regressor,
49 matrix with a score for each class and each sample
50 for a classifier.
52 @param X Samples, {array-like, sparse matrix}, shape = (n_samples, n_features)
53 @return array, shape = (n_samples,.), Returns predicted values.
54 """
55 raise NotImplementedError() # pragma: no cover
57 def score(self, X, y=None, sample_weight=None):
58 """
59 Returns the mean accuracy on the given test data and labels.
61 @param X Training data, numpy array or sparse matrix of shape [n_samples,n_features]
62 @param y Target values, numpy array of shape [n_samples, n_targets] (optional)
63 @param sample_weight Weight values, numpy array of shape [n_samples, n_targets] (optional)
64 @return score : float, Mean accuracy of self.predict(X) wrt. y.
65 """
66 raise NotImplementedError() # pragma: no cover