robitalhazmi commited on
Commit
848b00d
1 Parent(s): 0f9de8d

Add app file

Browse files
Files changed (2) hide show
  1. abalone_model.pkl +3 -0
  2. app.py +83 -0
abalone_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:77eead0e5e422c15d945d25a0e028171e3227f2cd7cec63404c3e0a70958efdb
3
+ size 13028
app.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import pickle
5
+
6
+ # Load the pre-trained model
7
+ with open('abalone_model.pkl', 'rb') as file:
8
+ model = pickle.load(file)
9
+
10
+ # Define the prediction function
11
+ def predict_age(sex, length, diameter, height, whole_weight, shucked_weight, viscera_weight, shell_weight):
12
+ shell_volume = length * diameter * height
13
+ meat_ratio = whole_weight / shell_weight
14
+ bmi = whole_weight / (length ** 2)
15
+ shell_surface_area = 2 * (length * diameter + length * height + diameter * height)
16
+ volume_to_weight_ratio = shell_volume / whole_weight
17
+ shell_weight_to_length_ratio = shell_weight / length
18
+ meat_weight_to_lenth_ratio = whole_weight / length
19
+ features = [[
20
+ sex,
21
+ length,
22
+ diameter,
23
+ height,
24
+ whole_weight,
25
+ shucked_weight,
26
+ viscera_weight,
27
+ shell_weight,
28
+ shell_volume,
29
+ meat_ratio,
30
+ bmi,
31
+ shell_surface_area,
32
+ volume_to_weight_ratio,
33
+ shell_weight_to_length_ratio,
34
+ meat_weight_to_lenth_ratio
35
+ ]]
36
+ columns = [
37
+ 'Sex',
38
+ 'Length',
39
+ 'Diameter',
40
+ 'Height',
41
+ 'Whole_weight',
42
+ 'Shucked_weight',
43
+ 'Viscera_weight',
44
+ 'Shell_weight',
45
+ 'Shell_Volume',
46
+ 'Meat_Ratio',
47
+ 'BMI',
48
+ 'Shell_Surface_Area',
49
+ 'Volume_to Weigh_Ratio',
50
+ 'Shell_Weight_to Length_Ratio',
51
+ 'Mea_Weight_to_Length Ratio'
52
+ ]
53
+ features_df = pd.DataFrame(data=features, columns=columns)
54
+ prediction = model.predict(features_df)
55
+ age = prediction[0] + 1.5
56
+ return age
57
+
58
+ # Streamlit app
59
+ st.title('Abalone Age Predictor')
60
+
61
+ st.write("Enter the physical measurements of the abalone to predict its age.")
62
+
63
+ # Input fields
64
+ sex = st.selectbox('Sex', ['M', 'F', 'I'])
65
+ length = st.number_input('Length (mm)', min_value=0.0, value=0.0)
66
+ diameter = st.number_input('Diameter (mm)', min_value=0.0, value=0.0)
67
+ height = st.number_input('Height (mm)', min_value=0.0, value=0.0)
68
+ whole_weight = st.number_input('Whole Weight (grams)', min_value=0.0, value=0.0)
69
+ shucked_weight = st.number_input('Shucked Weight (grams)', min_value=0.0, value=0.0)
70
+ viscera_weight = st.number_input('Viscera Weight (grams)', min_value=0.0, value=0.0)
71
+ shell_weight = st.number_input('Shell Weight (grams)', min_value=0.0, value=0.0)
72
+
73
+ # Predict button
74
+ if st.button('Predict Age'):
75
+ try:
76
+ # Check for valid input values
77
+ if length <= 0 or diameter <= 0 or height <= 0 or whole_weight <= 0 or shucked_weight <= 0 or viscera_weight <= 0 or shell_weight <= 0:
78
+ st.error("All input values must be greater than zero.")
79
+ else:
80
+ age = predict_age(sex, length, diameter, height, whole_weight, shucked_weight, viscera_weight, shell_weight)
81
+ st.write(f'The predicted age of the abalone is: {age:.2f} years')
82
+ except Exception as e:
83
+ st.error(f"An error occurred: {e}")