-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_analyzer.py
35 lines (29 loc) · 998 Bytes
/
data_analyzer.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 csv
import numpy as np
from sklearn.metrics import mean_squared_error
class DataAnalyzer:
def __init__(self, path):
with open(path) as f:
reader = csv.reader(f)
next(reader)
x = []
self.data = []
for row in reader:
self.data.append(np.float_(row[1:9]))
if len(row) == 10:
x.append(row[9])
self.expected_strength = np.float_(x)
def strength(self, exp):
func = eval('lambda A, B, C, D, E, F, G, H:' + exp)
strength_list = []
for x in self.data:
try:
strength_list.append(func(x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7]))
except:
strength_list.append(np.nan)
return strength_list
def mean_squared_error(self, exp):
try:
return mean_squared_error(self.expected_strength, self.strength(exp))
except:
return np.nan