-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodel.py
55 lines (44 loc) · 1.61 KB
/
model.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
from abc import ABC, abstractmethod
class Model(ABC):
"""
Abstract class that provides the base functionality requirements for a machine learning model
Methods:
- train: Trains machine learning model
- test: Computes the class likelihoods for each test instance in the dataset
- predict: Predicts the label for each instance in the testing dataset
- score: Evaluates model on testing dataset
- reset: Reset model parameters
"""
@abstractmethod
def train(self, X, Y):
"""
Trains machine learning model
:param Y: training dataset labels 'y'
:param X: training dataset features 'x'
"""
pass
@abstractmethod
def test(self, X, Y):
"""
Computes the class likelihoods for each test instance in the dataset
:param Y: training dataset labels 'y'
:param X: training dataset features 'x'
:return: list of probability predictions for each class for each test instance
"""
pass
@abstractmethod
def predict(self, X, Y):
"""
Predicts the label for each instance in the testing dataset
:param Y: training dataset labels 'y'
:param X: training dataset features 'x'
:return: label predictions for each instance
"""
pass
def get_eval_metrics(self):
"""
Provides metrics specific to the model for later visualisation (optional).
:return: list of metrics. Format for metric:
metrics = [{'name': plot_name, 'x': (x_label, x_values), 'y': (y_label, y_values)}, ...]
"""
return None