-
Notifications
You must be signed in to change notification settings - Fork 0
/
Modele.py
66 lines (49 loc) · 1.8 KB
/
Modele.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
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
class Modele:
"""Modele pour la classification binaire."""
def __init__(self):
self.X = np.array(0)
self.Y = np.array(0)
self.name = self.set_name()
return
def set_name(self):
raise NotImplementedError
def get_name(self):
return self.name
def read_data(self, filename, sep='\t'):
raise NotImplementedError
def train(self, filename):
raise NotImplementedError
def get_error(self, filename):
raise NotImplementedError
def get_separator(self):
raise NotImplementedError
def display_figure(self, output_name):
plt.figure()
labels_1 = self.Y == 1
plt.plot(self.X[labels_1, -2], self.X[labels_1, -1], 'bo')
labels_0 = self.Y == 0
plt.plot(self.X[labels_0, -2], self.X[labels_0, -1], 'ro')
(abscisse, ordonnee) = self.get_separator()
plt.plot(abscisse, ordonnee, 'k')
plt.savefig(output_name)
return
def display_error(self, filename):
print(f'Erreur ({filename}) : {self.get_error(filename):.2f}')
return
def main(self):
from load_data import get_plot_suffixe, get_test_filename, get_train_filename
for dataset_letter in ['A', 'B', 'C']:
self.train(get_train_filename(dataset_letter))
self.display_error(get_train_filename(dataset_letter))
self.display_figure(
get_train_filename(dataset_letter) + get_plot_suffixe(self.get_name()),
)
self.display_error(get_test_filename(dataset_letter))
self.display_figure(
get_test_filename(dataset_letter) + get_plot_suffixe(self.get_name()),
)
return True