File size: 2,215 Bytes
cfc74ca
 
 
 
 
 
 
 
 
 
 
3bf5901
 
 
cfc74ca
3bf5901
 
cfc74ca
3bf5901
 
 
 
 
 
 
cfc74ca
3bf5901
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71d479a
3bf5901
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cfc74ca
3bf5901
 
cfc74ca
3bf5901
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import streamlit as st
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
import os

# Fix protobuf compatibility issue
os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"

# Load Dataset
df = pd.read_csv("Iris.csv")
df.rename(columns={'Species': 'species'}, inplace=True)

# Tabs Navigation
tabs = st.tabs(["Overview", "Dataset Details", "Data Visualization", "Prediction"])

with tabs[0]:  # Overview
    st.title("Overview")
    st.write("""
    This app uses machine learning to classify Iris flowers into three species:
    - Setosa
    - Versicolor
    - Virginica
    
    The model is trained using the **Random Forest Classifier**.
    """)

with tabs[1]:  # Dataset Details
    st.title("Dataset Details")
    st.write("### Sample Data")
    st.dataframe(df.head())
    st.write("### Dataset Statistics")
    st.write(df.describe())

with tabs[2]:  # Data Visualization
    st.title("Data Visualization")
    st.write("### Pairplot of Features")
    fig = sns.pairplot(df, hue="species", diag_kind="kde")
    st.pyplot(fig)
    
    st.write("### Feature Correlation")
    fig, ax = plt.subplots()
    sns.heatmap(df.drop(columns=['species']).corr(), annot=True, cmap='coolwarm', ax=ax)
    st.pyplot(fig)

with tabs[3]:  # Prediction
    st.title("Iris Flower Prediction")
    
    st.sidebar.header("Enter flower measurements:")
    sepal_length = st.sidebar.slider("Sepal Length (cm)", 4.0, 8.0, 5.0)
    sepal_width = st.sidebar.slider("Sepal Width (cm)", 2.0, 5.0, 3.0)
    petal_length = st.sidebar.slider("Petal Length (cm)", 1.0, 7.0, 4.0)
    petal_width = st.sidebar.slider("Petal Width (cm)", 0.1, 2.5, 1.0)
    
    X = df.iloc[:, 1:-1]
    y = df['species']
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
    
    model = RandomForestClassifier()
    model.fit(X_train, y_train)
    
    input_data = [[sepal_length, sepal_width, petal_length, petal_width]]
    prediction = model.predict(input_data)[0]
    
    st.write("### Prediction Result")
    st.success(f"The predicted species is: {prediction}")