Spaces:
Sleeping
Sleeping
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.") | |