narinsak commited on
Commit
3401e7d
·
verified ·
1 Parent(s): 0497940

Upload 3 files

Browse files
app_predict_penguin_706.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ import pickle
4
+ import pandas as pd
5
+
6
+ # Load the model and encoders
7
+ with open('model_penguin_706.pkl', 'rb') as file:
8
+ model, species_encoder, island_encoder, sex_encoder = pickle.load(file)
9
+
10
+ # Streamlit app layout
11
+ st.title('Penguin Species Prediction')
12
+
13
+ # Create user input fields
14
+ st.sidebar.header('Input Features')
15
+
16
+ # User inputs
17
+ species = st.sidebar.selectbox('Species', species_encoder.classes_)
18
+ island = st.sidebar.selectbox('Island', island_encoder.classes_)
19
+ sex = st.sidebar.selectbox('Sex', sex_encoder.classes_)
20
+
21
+ # Slider for numeric inputs
22
+ bill_length_mm = st.sidebar.slider('Bill Length (mm)', 30.0, 60.0, 45.0)
23
+ bill_depth_mm = st.sidebar.slider('Bill Depth (mm)', 10.0, 25.0, 18.0)
24
+ flipper_length_mm = st.sidebar.slider('Flipper Length (mm)', 170.0, 240.0, 200.0)
25
+ body_mass_g = st.sidebar.slider('Body Mass (g)', 2500.0, 6000.0, 4000.0)
26
+
27
+ # Prepare the input data (ensure columns are in the same order as expected by the model)
28
+ input_data = pd.DataFrame({
29
+ 'species': [species],
30
+ 'island': [island],
31
+ 'sex': [sex],
32
+ 'bill_length_mm': [bill_length_mm],
33
+ 'bill_depth_mm': [bill_depth_mm],
34
+ 'flipper_length_mm': [flipper_length_mm],
35
+ 'body_mass_g': [body_mass_g]
36
+ })
37
+
38
+ # Apply encoding to categorical features (check column names here!)
39
+ input_data['species'] = species_encoder.transform(input_data['species'])
40
+ input_data['island'] = island_encoder.transform(input_data['island'])
41
+ input_data['sex'] = sex_encoder.transform(input_data['sex'])
42
+
43
+ # Ensure the columns are in the correct order
44
+ expected_columns = ['species', 'island', 'sex', 'bill_length_mm', 'bill_depth_mm', 'flipper_length_mm', 'body_mass_g']
45
+ input_data = input_data[expected_columns]
46
+
47
+ # Make prediction
48
+ prediction = model.predict(input_data)
49
+
50
+ # Show the result
51
+ st.write(f'Predicted Species: {species_encoder.inverse_transform(prediction)}')
52
+
model_penguin_706.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a76cf9dba49c9eb1c8f3a0e955658f5c129def6bfb4a1516ae108e75724e08b2
3
+ size 29968
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+
2
+ scikit-learn
3
+ pandas
4
+