-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadData.py
58 lines (41 loc) · 1.27 KB
/
loadData.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import json
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.metrics import r2_score
import matplotlib.pyplot as plt
#LOAD DATA
with open("data/ac_poor_1.bsad", "r") as fin:
ac_data = json.loads(fin.read())
tables = ac_data["tables"]
dataframes = []
for table in tables:
if table["header"]["flightphase"] == "cruise":
cols = table["header"]["variables"]
data = table["table"]
dataframes.append(pd.DataFrame(data, columns=cols))
mesureRun = dataframes[1]
variables = ["DISA","ALTITUDE","MASS","TAS"]
predictor = ["FUELFLOW"]
X = pd.DataFrame(mesureRun.get(variables), columns=variables)
Y = pd.DataFrame(mesureRun.get(predictor), columns=predictor)
print(X.describe())
print(Y.describe())
reg = LinearRegression().fit(X, Y)
print("Regreasaion Score: ")
print(reg.score(X, Y))
#Plot
#variables = ["DISA","ALTITUDE","MASS","TAS"]
plot = [1]
conts = [2,3,4]
plotVariable = variables[plot]
predictor = ["FUELFLOW"]
#keep const
varKeepConst = variables[const]
konst = [100,100,100];
plotVariableArr = X.get(plotVariable)
modelPred = reg.predict(X)
plt.scatter(plotVariableArr, Y.get(predictor), color='black')
#plt.plot(X.get(plotVariable), modelPred, color='blue', linewidth=3)
plt.xticks(())
plt.yticks(())
plt.show()