|
|
|
import streamlit as st |
|
import pandas as pd |
|
import matplotlib.pyplot as plt |
|
from sklearn.linear_model import LinearRegression |
|
from sklearn.preprocessing import PolynomialFeatures |
|
from sklearn.pipeline import make_pipeline |
|
from sklearn.svm import SVR |
|
from sklearn.ensemble import RandomForestRegressor |
|
|
|
st.title("๋ฐ์ดํฐ(csv)ํ์ผ์ ์
๋ก๋ํด์ฃผ์ธ์") |
|
|
|
uploaded_file = st.file_uploader("Choose a CSV file", type="csv") |
|
|
|
time_frame_options = [ |
|
"All", |
|
"1 second", |
|
"5 seconds", |
|
"10 seconds", |
|
"30 seconds", |
|
"1 minute", |
|
"5 minutes", |
|
"10 minutes", |
|
"30 minutes", |
|
"60 minutes", |
|
] |
|
time_frame = st.selectbox("Data Time Frame", time_frame_options) |
|
|
|
if uploaded_file is not None: |
|
|
|
data = pd.read_csv(uploaded_file) |
|
|
|
|
|
if time_frame != "All": |
|
seconds = { |
|
"1 second": 1, |
|
"5 seconds": 5, |
|
"10 seconds": 10, |
|
"30 seconds": 30, |
|
"1 minute": 60, |
|
"5 minutes": 300, |
|
"10 minutes": 600, |
|
"30 minutes": 1800, |
|
"60 minutes": 3600, |
|
} |
|
data['timestamp'] = pd.to_datetime(data['timestamp'], unit='ms') |
|
data.set_index('timestamp', inplace=True) |
|
data = data.resample(f"{seconds[time_frame]}S").mean().dropna().reset_index() |
|
|
|
|
|
selected_columns = st.multiselect("Select Columns", options=['R', 'G', 'B', 'H', 'S', 'V']) |
|
|
|
|
|
fig, ax = plt.subplots(figsize=(10, 5)) |
|
for col in selected_columns: |
|
ax.plot(data[col], label=col) |
|
|
|
ax.legend(loc='upper left') |
|
st.pyplot(fig) |
|
|
|
|
|
target_column = st.selectbox("Select Target Column", options=selected_columns) |
|
feature_columns = st.multiselect("Select Feature Columns", options=[col for col in selected_columns if col != target_column]) |
|
|
|
|
|
models = { |
|
"Linear Regression": LinearRegression(), |
|
"Polynomial Regression": make_pipeline(PolynomialFeatures(degree=2), LinearRegression()), |
|
"SVR (Support Vector Regression)": SVR(), |
|
"Random Forest Regression": RandomForestRegressor() |
|
} |
|
|
|
|
|
selected_model = st.selectbox("Select Regression Model", options=list(models.keys())) |
|
|
|
|
|
if st.button("Fit Model"): |
|
if feature_columns: |
|
X = data[feature_columns] |
|
y = data[target_column] |
|
model = models[selected_model] |
|
model.fit(X, y) |
|
|
|
|
|
predictions = model.predict(X) |
|
fig, ax = plt.subplots(figsize=(10, 5)) |
|
ax.plot(y, label="Actual") |
|
ax.plot(predictions, label="Predicted") |
|
ax.legend(loc='upper left') |
|
st.pyplot(fig) |
|
else: |
|
st.error("Please select at least one feature column.") |
|
else: |
|
st.warning("Please upload a CSV file.") |
|
|