-
Notifications
You must be signed in to change notification settings - Fork 848
/
base.py
34 lines (27 loc) · 989 Bytes
/
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
# Sebastian Raschka 2014-2016
# mlxtend Machine Learning Library Extensions
#
# Base Classifier (Classifier Parent Class)
# Author: Sebastian Raschka <sebastianraschka.com>
#
# License: BSD 3 clause
import numpy as np
class _BaseFeatureExtractor(object):
"""Parent Class for Feature Extractors"""
def __init__(self):
pass
def _check_arrays(self, X, y=None):
if isinstance(X, list):
raise ValueError('X must be a numpy array')
if not len(X.shape) == 2:
raise ValueError('X must be a 2D array. Try X[:,numpy.newaxis]')
try:
if y is None:
return
except(AttributeError):
if not len(y.shape) == 1:
raise ValueError('y must be a 1D array.')
if not isinstance(y, np.ndarray):
raise ValueError('y must be a numpy array')
if y.shape[0] != X.shape[0]:
raise ValueError('X and y must contain the same number of samples')