Syauqi Nabil Tasri commited on
Commit
05d91d5
·
verified ·
1 Parent(s): e7d0481

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -63
app.py CHANGED
@@ -3,73 +3,41 @@ import pandas as pd
3
  import pickle
4
 
5
  # Load the fitted model
6
- best_model = pickle.load(open('model (10).pkl', 'rb'))
 
 
 
 
 
 
 
 
7
 
8
  st.title('Almond Classification')
9
  st.write('This web app classifies almonds based on your input features.')
10
 
11
- # # Input untuk setiap fitur
12
- # length_major_axis = st.number_input('Length (major axis)', min_value=269.356903, max_value=279.879883)
13
- # width_minor_axis = st.number_input('Width (minor axis)', min_value=176.023636, max_value=227.940628)
14
- # thickness_depth = st.number_input('Thickness (depth)', min_value=107.253448, max_value=127.795132)
15
- # area = st.number_input('Area', min_value=18471.5, max_value=36683.0)
16
- # perimeter = st.number_input('Perimeter', min_value=551.688379, max_value=887.310743)
17
- # roundness = st.slider('Roundness', min_value=0.472718, max_value=0.643761, step=0.01)
18
- # solidity = st.slider('Solidity', min_value=0.931800, max_value=0.973384, step=0.01)
19
- # compactness = st.slider('Compactness', min_value=1.383965, max_value=1.764701, step=0.01)
20
- # aspect_ratio = st.slider('Aspect Ratio', min_value=1.530231, max_value=1.705716, step=0.01)
21
- # eccentricity = st.slider('Eccentricity', min_value=0.75693, max_value=0.81012, step=0.01)
22
- # extent = st.slider('Extent', min_value=0.656535, max_value=0.725739, step=0.01)
23
- # convex_area = st.number_input('Convex hull (convex area)', min_value=18068.0, max_value=36683.0, step=0.01)
24
-
25
- # # Tombol untuk memprediksi
26
- # if st.button('Predict'):
27
- # input_features = [[length_major_axis, width_minor_axis, thickness_depth, area,
28
- # perimeter, roundness, solidity, compactness, aspect_ratio,
29
- # eccentricity, extent, convex_area]]
30
- # prediction = model.predict(input_features)
31
- # st.write(f'The predicted class is: {prediction[0]}')
32
-
33
- # # Tombol untuk memprediksi
34
- # if st.button('Predict'):
35
- # input_features = [[length_major_axis, width_minor_axis, thickness_depth, area,
36
- # perimeter, roundness, solidity, compactness, aspect_ratio,
37
- # eccentricity, extent, convex_area]]
38
- # prediction = model.predict(input_features)
39
- # prediction_proba = model.predict_proba(input_features)
40
-
41
- # st.write(f'The predicted class is: {prediction[0]}')
42
- # st.write(f'Prediction probabilities: {prediction_proba}')
43
-
44
- # Input untuk beberapa fitur
45
- num_samples = st.number_input('Number of samples', min_value=1, max_value=10, value=1)
46
-
47
- input_features = []
48
- for i in range(num_samples):
49
- st.write(f'Sample {i + 1}')
50
- features = []
51
- length_major_axis = st.number_input('Length (major axis)', min_value=269.356903, max_value=279.879883, key=f'length_{i}')
52
- width_minor_axis = st.number_input('Width (minor axis)', min_value=176.023636, max_value=227.940628, key=f'width_{i}')
53
- thickness_depth = st.number_input('Thickness (depth)', min_value=107.253448, max_value=127.795132, key=f'thickness_{i}')
54
- area = st.number_input('Area', min_value=18471.5, max_value=36683.0, key=f'area_{i}')
55
- perimeter = st.number_input('Perimeter', min_value=551.688379, max_value=887.310743, key=f'perimeter_{i}')
56
- roundness = st.slider('Roundness', min_value=0.472718, max_value=0.643761, step=0.01, key=f'roundness_{i}')
57
- solidity = st.slider('Solidity', min_value=0.931800, max_value=0.973384, step=0.01, key=f'solidity_{i}')
58
- compactness = st.slider('Compactness', min_value=1.383965, max_value=1.764701, step=0.01, key=f'compactness_{i}')
59
- aspect_ratio = st.slider('Aspect Ratio', min_value=1.530231, max_value=1.705716, step=0.01, key=f'aspect_ratio_{i}')
60
- eccentricity = st.slider('Eccentricity', min_value=0.75693, max_value=0.81012, step=0.01, key=f'eccentricity_{i}')
61
- extent = st.slider('Extent', min_value=0.656535, max_value=0.725739, step=0.01, key=f'extent_{i}')
62
- convex_area = st.number_input('Convex hull (convex area)', min_value=18068.0, max_value=36683.0, step=0.01, key=f'convex_area_{i}')
63
-
64
- features = [length_major_axis, width_minor_axis, thickness_depth, area,
65
- perimeter, roundness, solidity, compactness, aspect_ratio,
66
- eccentricity, extent, convex_area]
67
- input_features.append(features)
68
 
69
  # Tombol untuk memprediksi
70
  if st.button('Predict'):
71
- predictions = best_model.predict(input_features)
72
- for i, prediction in enumerate(predictions):
73
- st.write(f'The predicted class for sample {i + 1} is: {prediction}')
74
-
75
-
 
 
 
 
 
3
  import pickle
4
 
5
  # Load the fitted model
6
+ model = pickle.load(open('model (10).pkl', 'rb'))
7
+
8
+ # Mapping antara kelas dan nama tipe almond
9
+ class_mapping = {
10
+ 0: 'Sweet Almond',
11
+ 1: 'Bitter Almond',
12
+ 2: 'California Almond',
13
+ # tambahkan kelas lainnya sesuai kebutuhan
14
+ }
15
 
16
  st.title('Almond Classification')
17
  st.write('This web app classifies almonds based on your input features.')
18
 
19
+ # Input untuk setiap fitur
20
+ length_major_axis = st.number_input('Length (major axis)', min_value=269.356903, max_value=279.879883)
21
+ width_minor_axis = st.number_input('Width (minor axis)', min_value=176.023636, max_value=227.940628)
22
+ thickness_depth = st.number_input('Thickness (depth)', min_value=107.253448, max_value=127.795132)
23
+ area = st.number_input('Area', min_value=18471.5, max_value=36683.0)
24
+ perimeter = st.number_input('Perimeter', min_value=551.688379, max_value=887.310743)
25
+ roundness = st.slider('Roundness', min_value=0.472718, max_value=0.643761, step=0.01)
26
+ solidity = st.slider('Solidity', min_value=0.931800, max_value=0.973384, step=0.01)
27
+ compactness = st.slider('Compactness', min_value=1.383965, max_value=1.764701, step=0.01)
28
+ aspect_ratio = st.slider('Aspect Ratio', min_value=1.530231, max_value=1.705716, step=0.01)
29
+ eccentricity = st.slider('Eccentricity', min_value=0.75693, max_value=0.81012, step=0.01)
30
+ extent = st.slider('Extent', min_value=0.656535, max_value=0.725739, step=0.01)
31
+ convex_area = st.number_input('Convex hull (convex area)', min_value=18068.0, max_value=36683.0, step=0.01)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  # Tombol untuk memprediksi
34
  if st.button('Predict'):
35
+ input_features = [[length_major_axis, width_minor_axis, thickness_depth, area,
36
+ perimeter, roundness, solidity, compactness, aspect_ratio,
37
+ eccentricity, extent, convex_area]]
38
+ prediction = model.predict(input_features)
39
+
40
+ # Menggunakan mapping untuk mendapatkan nama tipe almond
41
+ predicted_class_name = class_mapping[prediction[0]]
42
+
43
+ st.write(f'The predicted class is: {predicted_class_name}')