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}")