narinsak commited on
Commit
d8bc07d
1 Parent(s): c425d06

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -72
app.py DELETED
@@ -1,72 +0,0 @@
1
- import streamlit as st
2
- import pandas as pd
3
- from sklearn.model_selection import train_test_split
4
- from sklearn.pipeline import Pipeline
5
- from sklearn.preprocessing import StandardScaler, OneHotEncoder
6
- from sklearn.compose import ColumnTransformer
7
- from sklearn.neighbors import KNeighborsClassifier
8
- from sklearn.metrics import accuracy_score
9
-
10
- # Load your data (replace with your actual data loading)
11
- # Assuming penguins.csv is in the same directory as your Streamlit app
12
- try:
13
- penguins = pd.read_csv('penguins_lter.csv')
14
- except FileNotFoundError:
15
- st.error("Error: penguins_lter.csv not found. Please make sure the file is in the same directory as the app.")
16
- st.stop()
17
-
18
- # Preprocessing steps (same as your original code)
19
- penguins = penguins.dropna()
20
- penguins.drop_duplicates(inplace=True)
21
-
22
-
23
- # Streamlit app
24
- st.title('Penguin Species Prediction')
25
-
26
- # Sidebar for user input
27
- st.sidebar.header('Input Features')
28
-
29
- island = st.sidebar.selectbox('Island', penguins['Island'].unique())
30
- culmen_length = st.sidebar.slider('Culmen Length (mm)', float(penguins['Culmen Length (mm)'].min()), float(penguins['Culmen Length (mm)'].max()), float(penguins['Culmen Length (mm)'].mean()))
31
- culmen_depth = st.sidebar.slider('Culmen Depth (mm)', float(penguins['Culmen Depth (mm)'].min()), float(penguins['Culmen Depth (mm)'].max()), float(penguins['Culmen Depth (mm)'].mean()))
32
- flipper_length = st.sidebar.slider('Flipper Length (mm)', float(penguins['Flipper Length (mm)'].min()), float(penguins['Flipper Length (mm)'].max()), float(penguins['Flipper Length (mm)'].mean()))
33
- body_mass = st.sidebar.slider('Body Mass (g)', float(penguins['Body Mass (g)'].min()), float(penguins['Body Mass (g)'].max()), float(penguins['Body Mass (g)'].mean()))
34
- sex = st.sidebar.selectbox('Sex', penguins['Sex'].unique())
35
-
36
- # Create input DataFrame
37
- input_data = pd.DataFrame({
38
- 'Island': [island],
39
- 'Culmen Length (mm)': [culmen_length],
40
- 'Culmen Depth (mm)': [culmen_depth],
41
- 'Flipper Length (mm)': [flipper_length],
42
- 'Body Mass (g)': [body_mass],
43
- 'Sex': [sex]
44
- })
45
-
46
- # Prepare the model (same as before, including your pipeline)
47
- X = penguins.drop('Species', axis=1)
48
- y = penguins['Species']
49
-
50
- X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
51
-
52
- numerical_features = ['Culmen Length (mm)', 'Culmen Depth (mm)', 'Flipper Length (mm)', 'Body Mass (g)']
53
- categorical_features = ['Island', 'Sex']
54
-
55
- numerical_transformer = Pipeline(steps=[('scaler', StandardScaler())])
56
- categorical_transformer = Pipeline(steps=[('onehot', OneHotEncoder(handle_unknown='ignore'))])
57
-
58
- preprocessor = ColumnTransformer(
59
- transformers=[
60
- ('num', numerical_transformer, numerical_features),
61
- ('cat', categorical_transformer, categorical_features)
62
- ])
63
-
64
- pipeline = Pipeline(steps=[('preprocessor', preprocessor), ('classifier', KNeighborsClassifier())])
65
- pipeline.fit(X_train, y_train)
66
-
67
- # Make prediction
68
- prediction = pipeline.predict(input_data)
69
-
70
- # Display prediction
71
- st.subheader('Prediction')
72
- st.write(f"Predicted Penguin Species: {prediction[0]}")