Spaces:
Sleeping
Sleeping
narinsak unawong
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,6 @@ import pickle
|
|
3 |
import pandas as pd
|
4 |
from sklearn.pipeline import Pipeline
|
5 |
|
6 |
-
|
7 |
# Load the model and encoders
|
8 |
with open('model_penguin_706.pkl', 'rb') as file:
|
9 |
model, species_encoder, island_encoder, sex_encoder = pickle.load(file)
|
@@ -25,6 +24,10 @@ bill_depth_mm = st.sidebar.slider('Bill Depth (mm)', 10.0, 25.0, 18.0)
|
|
25 |
flipper_length_mm = st.sidebar.slider('Flipper Length (mm)', 170.0, 240.0, 200.0)
|
26 |
body_mass_g = st.sidebar.slider('Body Mass (g)', 2500.0, 6000.0, 4000.0)
|
27 |
|
|
|
|
|
|
|
|
|
28 |
# Prepare the input data (ensure columns are in the same order as expected by the model)
|
29 |
input_data = pd.DataFrame({
|
30 |
'species': [species],
|
@@ -33,7 +36,9 @@ input_data = pd.DataFrame({
|
|
33 |
'bill_length_mm': [bill_length_mm],
|
34 |
'bill_depth_mm': [bill_depth_mm],
|
35 |
'flipper_length_mm': [flipper_length_mm],
|
36 |
-
'body_mass_g': [body_mass_g]
|
|
|
|
|
37 |
})
|
38 |
|
39 |
# Apply encoding to categorical features (check column names here!)
|
@@ -42,7 +47,6 @@ input_data['island'] = island_encoder.transform(input_data['island'])
|
|
42 |
input_data['sex'] = sex_encoder.transform(input_data['sex'])
|
43 |
|
44 |
# Ensure the columns are in the correct order
|
45 |
-
# Check if the model includes a ColumnTransformer and use it if available
|
46 |
if isinstance(model, Pipeline):
|
47 |
preprocessor = model.named_steps.get('preprocessor') # Replace with actual step name if different
|
48 |
if preprocessor:
|
|
|
3 |
import pandas as pd
|
4 |
from sklearn.pipeline import Pipeline
|
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)
|
|
|
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 |
+
# Add missing columns with default values
|
28 |
+
culmen_length_mm = 40.0 # Default value, update with realistic values if available
|
29 |
+
culmen_depth_mm = 15.0 # Default value, update with realistic values if available
|
30 |
+
|
31 |
# Prepare the input data (ensure columns are in the same order as expected by the model)
|
32 |
input_data = pd.DataFrame({
|
33 |
'species': [species],
|
|
|
36 |
'bill_length_mm': [bill_length_mm],
|
37 |
'bill_depth_mm': [bill_depth_mm],
|
38 |
'flipper_length_mm': [flipper_length_mm],
|
39 |
+
'body_mass_g': [body_mass_g],
|
40 |
+
'culmen_length_mm': [culmen_length_mm],
|
41 |
+
'culmen_depth_mm': [culmen_depth_mm]
|
42 |
})
|
43 |
|
44 |
# Apply encoding to categorical features (check column names here!)
|
|
|
47 |
input_data['sex'] = sex_encoder.transform(input_data['sex'])
|
48 |
|
49 |
# Ensure the columns are in the correct order
|
|
|
50 |
if isinstance(model, Pipeline):
|
51 |
preprocessor = model.named_steps.get('preprocessor') # Replace with actual step name if different
|
52 |
if preprocessor:
|