-
Notifications
You must be signed in to change notification settings - Fork 2
/
model_class.py
76 lines (62 loc) · 1.95 KB
/
model_class.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
68
69
70
71
72
73
74
75
76
import torch
from torch import nn
from torch import sigmoid
class SpendingsPredictor(nn.Module):
def __init__(self, input_size: int, dropout_p: float = 0.5):
super().__init__()
self.mlp = nn.Sequential(
nn.Linear(input_size, 256),
nn.ReLU(),
nn.Dropout(dropout_p),
nn.Linear(256, 128),
nn.ReLU(),
nn.Dropout(dropout_p),
nn.Linear(128, 3)
)
def forward(self, x):
return self.mlp(x)
def predict_proba(self, x):
return sigmoid(self(x))
def predict(self, x):
y_pred_score = self.predict_proba(x)
return torch.argmax(y_pred_score, dim=1)
# # NN 3
class SpendingsPredictor3(nn.Module):
def __init__(self, input_size: int, dropout_p: float = 0.5):
super().__init__()
self.mlp = nn.Sequential(
nn.Linear(input_size, 256),
nn.Sigmoid(),
nn.Dropout(dropout_p),
nn.Linear(256, 128),
nn.Sigmoid(),
nn.Dropout(dropout_p),
nn.Linear(128, 3)
)
def forward(self, x):
return self.mlp(x)
def predict_proba(self, x):
return sigmoid(self(x))
def predict(self, x):
y_pred_score = self.predict_proba(x)
return torch.argmax(y_pred_score, dim=1)
# # NN 4
class SpendingsPredictor4(nn.Module):
def __init__(self, input_size: int, dropout_p: float = 0.5):
super().__init__()
self.mlp = nn.Sequential(
nn.Linear(input_size, 256),
nn.PReLU(),
nn.Dropout(dropout_p),
nn.Linear(256, 128),
nn.PReLU(),
nn.Dropout(dropout_p),
nn.Linear(128, 3)
)
def forward(self, x):
return self.mlp(x)
def predict_proba(self, x):
return sigmoid(self(x))
def predict(self, x):
y_pred_score = self.predict_proba(x)
return torch.argmax(y_pred_score, dim=1)