-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
35 lines (25 loc) · 1.06 KB
/
Copy pathclient.py
File metadata and controls
35 lines (25 loc) · 1.06 KB
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
from model import create_model
from utils import add_noise
class Client:
def __init__(self, data, client_name="Client"):
self.client_name = client_name
self.X_train, self.X_test, self.y_train, self.y_test = data
self.model = create_model()
def train(self, global_weights=None):
self.model.fit(self.X_train, self.y_train)
if global_weights is not None:
self.model.coef_ = global_weights[0].copy()
self.model.intercept_ = global_weights[1].copy()
self.model.fit(self.X_train, self.y_train)
weights = (self.model.coef_.copy(), self.model.intercept_.copy())
return add_noise(weights)
def set_weights(self, weights):
self.model.fit(self.X_train, self.y_train)
self.model.coef_ = weights[0].copy()
self.model.intercept_ = weights[1].copy()
def evaluate(self):
return self.model.score(self.X_test, self.y_test)
def predict_proba(self, X):
return self.model.predict_proba(X)
def predict(self, X):
return self.model.predict(X)