-
Notifications
You must be signed in to change notification settings - Fork 0
/
or.py
41 lines (32 loc) · 1.14 KB
/
or.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
from utils.model import Perceptron
from utils.all_utils import prepare_data, save_plot, save_model
import pandas as pd
import logging
import os
logging_str = "[%(asctime)s: %(levelname)s: %(module)s] %(message)s"
log_dir = "logs"
os.makedirs(log_dir, exist_ok=True)
logging.basicConfig(filename=os.path.join("running_logs.log"), level=logging.INFO, format=logging_str, filemode="a")
def main(data, modelName, plotName, eta, epochs):
df = pd.DataFrame(data)
logging.info(f"this is actual dataframe{df}")
X, y = prepare_data(df)
model = Perceptron(eta=eta, epochs=epochs)
model.fit(X, y)
_ = model.total_loss()
save_model(model, filename=modelName)
save_plot(df, plotName, model)
if __name__ == '__main__':
OR = {
"x1": [0,0,1,1],
"x2": [0,1,0,1],
"y": [0,1,1,1],
}
ETA = 0.3 # 0 and 1
EPOCHS = 100
try:
logging.info(">>>>>>>>> starting training >>>>>>>")
main(data=OR, modelName="or.model", plotName="or.png", eta=ETA, epochs=EPOCHS)
logging.info("<<<<<<< training done successfully <<<<<<<<\n")
except Exception as e:
logging.exception(e)