File size: 1,915 Bytes
e1a0db6
 
 
 
 
 
 
 
7dc7779
e1a0db6
6e4de9d
e1a0db6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score, classification_report
from sklearn.preprocessing import StandardScaler

st.set_page_config(page_title="Random Forest Diabetes Classifier", layout="centered")
st.title("👨🏻‍💻Dynamic Code Generating ChatBot🤖")

uploaded_file = st.file_uploader("📂 Upload your  CSV dataset", type=["csv"])

if uploaded_file:
    df = pd.read_csv(uploaded_file)
    st.success("✅ File loaded successfully!")
    st.write("### Preview of Dataset:")
    st.dataframe(df.head())

    all_columns = df.columns.tolist()

    target_column = st.selectbox("🎯 Select the target column (diabetes outcome)", all_columns)
    feature_columns = st.multiselect("🛠️ Select feature columns", [col for col in all_columns if col != target_column])

    if st.button("🚀 Run Random Forest Classifier"):
        try:
            X = df[feature_columns]
            y = df[target_column]

            X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

            scaler = StandardScaler()
            X_train = scaler.fit_transform(X_train)
            X_test = scaler.transform(X_test)

            model = RandomForestClassifier(n_estimators=100, random_state=42)
            model.fit(X_train, y_train)
            y_pred = model.predict(X_test)

            accuracy = accuracy_score(y_test, y_pred)
            report = classification_report(y_test, y_pred, output_dict=False)

            st.write("### ✅ Accuracy:")
            st.write(f"{accuracy * 100:.2f}%")

            st.write("### 📋 Classification Report:")
            st.code(report)

        except Exception as e:
            st.error(f"❌ An error occurred: {e}")
else:
    st.info("👈 Upload a CSV file to begin.")