Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,12 @@ import streamlit as st
|
|
3 |
import pandas as pd
|
4 |
import matplotlib.pyplot as plt
|
5 |
import io
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
st.title("Webcam Color Detection Charting")
|
8 |
|
@@ -22,6 +28,15 @@ time_frame_options = [
|
|
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,7 +65,57 @@ if uploaded_file is not None:
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
axes[0].set_title('RGB Values')
|
55 |
|
56 |
# HSV ์ฐจํธ
|
|
|
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 |
]
|
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)
|
|
|
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 ์ฐจํธ
|