Tim Bartolo commited on
Commit
32dea6f
1 Parent(s): 264c028

first commit

Browse files
flight_crash_fatality_prediction.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # script to create a new (normalized) observation data point for the plane crash dataset
2
+ # author tbartolo
3
+ import joblib
4
+ import numpy as np
5
+ import gradio as gr
6
+ import os
7
+
8
+ resources_dir = "resources"
9
+ normalizers_dir = "normalizers"
10
+ algorithms_dir = "algorithms"
11
+
12
+
13
+ def master_fn(year, operator, location, ac_type, passengers, crew, algorithm):
14
+ def ac_type_normalizer(value):
15
+ hasher = joblib.load(os.path.join(resources_dir, normalizers_dir, "ac_type_hash_model.joblib"))
16
+ return hasher.transform([[value]]).toarray().flatten()
17
+
18
+ def location_normalizer(value):
19
+ hasher = joblib.load(os.path.join(resources_dir, normalizers_dir, "location_hash_model.joblib"))
20
+ return hasher.transform([[value]]).toarray().flatten()
21
+
22
+ def operator_normalizer(value):
23
+ hasher = joblib.load(os.path.join(resources_dir, normalizers_dir, "operator_hash_model.joblib"))
24
+ return hasher.transform([[value]]).toarray().flatten()
25
+
26
+ def year_normalizer(value):
27
+ kbins_discretizer = joblib.load(os.path.join(resources_dir, normalizers_dir, "year_qbins_model.joblib"))
28
+ return kbins_discretizer.transform([[value]]).flatten()
29
+
30
+ def passenger_crew_normalizer(value1, value2):
31
+ scaler = joblib.load(os.path.join(resources_dir, normalizers_dir, "passenger_crew_scaler_model.joblib"))
32
+ return scaler.transform([[value1, value2]])[0]
33
+
34
+ observation = np.concatenate((year_normalizer(year), operator_normalizer(operator), location_normalizer(location),
35
+ ac_type_normalizer(ac_type), passenger_crew_normalizer(passengers, crew)))
36
+
37
+ result = float
38
+
39
+ if algorithm == "SVR":
40
+ svr = joblib.load(os.path.join(resources_dir, algorithms_dir, "svr_model.joblib"))
41
+ result = svr.predict([observation])[0]
42
+ elif algorithm == "KNN":
43
+ knn = joblib.load(os.path.join(resources_dir, algorithms_dir, "knn_model.joblib"))
44
+ result = knn.predict([observation])[0]
45
+ elif algorithm == "Isolation Forest":
46
+ random_forest = joblib.load(os.path.join(resources_dir, algorithms_dir, "random_forest_model.joblib"))
47
+ result = random_forest.predict([observation])[0]
48
+ else:
49
+ raise ValueError('Unknown algorithm: {}'.format(algorithm))
50
+
51
+ return round(result, 2)
52
+
53
+
54
+ demo = gr.Interface(
55
+ master_fn,
56
+ [
57
+ "number",
58
+ "text",
59
+ "text",
60
+ "text",
61
+ "number",
62
+ "number",
63
+ gr.Radio(["KNN", "Isolation Forest", "SVR"])
64
+ ],
65
+ "number",
66
+ title="Flight Crash Fatality Prediction",
67
+ description="Enter the flight details and the algorithm to perform the prediction. Note that the purpose of this "
68
+ "effort is strictly to showcase the strengths and weaknesses amongst the 3 techniques used, "
69
+ "and by no means claims any sort of accuracy in its predictions.",
70
+ )
71
+
72
+ if __name__ == "__main__":
73
+ demo.launch(show_api=False)
requirements.txt ADDED
Binary file (2.51 kB). View file
 
resources/algorithms/knn_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:113ac752538bdfab02239dfe94373efb6e3422263b10dc7346fdcb0c79fa343b
3
+ size 558836
resources/algorithms/random_forest_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b4e419bf578ecedbafe150d168456ff2a0eb7a384730930b45599004d3270250
3
+ size 612001
resources/algorithms/svr_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6acfde665a77f17366a12c1131d4b7e2578de717305e54fffef20892b4980654
3
+ size 433620
resources/datasets/plane_crashes_transformed.csv ADDED
The diff for this file is too large to render. See raw diff
 
resources/datasets/plane_crashes_untransformed.csv ADDED
The diff for this file is too large to render. See raw diff
 
resources/normalizers/ac_type_hash_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4ebc099e2768f32ce9034b6857a1f5cc52de67ca9c5681c3813ea3fb8e915c70
3
+ size 183
resources/normalizers/location_hash_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4ebc099e2768f32ce9034b6857a1f5cc52de67ca9c5681c3813ea3fb8e915c70
3
+ size 183
resources/normalizers/operator_hash_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4ebc099e2768f32ce9034b6857a1f5cc52de67ca9c5681c3813ea3fb8e915c70
3
+ size 183
resources/normalizers/passenger_crew_scaler_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ca4532ad1463f26ac6e0e5cbd6d6ab5bcf0088f94a8ccb13367f61ecef9c5915
3
+ size 1063
resources/normalizers/year_qbins_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8ccc8e0cf73b8844100abe773f96a63598a9bb158095743530d57972ff03bdef
3
+ size 1599