-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecute.py
33 lines (25 loc) · 1.18 KB
/
execute.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
from datasets.linear_regression_dataset import LinRegDataset
from models.linear_regression_model import LinearRegression
from utils.metrics import MSE
from utils.visualisation import Visualisation
def experiment(lin_reg_cfg, visualise_prediction=True):
lin_reg_model = LinearRegression(lin_reg_cfg.base_functions)
linreg_dataset = LinRegDataset()(lin_reg_cfg.dataframe_path)
predictions = lin_reg_model(linreg_dataset["inputs"])
error = MSE(predictions, linreg_dataset["targets"])
if visualise_prediction:
Visualisation.visualise_predicted_trace(
predictions,
linreg_dataset["inputs"],
linreg_dataset["targets"],
plot_title=f"Полином степени {len(lin_reg_cfg.base_functions)}; MSE = {round(error, 2)}",
)
if __name__ == "__main__":
from configs.linear_regression_cfg import cfg as lin_reg_cfg
degrees = [1, 8, 100]
for elem in degrees:
lin_reg_cfg.update(
# we have f1, f2, ... fn functions, about f0 in __plan_matrix
base_functions=[lambda x, degree=i: x**degree for i in range(1, 1 + elem)]
)
experiment(lin_reg_cfg, visualise_prediction=True)