rollback
Browse files
app.py
CHANGED
@@ -3,12 +3,6 @@ import streamlit as st
|
|
3 |
import pandas as pd
|
4 |
import matplotlib.pyplot as plt
|
5 |
import io
|
6 |
-
import numpy as np
|
7 |
-
from sklearn.linear_model import LinearRegression
|
8 |
-
from sklearn.preprocessing import PolynomialFeatures
|
9 |
-
from sklearn.pipeline import make_pipeline
|
10 |
-
from sklearn.svm import SVR
|
11 |
-
from sklearn.ensemble import RandomForestRegressor
|
12 |
|
13 |
st.title("Webcam Color Detection Charting")
|
14 |
|
@@ -28,128 +22,6 @@ time_frame_options = [
|
|
28 |
]
|
29 |
time_frame = st.selectbox("Data Time Frame", time_frame_options)
|
30 |
|
31 |
-
|
32 |
-
regression_options = [
|
33 |
-
"None",
|
34 |
-
"Linear Regression",
|
35 |
-
"Polynomial Regression",
|
36 |
-
"SVR (Support Vector Regression)",
|
37 |
-
"Random Forest Regression",
|
38 |
-
]
|
39 |
-
regression_type = st.selectbox("Regression Analysis Type", regression_options)
|
40 |
-
if uploaded_file is not None:
|
41 |
-
# CSV ํ์ผ ์ฝ๊ธฐ
|
42 |
-
data = pd.read_csv(uploaded_file)
|
43 |
-
|
44 |
-
# ์๊ฐ ํ๋ ์์ ๋ฐ๋ฅธ ๋ฐ์ดํฐ ํํฐ๋ง
|
45 |
-
if time_frame != "All":
|
46 |
-
seconds = {
|
47 |
-
"1 second": 1,
|
48 |
-
"5 seconds": 5,
|
49 |
-
"10 seconds": 10,
|
50 |
-
"30 seconds": 30,
|
51 |
-
"1 minute": 60,
|
52 |
-
"5 minutes": 300,
|
53 |
-
"10 minutes": 600,
|
54 |
-
"30 minutes": 1800,
|
55 |
-
"60 minutes": 3600,
|
56 |
-
}
|
57 |
-
data['timestamp'] = pd.to_datetime(data['timestamp'], unit='ms')
|
58 |
-
data.set_index('timestamp', inplace=True)
|
59 |
-
data = data.resample(f"{seconds[time_frame]}S").mean().dropna().reset_index()
|
60 |
-
|
61 |
-
# ์ฐจํธ ์์ฑ
|
62 |
-
fig, axes = plt.subplots(2, 1, figsize=(10, 8))
|
63 |
-
|
64 |
-
# RGB ์ฐจํธ
|
65 |
-
axes[0].plot(data['R'], 'r', label='R')
|
66 |
-
axes[0].plot(data['G'], 'g', label='G')
|
67 |
-
axes[0].plot(data['B'], 'b', label='B')
|
68 |
-
|
69 |
-
# ํ๊ท ๋ถ์ ์ํ
|
70 |
-
X = np.arange(len(data)).reshape(-1, 1)
|
71 |
-
|
72 |
-
# ์ ํ ํ๊ท
|
73 |
-
if regression_type == "Linear Regression":
|
74 |
-
model = LinearRegression()
|
75 |
-
model.fit(X, data['R'])
|
76 |
-
axes[0].plot(X, model.predict(X), 'r--')
|
77 |
-
st.write(f"R: y = {model.coef_[0]} * x + {model.intercept_}")
|
78 |
-
model.fit(X, data['G'])
|
79 |
-
axes[0].plot(X, model.predict(X), 'g--')
|
80 |
-
st.write(f"G: y = {model.coef_[0]} * x + {model.intercept_}")
|
81 |
-
model.fit(X, data['B'])
|
82 |
-
axes[0].plot(X, model.predict(X), 'b--')
|
83 |
-
st.write(f"B: y = {model.coef_[0]} * x + {model.intercept_}")
|
84 |
-
|
85 |
-
# ๋คํญ ํ๊ท
|
86 |
-
elif regression_type == "Polynomial Regression":
|
87 |
-
polynomial_features = PolynomialFeatures(degree=2)
|
88 |
-
model = make_pipeline(polynomial_features, LinearRegression())
|
89 |
-
model.fit(X, data['R'])
|
90 |
-
axes[0].plot(X, model.predict(X), 'r--')
|
91 |
-
model.fit(X, data['G'])
|
92 |
-
axes[0].plot(X, model.predict(X), 'g--')
|
93 |
-
model.fit(X, data['B'])
|
94 |
-
axes[0].plot(X, model.predict(X), 'b--')
|
95 |
-
st.write("Polynomial regression equation is not easily representable.")
|
96 |
-
|
97 |
-
# SVR (Support Vector Regression)
|
98 |
-
elif regression_type == "SVR (Support Vector Regression)":
|
99 |
-
model = SVR()
|
100 |
-
model.fit(X, data['R'])
|
101 |
-
axes[0].plot(X, model.predict(X), 'r--')
|
102 |
-
model.fit(X, data['G'])
|
103 |
-
axes[0].plot(X, model.predict(X), 'g--')
|
104 |
-
model.fit(X, data['B'])
|
105 |
-
axes[0].plot(X, model.predict(X), 'b--')
|
106 |
-
st.write("SVR equation is not easily representable.")
|
107 |
-
|
108 |
-
# Random Forest Regression
|
109 |
-
elif regression_type == "Random Forest Regression":
|
110 |
-
model = RandomForestRegressor()
|
111 |
-
model.fit(X, data['R'])
|
112 |
-
axes[0].plot(X, model.predict(X), 'r--')
|
113 |
-
model.fit(X, data['G'])
|
114 |
-
axes[0].plot(X, model.predict(X), 'g--')
|
115 |
-
model.fit(X, data['B'])
|
116 |
-
axes[0].plot(X, model.predict(X), 'b--')
|
117 |
-
st.write("Random Forest equation is not easily representable.")
|
118 |
-
axes[0].legend(loc='upper right')
|
119 |
-
axes[0].set_title('RGB Values')
|
120 |
-
|
121 |
-
# HSV ์ฐจํธ
|
122 |
-
axes[1].plot(data['H'], 'r', label='H')
|
123 |
-
axes[1].plot(data['S'], 'g', label='S')
|
124 |
-
axes[1].plot(data['V'], 'b', label='V')
|
125 |
-
axes[1].legend(loc='upper right')
|
126 |
-
axes[1].set_title('HSV Values')
|
127 |
-
|
128 |
-
st.pyplot(fig)uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
|
129 |
-
|
130 |
-
time_frame_options = [
|
131 |
-
"All",
|
132 |
-
"1 second",
|
133 |
-
"5 seconds",
|
134 |
-
"10 seconds",
|
135 |
-
"30 seconds",
|
136 |
-
"1 minute",
|
137 |
-
"5 minutes",
|
138 |
-
"10 minutes",
|
139 |
-
"30 minutes",
|
140 |
-
"60 minutes",
|
141 |
-
]
|
142 |
-
time_frame = st.selectbox("Data Time Frame", time_frame_options)
|
143 |
-
|
144 |
-
|
145 |
-
regression_options = [
|
146 |
-
"None",
|
147 |
-
"Linear Regression",
|
148 |
-
"Polynomial Regression",
|
149 |
-
"SVR (Support Vector Regression)",
|
150 |
-
"Random Forest Regression",
|
151 |
-
]
|
152 |
-
regression_type = st.selectbox("Regression Analysis Type", regression_options)
|
153 |
if uploaded_file is not None:
|
154 |
# CSV ํ์ผ ์ฝ๊ธฐ
|
155 |
data = pd.read_csv(uploaded_file)
|
@@ -178,81 +50,6 @@ if uploaded_file is not None:
|
|
178 |
axes[0].plot(data['R'], 'r', label='R')
|
179 |
axes[0].plot(data['G'], 'g', label='G')
|
180 |
axes[0].plot(data['B'], 'b', label='B')
|
181 |
-
|
182 |
-
# ํ๊ท ๋ถ์ ์ํ
|
183 |
-
X = np.arange(len(data)).reshape(-1, 1)
|
184 |
-
|
185 |
-
# ์ ํ ํ๊ท
|
186 |
-
if regression_type == "Linear Regression":
|
187 |
-
model = LinearRegression()
|
188 |
-
model.fit(X, data['R'])
|
189 |
-
axes[0].plot(X, model.predict(X), 'r--')
|
190 |
-
st.write(f"R: y = {model.coef_[0]} * x + {model.intercept_}")
|
191 |
-
model.fit(X, data['G'])
|
192 |
-
axes[0].plot(X, model.predict(X), 'g--')
|
193 |
-
st.write(f"G: y = {model.coef_[0]} * x + {model.intercept_}")
|
194 |
-
model.fit(X, data['B'])
|
195 |
-
axes[0].plot(X, model.predict(X), 'b--')
|
196 |
-
st.write(f"B: y = {model.coef_[0]} * x + {model.intercept_}")
|
197 |
-
|
198 |
-
# ๋คํญ ํ๊ท
|
199 |
-
elif regression_type == "Polynomial Regression":
|
200 |
-
polynomial_features = PolynomialFeatures(degree=2)
|
201 |
-
model = make_pipeline(polynomial_features, LinearRegression())
|
202 |
-
model.fit(X, data['R'])
|
203 |
-
axes[0].plot(X, model.predict(X), 'r--')
|
204 |
-
model.fit(X, data['G'])
|
205 |
-
axes[0].plot(X, model.predict(X), 'g--')
|
206 |
-
model.fit(X, data['B'])
|
207 |
-
axes[0].plot(X, model.predict(X), 'b--')
|
208 |
-
st.write("Polynomial regression equation is not easily representable.")
|
209 |
-
|
210 |
-
# SVR (Support Vector Regression)
|
211 |
-
elif regression_type == "SVR (Support Vector Regression)":
|
212 |
-
model = SVR()
|
213 |
-
model.fit(X, data['R'])
|
214 |
-
axes[0].plot(X, model.predict(X), 'r--')
|
215 |
-
model.fit(X, data['G'])
|
216 |
-
axes[0].plot(X, model.predict(X), 'g--')
|
217 |
-
model.fit(X, data['B'])
|
218 |
-
axes[0].plot(X, model.predict(X), 'b--')
|
219 |
-
st.write("SVR equation is not easily representable.")
|
220 |
-
|
221 |
-
# Random Forest Regression
|
222 |
-
elif regression_type == "Random Forest Regression":
|
223 |
-
model = RandomForestRegressor()
|
224 |
-
model.fit(X, data['R'])
|
225 |
-
axes[0].plot(X, model.predict(X), 'r--')
|
226 |
-
model.fit(X, data['G'])
|
227 |
-
axes[0].plot(X, model.predict(X), 'g--')
|
228 |
-
model.fit(X, data['B'])
|
229 |
-
axes[0].plot(X, model.predict(X), 'b--')
|
230 |
-
st.write("Random Forest equation is not easily representable.")
|
231 |
-
axes[0].legend(loc='upper right')
|
232 |
-
axes[0].set_title('RGB Values')
|
233 |
-
|
234 |
-
# HSV ์ฐจํธ
|
235 |
-
axes[1].plot(data['H'], 'r', label='H')
|
236 |
-
axes[1].plot(data['S'], 'g', label='S')
|
237 |
-
axes[1].plot(data['V'], 'b', label='V')
|
238 |
-
axes[1].legend(loc='upper right')
|
239 |
-
axes[1].set_title('HSV Values')
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
if uploaded_file is not None:
|
244 |
-
# CSV ํ์ผ ์ฝ๊ธฐ
|
245 |
-
data = pd.read_csv(uploaded_file)
|
246 |
-
st.write("Data Preview:")
|
247 |
-
st.write(data.head())
|
248 |
-
|
249 |
-
# ๋ฐ์ดํฐ ์๊ฐํ (RGB & HSV)
|
250 |
-
fig, axes = plt.subplots(2, 1, figsize=(10, 8))
|
251 |
-
|
252 |
-
# RGB ์ฐจํธ
|
253 |
-
axes[0].plot(data['R'], 'r', label='R')
|
254 |
-
axes[0].plot(data['G'], 'g', label='G')
|
255 |
-
axes[0].plot(data['B'], 'b', label='B')
|
256 |
axes[0].legend(loc='upper right')
|
257 |
axes[0].set_title('RGB Values')
|
258 |
|
@@ -264,18 +61,3 @@ if uploaded_file is not None:
|
|
264 |
axes[1].set_title('HSV Values')
|
265 |
|
266 |
st.pyplot(fig)
|
267 |
-
|
268 |
-
X = np.arange(len(data)).reshape(-1, 1)
|
269 |
-
|
270 |
-
# Linear Regression
|
271 |
-
if regression_type == "Linear Regression":
|
272 |
-
model = LinearRegression()
|
273 |
-
model.fit(X, data['R'])
|
274 |
-
axes[0].plot(X, model.predict(X), 'r--')
|
275 |
-
model.fit(X, data['G'])
|
276 |
-
axes[0].plot(X, model.predict(X), 'g--')
|
277 |
-
model.fit(X, data['B'])
|
278 |
-
axes[0].plot(X, model.predict(X), 'b--')
|
279 |
-
st.write(f"Linear equation: y = {model.coef_[0]} * x + {model.intercept_}")
|
280 |
-
|
281 |
-
# Other regression types...
|
|
|
3 |
import pandas as pd
|
4 |
import matplotlib.pyplot as plt
|
5 |
import io
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
st.title("Webcam Color Detection Charting")
|
8 |
|
|
|
22 |
]
|
23 |
time_frame = st.selectbox("Data Time Frame", time_frame_options)
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
if uploaded_file is not None:
|
26 |
# CSV ํ์ผ ์ฝ๊ธฐ
|
27 |
data = pd.read_csv(uploaded_file)
|
|
|
50 |
axes[0].plot(data['R'], 'r', label='R')
|
51 |
axes[0].plot(data['G'], 'g', label='G')
|
52 |
axes[0].plot(data['B'], 'b', label='B')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
axes[0].legend(loc='upper right')
|
54 |
axes[0].set_title('RGB Values')
|
55 |
|
|
|
61 |
axes[1].set_title('HSV Values')
|
62 |
|
63 |
st.pyplot(fig)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|