-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPredictor.py
67 lines (55 loc) · 1.58 KB
/
Predictor.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
56
57
58
59
60
61
62
63
64
65
66
67
from Estimator import Estimator
class Predictor(Estimator):
def __init__(self, model=None):
"""Initialize the Predictor with a given model."""
self.model = model
def predict(self, X):
"""
Make predictions on the test data.
Parameters:
-----------
X : numpy.ndarray
The test data.
Returns:
--------
numpy.ndarray
The predictions.
"""
return self.model.predict(X)
def score(self, X, y):
"""
Evaluate the model on the test data.
Parameters:
-----------
X : numpy.ndarray
The test data.
y : numpy.ndarray
The target values.
Returns:
--------
float
The score of the model.
Raises:
-------
NotImplementedError
If the score method has not been implemented.
"""
raise NotImplementedError("The score method has not been implemented.")
def fit_predict(self, X_train, y_train, X_test):
"""
Train the model on the training data and make predictions on the test data.
Parameters:
-----------
X_train : numpy.ndarray
The training data.
y_train : numpy.ndarray
The target values.
X_test : numpy.ndarray
The test data.
Returns:
--------
numpy.ndarray
The predictions.
"""
self.model.fit(X_train, y_train)
return self.predict(X_test)