Update app.py
Browse files
app.py
CHANGED
|
@@ -2,12 +2,6 @@
|
|
| 2 |
import streamlit as st
|
| 3 |
import pandas as pd
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
-
import numpy as np
|
| 6 |
-
from sklearn.linear_model import LinearRegression
|
| 7 |
-
from sklearn.preprocessing import PolynomialFeatures
|
| 8 |
-
from sklearn.pipeline import make_pipeline
|
| 9 |
-
from sklearn.svm import SVR
|
| 10 |
-
from sklearn.ensemble import RandomForestRegressor
|
| 11 |
|
| 12 |
st.title("Webcam Color Detection Charting")
|
| 13 |
|
|
@@ -27,15 +21,6 @@ time_frame_options = [
|
|
| 27 |
]
|
| 28 |
time_frame = st.selectbox("Data Time Frame", time_frame_options)
|
| 29 |
|
| 30 |
-
regression_options = [
|
| 31 |
-
"None",
|
| 32 |
-
"Linear Regression",
|
| 33 |
-
"Polynomial Regression",
|
| 34 |
-
"SVR (Support Vector Regression)",
|
| 35 |
-
"Random Forest Regression",
|
| 36 |
-
]
|
| 37 |
-
regression_type = st.selectbox("Regression Analysis Type", regression_options)
|
| 38 |
-
|
| 39 |
if uploaded_file is not None:
|
| 40 |
# Read CSV file
|
| 41 |
data = pd.read_csv(uploaded_file)
|
|
@@ -57,59 +42,13 @@ if uploaded_file is not None:
|
|
| 57 |
data.set_index('timestamp', inplace=True)
|
| 58 |
data = data.resample(f"{seconds[time_frame]}S").mean().dropna().reset_index()
|
| 59 |
|
| 60 |
-
#
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
# RGB chart
|
| 64 |
-
axes[0].plot(data['R'], 'r', label='R')
|
| 65 |
-
axes[0].plot(data['G'], 'g', label='G')
|
| 66 |
-
axes[0].plot(data['B'], 'b', label='B')
|
| 67 |
-
|
| 68 |
-
# HSV chart
|
| 69 |
-
axes[1].plot(data['H'], 'r', label='H')
|
| 70 |
-
axes[1].plot(data['S'], 'g', label='S')
|
| 71 |
-
axes[1].plot(data['V'], 'b', label='V')
|
| 72 |
-
|
| 73 |
-
axes[0].legend(loc='upper right')
|
| 74 |
-
axes[0].set_title('RGB Values')
|
| 75 |
-
axes[1].legend(loc='upper right')
|
| 76 |
-
axes[1].set_title('HSV Values')
|
| 77 |
-
|
| 78 |
-
# Perform regression analysis if selected
|
| 79 |
-
if regression_type != "None":
|
| 80 |
-
X = np.arange(len(data)).reshape(-1, 1)
|
| 81 |
-
|
| 82 |
-
# Linear Regression
|
| 83 |
-
if regression_type == "Linear Regression":
|
| 84 |
-
model = LinearRegression()
|
| 85 |
-
for color, code in zip(['R', 'G', 'B'], ['r', 'g', 'b']):
|
| 86 |
-
model.fit(X, data[color])
|
| 87 |
-
axes[0].plot(X, model.predict(X), f'{code}--')
|
| 88 |
-
st.write(f"{color}: y = {model.coef_[0]} * x + {model.intercept_}")
|
| 89 |
-
|
| 90 |
-
# Polynomial Regression
|
| 91 |
-
elif regression_type == "Polynomial Regression":
|
| 92 |
-
polynomial_features = PolynomialFeatures(degree=2)
|
| 93 |
-
model = make_pipeline(polynomial_features, LinearRegression())
|
| 94 |
-
for color, code in zip(['R', 'G', 'B'], ['r', 'g', 'b']):
|
| 95 |
-
model.fit(X, data[color])
|
| 96 |
-
axes[0].plot(X, model.predict(X), f'{code}--')
|
| 97 |
-
st.write("Polynomial regression equation is not easily representable.")
|
| 98 |
-
|
| 99 |
-
# SVR (Support Vector Regression)
|
| 100 |
-
elif regression_type == "SVR (Support Vector Regression)":
|
| 101 |
-
model = SVR()
|
| 102 |
-
for color, code in zip(['R', 'G', 'B'], ['r', 'g', 'b']):
|
| 103 |
-
model.fit(X, data[color])
|
| 104 |
-
axes[0].plot(X, model.predict(X), f'{code}--')
|
| 105 |
-
st.write("SVR equation is not easily representable.")
|
| 106 |
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
model.fit(X, data[color])
|
| 112 |
-
axes[0].plot(X, model.predict(X), f'{code}--')
|
| 113 |
-
st.write("Random Forest equation is not easily representable.")
|
| 114 |
|
|
|
|
| 115 |
st.pyplot(fig)
|
|
|
|
| 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 |
|
|
|
|
| 21 |
]
|
| 22 |
time_frame = st.selectbox("Data Time Frame", time_frame_options)
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
if uploaded_file is not None:
|
| 25 |
# Read CSV file
|
| 26 |
data = pd.read_csv(uploaded_file)
|
|
|
|
| 42 |
data.set_index('timestamp', inplace=True)
|
| 43 |
data = data.resample(f"{seconds[time_frame]}S").mean().dropna().reset_index()
|
| 44 |
|
| 45 |
+
# Let the user select the columns
|
| 46 |
+
selected_columns = st.multiselect("Select Columns", options=['R', 'G', 'B', 'H', 'S', 'V'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
# Create charts based on selected columns
|
| 49 |
+
fig, ax = plt.subplots(figsize=(10, 5))
|
| 50 |
+
for col in selected_columns:
|
| 51 |
+
ax.plot(data[col], label=col)
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
ax.legend(loc='upper left')
|
| 54 |
st.pyplot(fig)
|