File size: 2,064 Bytes
11afda8
b05d633
9772547
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b05d633
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
pip install streamlit
import streamlit as st
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score

# Page Title
st.title("Machine Learning Life Cycle in Streamlit")

# Buttons for each stage
if st.button("1. Data Collection"):
    st.header("Data Collection")
    st.write("Using Iris dataset for demonstration.")
    data = load_iris(as_frame=True)
    st.write(data.frame.head())

elif st.button("2. Data Preprocessing"):
    st.header("Data Preprocessing")
    st.write("Splitting the data into train and test sets.")
    data = load_iris(as_frame=True)
    X_train, X_test, y_train, y_test = train_test_split(data.data, data.target, test_size=0.2, random_state=42)
    st.write(f"Train size: {len(X_train)}; Test size: {len(X_test)}")

elif st.button("3. Model Training"):
    st.header("Model Training")
    st.write("Training a Random Forest Classifier.")
    data = load_iris(as_frame=True)
    X_train, X_test, y_train, y_test = train_test_split(data.data, data.target, test_size=0.2, random_state=42)
    model = RandomForestClassifier()
    model.fit(X_train, y_train)
    st.write("Model trained successfully.")

elif st.button("4. Model Evaluation"):
    st.header("Model Evaluation")
    st.write("Evaluating the model on the test data.")
    data = load_iris(as_frame=True)
    X_train, X_test, y_train, y_test = train_test_split(data.data, data.target, test_size=0.2, random_state=42)
    model = RandomForestClassifier()
    model.fit(X_train, y_train)
    predictions = model.predict(X_test)
    accuracy = accuracy_score(y_test, predictions)
    st.write(f"Accuracy: {accuracy:.2f}")

elif st.button("5. Model Deployment"):
    st.header("Model Deployment")
    st.write("This step involves deploying the model for usage.")
    st.write("You can expose the model via APIs or integrate it into an application.")

else:
    st.write("Use the buttons above to navigate through the Machine Learning life cycle.")