narinsak unawong commited on
Commit
01f786d
·
verified ·
1 Parent(s): d6b66d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -1,4 +1,3 @@
1
-
2
  import streamlit as st
3
  import pickle
4
  import pandas as pd
@@ -41,12 +40,14 @@ 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
-
 
 
1
  import streamlit as st
2
  import pickle
3
  import pandas as pd
 
40
  input_data['sex'] = sex_encoder.transform(input_data['sex'])
41
 
42
  # Ensure the columns are in the correct order
43
+ # Check if the model includes a ColumnTransformer and use it if available
44
+ if isinstance(model, Pipeline):
45
+ preprocessor = model.named_steps.get('preprocessor') # Replace with actual step name if different
46
+ if preprocessor:
47
+ input_data = preprocessor.transform(input_data) # Apply any necessary transformations
48
 
49
  # Make prediction
50
  prediction = model.predict(input_data)
51
 
52
  # Show the result
53
  st.write(f'Predicted Species: {species_encoder.inverse_transform(prediction)}')