-
Notifications
You must be signed in to change notification settings - Fork 0
/
myTraining.py
35 lines (25 loc) · 1006 Bytes
/
myTraining.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
import pandas as pd
import numpy as np
from sklearn.linear_model import LogisticRegression as lg
import pickle
def dataSplit(data, ratio):
np.random.seed(42)
shuffled = np.random.permutation(len(data))
test_setSize = int(len(data) * ratio)
test_indices = shuffled[:test_setSize]
train_indices = shuffled[test_setSize:]
return data.iloc[train_indices], data.iloc[test_indices]
if __name__ == "__main__":
df = pd.read_csv('data.csv')
train, test = dataSplit(df, 0.2)
x_train = train[['fever', 'bodyPain', 'age', 'runnyNose', 'diffBreath']].to_numpy()
x_test = test[['fever', 'bodyPain', 'age', 'runnyNose', 'diffBreath']].to_numpy()
y_train = train[['infectionProb']].to_numpy().reshape(2060 ,)
y_test = test[['infectionProb']].to_numpy().reshape(515 ,)
clf = lg()
clf.fit(x_train, y_train)
file = open('model.pkl', 'wb')
pickle.dump(clf, file)
input = [98, 0, 13, 0, 1]
inf = clf.predict_proba([input])[0][1]
file.close()