File size: 3,061 Bytes
ffdb35d
bd820cc
 
ffdb35d
7c53a1e
 
 
 
 
ffdb35d
7501233
ffdb35d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a7eda84
 
ffdb35d
a7eda84
 
 
 
e741394
a7eda84
ffdb35d
7c53a1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

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:
    # Read CSV file
    data = pd.read_csv(uploaded_file)

    # Filter data according to the time frame
    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()

    # Let the user select the columns
    selected_columns = st.multiselect("Select Columns", options=['R', 'G', 'B', 'H', 'S', 'V'])

    # Create charts based on selected columns
    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)

    # Selecting target and features
    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])

    # Defining models
    models = {
        "Linear Regression": LinearRegression(),
        "Polynomial Regression": make_pipeline(PolynomialFeatures(degree=2), LinearRegression()),
        "SVR (Support Vector Regression)": SVR(),
        "Random Forest Regression": RandomForestRegressor()
    }

    # Selecting model
    selected_model = st.selectbox("Select Regression Model", options=list(models.keys()))

    # Fitting the model
    if st.button("Fit Model"):
        if feature_columns: # Check if feature columns are selected
            X = data[feature_columns]
            y = data[target_column]
            model = models[selected_model]
            model.fit(X, y)

            # Predicting and plotting
            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.")