-
Notifications
You must be signed in to change notification settings - Fork 4
/
base.py
55 lines (45 loc) · 1.43 KB
/
base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
FileName: base.py
Description:
Author: Barry Chow
Date: 2020/2/23 6:07 PM
Version: 0.1
"""
from abc import ABCMeta
from abc import abstractmethod
class Classifier(metaclass=ABCMeta):
"""Base class for all classifiers
Warning: This class should not be used directly.
Use derived classes instead.
"""
@abstractmethod
def fit(self, X, y):
"""Given train data X and labels y,and feature labels, fit the classifier
Parameters
----------
X : array_like or sparse matrix, shape = [n_samples, n_features]
The input samples. Internally, it will be converted to
``dtype=np.float32`` and if a sparse matrix is provided
to a sparse ``csr_matrix``.
y : array_like, length = n_samples
Returns
-------
None
"""
raise NotImplementedError()
@abstractmethod
def predict(self, X):
"""Given train data X and labels y, fit the classifier
Parameters
----------
X : array_like or sparse matrix, shape = [n_samples, n_features]
The input samples. Internally, it will be converted to
``dtype=np.float32`` and if a sparse matrix is provided
to a sparse ``csr_matrix``.
Returns
-------
predit labels,array_like, length=n_samples
"""
raise NotImplementedError()