Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
|
2 |
import streamlit as st
|
3 |
import pandas as pd
|
4 |
import matplotlib.pyplot as plt
|
@@ -125,4 +124,117 @@ elif regression_type == "Random Forest Regression":
|
|
125 |
axes[1].legend(loc='upper right')
|
126 |
axes[1].set_title('HSV Values')
|
127 |
|
128 |
-
st.pyplot(fig)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import matplotlib.pyplot as plt
|
|
|
124 |
axes[1].legend(loc='upper right')
|
125 |
axes[1].set_title('HSV Values')
|
126 |
|
127 |
+
st.pyplot(figst.pyplot(fig)uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
|
128 |
+
|
129 |
+
time_frame_options = [
|
130 |
+
"All",
|
131 |
+
"1 second",
|
132 |
+
"5 seconds",
|
133 |
+
"10 seconds",
|
134 |
+
"30 seconds",
|
135 |
+
"1 minute",
|
136 |
+
"5 minutes",
|
137 |
+
"10 minutes",
|
138 |
+
"30 minutes",
|
139 |
+
"60 minutes",
|
140 |
+
]
|
141 |
+
time_frame = st.selectbox("Data Time Frame", time_frame_options)
|
142 |
+
|
143 |
+
|
144 |
+
regression_options = [
|
145 |
+
"None",
|
146 |
+
"Linear Regression",
|
147 |
+
"Polynomial Regression",
|
148 |
+
"SVR (Support Vector Regression)",
|
149 |
+
"Random Forest Regression",
|
150 |
+
]
|
151 |
+
regression_type = st.selectbox("Regression Analysis Type", regression_options)
|
152 |
+
if uploaded_file is not None:
|
153 |
+
# CSV ํ์ผ ์ฝ๊ธฐ
|
154 |
+
data = pd.read_csv(uploaded_file)
|
155 |
+
|
156 |
+
# ์๊ฐ ํ๋ ์์ ๋ฐ๋ฅธ ๋ฐ์ดํฐ ํํฐ๋ง
|
157 |
+
if time_frame != "All":
|
158 |
+
seconds = {
|
159 |
+
"1 second": 1,
|
160 |
+
"5 seconds": 5,
|
161 |
+
"10 seconds": 10,
|
162 |
+
"30 seconds": 30,
|
163 |
+
"1 minute": 60,
|
164 |
+
"5 minutes": 300,
|
165 |
+
"10 minutes": 600,
|
166 |
+
"30 minutes": 1800,
|
167 |
+
"60 minutes": 3600,
|
168 |
+
}
|
169 |
+
data['timestamp'] = pd.to_datetime(data['timestamp'], unit='ms')
|
170 |
+
data.set_index('timestamp', inplace=True)
|
171 |
+
data = data.resample(f"{seconds[time_frame]}S").mean().dropna().reset_index()
|
172 |
+
|
173 |
+
# ์ฐจํธ ์์ฑ
|
174 |
+
fig, axes = plt.subplots(2, 1, figsize=(10, 8))
|
175 |
+
|
176 |
+
# RGB ์ฐจํธ
|
177 |
+
axes[0].plot(data['R'], 'r', label='R')
|
178 |
+
axes[0].plot(data['G'], 'g', label='G')
|
179 |
+
axes[0].plot(data['B'], 'b', label='B')
|
180 |
+
|
181 |
+
# ํ๊ท ๋ถ์ ์ํ
|
182 |
+
X = np.arange(len(data)).reshape(-1, 1)
|
183 |
+
|
184 |
+
# ์ ํ ํ๊ท
|
185 |
+
if regression_type == "Linear Regression":
|
186 |
+
model = LinearRegression()
|
187 |
+
model.fit(X, data['R'])
|
188 |
+
axes[0].plot(X, model.predict(X), 'r--')
|
189 |
+
st.write(f"R: y = {model.coef_[0]} * x + {model.intercept_}")
|
190 |
+
model.fit(X, data['G'])
|
191 |
+
axes[0].plot(X, model.predict(X), 'g--')
|
192 |
+
st.write(f"G: y = {model.coef_[0]} * x + {model.intercept_}")
|
193 |
+
model.fit(X, data['B'])
|
194 |
+
axes[0].plot(X, model.predict(X), 'b--')
|
195 |
+
st.write(f"B: y = {model.coef_[0]} * x + {model.intercept_}")
|
196 |
+
|
197 |
+
# ๋คํญ ํ๊ท
|
198 |
+
elif regression_type == "Polynomial Regression":
|
199 |
+
polynomial_features = PolynomialFeatures(degree=2)
|
200 |
+
model = make_pipeline(polynomial_features, LinearRegression())
|
201 |
+
model.fit(X, data['R'])
|
202 |
+
axes[0].plot(X, model.predict(X), 'r--')
|
203 |
+
model.fit(X, data['G'])
|
204 |
+
axes[0].plot(X, model.predict(X), 'g--')
|
205 |
+
model.fit(X, data['B'])
|
206 |
+
axes[0].plot(X, model.predict(X), 'b--')
|
207 |
+
st.write("Polynomial regression equation is not easily representable.")
|
208 |
+
|
209 |
+
# SVR (Support Vector Regression)
|
210 |
+
elif regression_type == "SVR (Support Vector Regression)":
|
211 |
+
model = SVR()
|
212 |
+
model.fit(X, data['R'])
|
213 |
+
axes[0].plot(X, model.predict(X), 'r--')
|
214 |
+
model.fit(X, data['G'])
|
215 |
+
axes[0].plot(X, model.predict(X), 'g--')
|
216 |
+
model.fit(X, data['B'])
|
217 |
+
axes[0].plot(X, model.predict(X), 'b--')
|
218 |
+
st.write("SVR equation is not easily representable.")
|
219 |
+
|
220 |
+
# Random Forest Regression
|
221 |
+
elif regression_type == "Random Forest Regression":
|
222 |
+
model = RandomForestRegressor()
|
223 |
+
model.fit(X, data['R'])
|
224 |
+
axes[0].plot(X, model.predict(X), 'r--')
|
225 |
+
model.fit(X, data['G'])
|
226 |
+
axes[0].plot(X, model.predict(X), 'g--')
|
227 |
+
model.fit(X, data['B'])
|
228 |
+
axes[0].plot(X, model.predict(X), 'b--')
|
229 |
+
st.write("Random Forest equation is not easily representable.")
|
230 |
+
axes[0].legend(loc='upper right')
|
231 |
+
axes[0].set_title('RGB Values')
|
232 |
+
|
233 |
+
# HSV ์ฐจํธ
|
234 |
+
axes[1].plot(data['H'], 'r', label='H')
|
235 |
+
axes[1].plot(data['S'], 'g', label='S')
|
236 |
+
axes[1].plot(data['V'], 'b', label='V')
|
237 |
+
axes[1].legend(loc='upper right')
|
238 |
+
axes[1].set_title('HSV Values')
|
239 |
+
|
240 |
+
|