fdabbiras commited on
Commit
a83028c
·
verified ·
1 Parent(s): 05d2144

Upload 4 files

Browse files
Files changed (4) hide show
  1. KSD.ipynb +0 -0
  2. gui.py +45 -0
  3. importsklearn.py +2 -0
  4. random_forest_model.pkl +3 -0
KSD.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
gui.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request
2
+ import pickle
3
+ import numpy as np
4
+
5
+ app = Flask(__name__)
6
+
7
+ # Load model
8
+ with open('random_forest_model.pkl', 'rb') as file:
9
+ model = pickle.load(file)
10
+
11
+ @app.route('/', methods=['GET', 'POST'])
12
+ def predict():
13
+ if request.method == 'POST':
14
+ # Ambil input dari form
15
+ age = int(request.form['age'])
16
+ gender = int(request.form['gender'])
17
+ height = float(request.form['height'])
18
+ weight = float(request.form['weight'])
19
+ ap_hi = int(request.form['ap_hi'])
20
+ ap_lo = int(request.form['ap_lo'])
21
+ cholesterol = int(request.form['cholesterol'])
22
+ gluc = int(request.form['gluc'])
23
+ smoke = int(request.form['smoke'])
24
+ alco = int(request.form['alco'])
25
+ active = int(request.form['active'])
26
+
27
+
28
+ # Buat array input untuk model
29
+ input_features = np.array([[age, gender, height, weight, ap_hi, ap_lo,
30
+ cholesterol, gluc, smoke, alco, active]])
31
+
32
+ # Prediksi
33
+ prediction = model.predict(input_features)[0] # 0 = Low Risk, 1 = High Risk
34
+ probability = model.predict_proba(input_features)[0][1] # Probabilitas risiko tinggi
35
+
36
+ # Tentukan hasil berdasarkan prediksi
37
+ risk_level = "Tinggi" if prediction == 1 else "Rendah"
38
+ percentage = round(probability * 100, 2)
39
+
40
+ return render_template('index.html', risk_level=risk_level, percentage=percentage)
41
+
42
+ return render_template('index.html', risk_level=None)
43
+
44
+ if __name__ == '__main__':
45
+ app.run(debug=True)
importsklearn.py ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ import sklearn
2
+ print(sklearn.__version__)
random_forest_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:19cfebc3156ca0e30b28bdfaee417771746a272560b5466a4e71895479231b3d
3
+ size 108745