Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,11 @@
|
|
| 2 |
import streamlit as st
|
| 3 |
import pandas as pd
|
| 4 |
import matplotlib.pyplot as plt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
st.title("Webcam Color Detection Charting")
|
| 7 |
|
|
@@ -52,3 +57,38 @@ if uploaded_file is not None:
|
|
| 52 |
|
| 53 |
ax.legend(loc='upper left')
|
| 54 |
st.pyplot(fig)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
import pandas as pd
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
+
from sklearn.linear_model import LinearRegression
|
| 6 |
+
from sklearn.preprocessing import PolynomialFeatures
|
| 7 |
+
from sklearn.pipeline import make_pipeline
|
| 8 |
+
from sklearn.svm import SVR
|
| 9 |
+
from sklearn.ensemble import RandomForestRegressor
|
| 10 |
|
| 11 |
st.title("Webcam Color Detection Charting")
|
| 12 |
|
|
|
|
| 57 |
|
| 58 |
ax.legend(loc='upper left')
|
| 59 |
st.pyplot(fig)
|
| 60 |
+
|
| 61 |
+
# Selecting target and features
|
| 62 |
+
target_column = st.selectbox("Select Target Column", options=selected_columns)
|
| 63 |
+
feature_columns = st.multiselect("Select Feature Columns", options=[col for col in selected_columns if col != target_column])
|
| 64 |
+
|
| 65 |
+
# Defining models
|
| 66 |
+
models = {
|
| 67 |
+
"Linear Regression": LinearRegression(),
|
| 68 |
+
"Polynomial Regression": make_pipeline(PolynomialFeatures(degree=2), LinearRegression()),
|
| 69 |
+
"SVR (Support Vector Regression)": SVR(),
|
| 70 |
+
"Random Forest Regression": RandomForestRegressor()
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
# Selecting model
|
| 74 |
+
selected_model = st.selectbox("Select Regression Model", options=list(models.keys()))
|
| 75 |
+
|
| 76 |
+
# Fitting the model
|
| 77 |
+
if st.button("Fit Model"):
|
| 78 |
+
if feature_columns: # Check if feature columns are selected
|
| 79 |
+
X = data[feature_columns]
|
| 80 |
+
y = data[target_column]
|
| 81 |
+
model = models[selected_model]
|
| 82 |
+
model.fit(X, y)
|
| 83 |
+
|
| 84 |
+
# Predicting and plotting
|
| 85 |
+
predictions = model.predict(X)
|
| 86 |
+
fig, ax = plt.subplots(figsize=(10, 5))
|
| 87 |
+
ax.plot(y, label="Actual")
|
| 88 |
+
ax.plot(predictions, label="Predicted")
|
| 89 |
+
ax.legend(loc='upper left')
|
| 90 |
+
st.pyplot(fig)
|
| 91 |
+
else:
|
| 92 |
+
st.error("Please select at least one feature column.")
|
| 93 |
+
else:
|
| 94 |
+
st.warning("Please upload a CSV file.")
|