Update src/streamlit_app.py
Browse files- src/streamlit_app.py +154 -73
src/streamlit_app.py
CHANGED
|
@@ -23,75 +23,118 @@ DetectorFactory.seed = 0
|
|
| 23 |
# ==============================
|
| 24 |
st.set_page_config(page_title="SKRIPSI - Sentiment & Volatility", page_icon="βΏ", layout="wide")
|
| 25 |
|
| 26 |
-
# Custom CSS
|
| 27 |
st.markdown("""
|
| 28 |
<style>
|
|
|
|
| 29 |
:root {
|
| 30 |
--bitcoin-orange: #F7931A;
|
| 31 |
-
--
|
| 32 |
-
--
|
| 33 |
-
--
|
|
|
|
|
|
|
|
|
|
| 34 |
}
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
h1, h2, h3, h4, h5, h6 {
|
| 37 |
-
color: var(--
|
| 38 |
-
font-
|
|
|
|
| 39 |
}
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
div.stButton > button:first-child {
|
| 42 |
background-color: var(--bitcoin-orange);
|
| 43 |
color: #ffffff;
|
| 44 |
border: none;
|
| 45 |
-
border-radius:
|
| 46 |
-
padding: 0.
|
| 47 |
-
font-weight:
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
| 49 |
}
|
| 50 |
div.stButton > button:first-child:hover {
|
| 51 |
-
background-color:
|
| 52 |
-
box-shadow: 0
|
| 53 |
-
transform: translateY(-
|
|
|
|
| 54 |
}
|
| 55 |
-
|
|
|
|
| 56 |
.stTabs [data-baseweb="tab-list"] {
|
| 57 |
-
gap:
|
|
|
|
| 58 |
}
|
| 59 |
.stTabs [data-baseweb="tab"] {
|
| 60 |
-
height:
|
| 61 |
white-space: pre-wrap;
|
| 62 |
background-color: transparent;
|
| 63 |
-
border-radius:
|
| 64 |
-
|
|
|
|
|
|
|
| 65 |
padding-top: 10px;
|
| 66 |
padding-bottom: 10px;
|
| 67 |
}
|
| 68 |
.stTabs [aria-selected="true"] {
|
| 69 |
border-bottom: 3px solid var(--bitcoin-orange) !important;
|
| 70 |
-
color: var(--
|
| 71 |
-
font-weight:
|
| 72 |
}
|
| 73 |
-
|
|
|
|
| 74 |
.streamlit-expanderHeader {
|
| 75 |
-
font-weight:
|
|
|
|
|
|
|
|
|
|
| 76 |
}
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
}
|
| 81 |
</style>
|
| 82 |
""", unsafe_allow_html=True)
|
| 83 |
|
| 84 |
-
# Styling Grafik Seaborn & Matplotlib agar sesuai tema
|
| 85 |
-
sns.set_theme(style="
|
| 86 |
-
"axes.facecolor": "#
|
| 87 |
-
"figure.facecolor": "#
|
| 88 |
-
"axes.edgecolor": "#
|
| 89 |
-
"text.color": "#
|
| 90 |
-
"xtick.color": "#
|
| 91 |
-
"ytick.color": "#
|
| 92 |
-
"grid.color": "#
|
| 93 |
})
|
| 94 |
-
plt.style.use('
|
| 95 |
|
| 96 |
# ==============================
|
| 97 |
# DOWNLOAD REQUIRED RESOURCES
|
|
@@ -153,11 +196,31 @@ def get_daily_label(score):
|
|
| 153 |
else: return 'Neutral'
|
| 154 |
|
| 155 |
# ==============================
|
| 156 |
-
# UI UTAMA STREAMLIT
|
| 157 |
# ==============================
|
| 158 |
-
st.markdown("<
|
| 159 |
-
|
| 160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
tab1, tab2 = st.tabs(["π§ͺ Uji Kalimat (Playground)", "π Analisis Batch Data (Pipeline)"])
|
| 163 |
|
|
@@ -165,7 +228,8 @@ tab1, tab2 = st.tabs(["π§ͺ Uji Kalimat (Playground)", "π Analisis Batch Data
|
|
| 165 |
# TAB 1: UJI KALIMAT
|
| 166 |
# ==============================
|
| 167 |
with tab1:
|
| 168 |
-
|
|
|
|
| 169 |
|
| 170 |
with col1:
|
| 171 |
st.subheader("Input Data")
|
|
@@ -204,7 +268,6 @@ with tab1:
|
|
| 204 |
try: rl_label = roberta_large(text)[0]['label'].lower()
|
| 205 |
except: rl_label = "neutral"
|
| 206 |
|
| 207 |
-
# Formatting label untuk tampilan yang lebih menarik
|
| 208 |
def format_label(label):
|
| 209 |
if label == 'positive': return "π’ Positive"
|
| 210 |
elif label == 'negative': return "π΄ Negative"
|
|
@@ -220,12 +283,22 @@ with tab1:
|
|
| 220 |
# TAB 2: ANALISIS BATCH
|
| 221 |
# ==============================
|
| 222 |
with tab2:
|
| 223 |
-
st.
|
| 224 |
-
|
|
|
|
|
|
|
| 225 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
with col_upload:
|
|
|
|
|
|
|
| 227 |
tweet_files = st.file_uploader("Pilih file Tweet (.txt)", type=['txt'], accept_multiple_files=True)
|
| 228 |
-
|
| 229 |
with st.expander("π Lihat Format TXT yang Benar"):
|
| 230 |
st.code("username | 2024-03-01 14:00:00\nIsi tweet baris pertama di sini\n\nusername2 | 2024-03-01 15:30:00\nIsi tweet baris kedua di sini", language="text")
|
| 231 |
|
|
@@ -346,14 +419,13 @@ with tab2:
|
|
| 346 |
st.warning("β οΈ Data Harga API kosong setelah di-filter. Pastikan format penulisan tanggal di .txt sesuai (yyyy-mm-dd).")
|
| 347 |
else:
|
| 348 |
st.markdown("---")
|
| 349 |
-
st.
|
| 350 |
-
|
| 351 |
-
t1, t2, t3 = st.tabs(["π£οΈ Sentimen Mentah", "π’ Agregasi Sentimen Harian", "βΏ Data Harga Bitcoin"])
|
| 352 |
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
|
|
|
| 357 |
|
| 358 |
# KONVERSI LABEL SENTIMEN KE ANGKA
|
| 359 |
sentiment_map = {"positive": 1, "neutral": 0, "negative": -1}
|
|
@@ -372,22 +444,27 @@ with tab2:
|
|
| 372 |
for col in models:
|
| 373 |
daily_display_cols.extend([col, f"{col}_label"])
|
| 374 |
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
|
|
|
|
|
|
| 378 |
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
|
|
|
|
|
|
| 382 |
|
| 383 |
# MERGE KEDUA TABEL
|
| 384 |
df_merged = pd.merge(df_price, df_sentiment_daily, on="date", how="inner")
|
| 385 |
|
| 386 |
-
st.markdown("
|
|
|
|
| 387 |
final_display_cols = ["date", "price", "pct_change", "log_return"] + [c for c in daily_display_cols if c != "date"]
|
| 388 |
-
st.dataframe(df_merged[final_display_cols], use_container_width=True)
|
| 389 |
|
| 390 |
-
# Export Buttons
|
| 391 |
col_dl1, col_dl2, _ = st.columns([1, 1, 2])
|
| 392 |
csv_data = df_merged.to_csv(index=False).encode('utf-8')
|
| 393 |
col_dl1.download_button("π₯ Download CSV", data=csv_data, file_name="sentiment_volatility.csv", mime="text/csv")
|
|
@@ -439,16 +516,19 @@ with tab2:
|
|
| 439 |
st.subheader("π Trend Analisis: Sentiment vs BTC Volatility")
|
| 440 |
|
| 441 |
fig_line, ax_line = plt.subplots(figsize=(14, 6))
|
|
|
|
|
|
|
| 442 |
ax_line.plot(df_merged["date"], df_merged["log_return"], label="BTC Log Return", color="#F7931A", linewidth=3, linestyle="-")
|
| 443 |
|
| 444 |
-
|
|
|
|
| 445 |
for idx, method in enumerate(["vader", "textblob", "roberta", "roberta_large", "bertweet"]):
|
| 446 |
ax_line.plot(df_merged["date"], df_merged[method], label=f"Sentiment: {method.upper()}", color=colors[idx], linewidth=1.5, linestyle="--", alpha=0.8)
|
| 447 |
|
| 448 |
-
ax_line.set_title("Pergerakan Rata-Rata Sentimen Harian Terhadap Volatilitas Harga Bitcoin", color="
|
| 449 |
-
ax_line.set_xlabel("Tanggal", color="#
|
| 450 |
-
ax_line.set_ylabel("Nilai (Value)", color="#
|
| 451 |
-
ax_line.legend(loc='upper left', bbox_to_anchor=(1, 1), frameon=
|
| 452 |
plt.tight_layout()
|
| 453 |
st.pyplot(fig_line)
|
| 454 |
|
|
@@ -464,18 +544,19 @@ with tab2:
|
|
| 464 |
for idx, method in enumerate(models_list):
|
| 465 |
with cols[idx % 3]:
|
| 466 |
fig_scatter, ax_scatter = plt.subplots(figsize=(5, 4))
|
|
|
|
| 467 |
sns.regplot(data=df_merged, x=method, y="log_return", ax=ax_scatter,
|
| 468 |
-
scatter_kws={"s": 50, "color": "#
|
| 469 |
-
line_kws={"color": "#F7931A", "linewidth": 2})
|
| 470 |
-
ax_scatter.set_title(f"{method.upper()} vs Log Return", color="
|
| 471 |
-
ax_scatter.set_xlabel("Skor Sentimen", color="#
|
| 472 |
-
ax_scatter.set_ylabel("Log Return", color="#
|
| 473 |
plt.tight_layout()
|
| 474 |
st.pyplot(fig_scatter)
|
| 475 |
|
| 476 |
with st.expander("π Panduan Membaca Grafik"):
|
| 477 |
st.write("- **Garis Orange (Trendline):** Menunjukkan arah korelasi (Naik = Positif, Turun = Negatif).")
|
| 478 |
-
st.write("- **Titik
|
| 479 |
|
| 480 |
# ==============================
|
| 481 |
# KESIMPULAN & PEMBAHASAN AKHIR
|
|
|
|
| 23 |
# ==============================
|
| 24 |
st.set_page_config(page_title="SKRIPSI - Sentiment & Volatility", page_icon="βΏ", layout="wide")
|
| 25 |
|
| 26 |
+
# Custom CSS ala "Vancouver Bitcoin" (Clean, Light, Professional, Bitcoin Orange Accents)
|
| 27 |
st.markdown("""
|
| 28 |
<style>
|
| 29 |
+
/* Konfigurasi Palet Warna */
|
| 30 |
:root {
|
| 31 |
--bitcoin-orange: #F7931A;
|
| 32 |
+
--bitcoin-orange-hover: #E8830C;
|
| 33 |
+
--bg-main: #ffffff;
|
| 34 |
+
--bg-secondary: #f8f9fa;
|
| 35 |
+
--text-dark: #111827;
|
| 36 |
+
--text-muted: #6b7280;
|
| 37 |
+
--border-color: #e5e7eb;
|
| 38 |
}
|
| 39 |
+
|
| 40 |
+
/* Memaksa Tampilan Light Mode */
|
| 41 |
+
.stApp {
|
| 42 |
+
background-color: var(--bg-main);
|
| 43 |
+
color: var(--text-dark);
|
| 44 |
+
font-family: 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
/* Mengubah warna teks header utama */
|
| 48 |
h1, h2, h3, h4, h5, h6 {
|
| 49 |
+
color: var(--text-dark) !important;
|
| 50 |
+
font-weight: 700 !important;
|
| 51 |
+
letter-spacing: -0.5px;
|
| 52 |
}
|
| 53 |
+
|
| 54 |
+
/* Highlight spesifik untuk teks Bitcoin */
|
| 55 |
+
.btc-highlight {
|
| 56 |
+
color: var(--bitcoin-orange);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
/* Styling Tombol ala Vancouver Bitcoin */
|
| 60 |
div.stButton > button:first-child {
|
| 61 |
background-color: var(--bitcoin-orange);
|
| 62 |
color: #ffffff;
|
| 63 |
border: none;
|
| 64 |
+
border-radius: 4px;
|
| 65 |
+
padding: 0.6rem 1.5rem;
|
| 66 |
+
font-weight: 600;
|
| 67 |
+
letter-spacing: 0.5px;
|
| 68 |
+
text-transform: uppercase;
|
| 69 |
+
transition: all 0.2s ease-in-out;
|
| 70 |
+
box-shadow: 0 2px 4px rgba(247, 147, 26, 0.2);
|
| 71 |
}
|
| 72 |
div.stButton > button:first-child:hover {
|
| 73 |
+
background-color: var(--bitcoin-orange-hover);
|
| 74 |
+
box-shadow: 0 4px 8px rgba(247, 147, 26, 0.4);
|
| 75 |
+
transform: translateY(-1px);
|
| 76 |
+
color: #ffffff;
|
| 77 |
}
|
| 78 |
+
|
| 79 |
+
/* Styling Tabs yang Elegan */
|
| 80 |
.stTabs [data-baseweb="tab-list"] {
|
| 81 |
+
gap: 30px;
|
| 82 |
+
border-bottom: 2px solid var(--border-color);
|
| 83 |
}
|
| 84 |
.stTabs [data-baseweb="tab"] {
|
| 85 |
+
height: 55px;
|
| 86 |
white-space: pre-wrap;
|
| 87 |
background-color: transparent;
|
| 88 |
+
border-radius: 0px;
|
| 89 |
+
color: var(--text-muted);
|
| 90 |
+
font-weight: 500;
|
| 91 |
+
font-size: 1.05rem;
|
| 92 |
padding-top: 10px;
|
| 93 |
padding-bottom: 10px;
|
| 94 |
}
|
| 95 |
.stTabs [aria-selected="true"] {
|
| 96 |
border-bottom: 3px solid var(--bitcoin-orange) !important;
|
| 97 |
+
color: var(--text-dark) !important;
|
| 98 |
+
font-weight: 700;
|
| 99 |
}
|
| 100 |
+
|
| 101 |
+
/* Expander & Accordion */
|
| 102 |
.streamlit-expanderHeader {
|
| 103 |
+
font-weight: 600;
|
| 104 |
+
color: var(--text-dark);
|
| 105 |
+
background-color: var(--bg-secondary);
|
| 106 |
+
border-radius: 6px;
|
| 107 |
}
|
| 108 |
+
|
| 109 |
+
/* Metrics / Data Cards */
|
| 110 |
+
[data-testid="stMetricValue"] {
|
| 111 |
+
color: var(--bitcoin-orange);
|
| 112 |
+
font-weight: 700;
|
| 113 |
+
}
|
| 114 |
+
[data-testid="stMetricLabel"] {
|
| 115 |
+
color: var(--text-muted);
|
| 116 |
+
font-weight: 600;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
/* Custom divider */
|
| 120 |
+
hr {
|
| 121 |
+
border-color: var(--border-color);
|
| 122 |
+
margin: 2rem 0;
|
| 123 |
}
|
| 124 |
</style>
|
| 125 |
""", unsafe_allow_html=True)
|
| 126 |
|
| 127 |
+
# Styling Grafik Seaborn & Matplotlib agar sesuai tema Terang/Finansial
|
| 128 |
+
sns.set_theme(style="whitegrid", rc={
|
| 129 |
+
"axes.facecolor": "#ffffff",
|
| 130 |
+
"figure.facecolor": "#ffffff",
|
| 131 |
+
"axes.edgecolor": "#e5e7eb",
|
| 132 |
+
"text.color": "#111827",
|
| 133 |
+
"xtick.color": "#4b5563",
|
| 134 |
+
"ytick.color": "#4b5563",
|
| 135 |
+
"grid.color": "#f3f4f6"
|
| 136 |
})
|
| 137 |
+
plt.style.use('default')
|
| 138 |
|
| 139 |
# ==============================
|
| 140 |
# DOWNLOAD REQUIRED RESOURCES
|
|
|
|
| 196 |
else: return 'Neutral'
|
| 197 |
|
| 198 |
# ==============================
|
| 199 |
+
# UI UTAMA STREAMLIT (HERO BANNER)
|
| 200 |
# ==============================
|
| 201 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 202 |
+
|
| 203 |
+
# Layout 2 kolom: Kiri untuk teks judul, Kanan untuk gambar dompet 3D
|
| 204 |
+
hero_col1, hero_col2 = st.columns([1.2, 1], gap="large")
|
| 205 |
+
|
| 206 |
+
with hero_col1:
|
| 207 |
+
st.markdown("""
|
| 208 |
+
<div style="padding-top: 1rem;">
|
| 209 |
+
<h1 style="font-size: 2.8rem; line-height: 1.2; margin-bottom: 1rem;"><span class="btc-highlight">βΏ</span>itcoin Volatility vs Public Sentiment</h1>
|
| 210 |
+
<p style='color: #4b5563; font-size: 1.15rem; font-weight: 500;'>Analisis Volatilitas Harga Bitcoin Terhadap Sentimen Publik Pada Platform X Berbasis Python</p>
|
| 211 |
+
<p style='color: #9ca3af; font-size: 0.95rem; margin-top: 1.5rem; border-left: 4px solid var(--bitcoin-orange); padding-left: 10px;'>
|
| 212 |
+
<b>Peneliti:</b> Arya Galuh Saputra (H1D022022)
|
| 213 |
+
</p>
|
| 214 |
+
</div>
|
| 215 |
+
""", unsafe_allow_html=True)
|
| 216 |
+
|
| 217 |
+
with hero_col2:
|
| 218 |
+
try:
|
| 219 |
+
st.image("crypto-currency-concept-830px.png", use_container_width=True)
|
| 220 |
+
except Exception:
|
| 221 |
+
st.info("β³ Menunggu gambar crypto-currency-concept-830px.png diunggah ke Hugging Face...")
|
| 222 |
+
|
| 223 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 224 |
|
| 225 |
tab1, tab2 = st.tabs(["π§ͺ Uji Kalimat (Playground)", "π Analisis Batch Data (Pipeline)"])
|
| 226 |
|
|
|
|
| 228 |
# TAB 1: UJI KALIMAT
|
| 229 |
# ==============================
|
| 230 |
with tab1:
|
| 231 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 232 |
+
col1, col2 = st.columns([1, 1], gap="large")
|
| 233 |
|
| 234 |
with col1:
|
| 235 |
st.subheader("Input Data")
|
|
|
|
| 268 |
try: rl_label = roberta_large(text)[0]['label'].lower()
|
| 269 |
except: rl_label = "neutral"
|
| 270 |
|
|
|
|
| 271 |
def format_label(label):
|
| 272 |
if label == 'positive': return "π’ Positive"
|
| 273 |
elif label == 'negative': return "π΄ Negative"
|
|
|
|
| 283 |
# TAB 2: ANALISIS BATCH
|
| 284 |
# ==============================
|
| 285 |
with tab2:
|
| 286 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 287 |
+
|
| 288 |
+
# Layout 2 kolom: Kiri untuk gambar ilustrasi dashboard, Kanan untuk file uploader
|
| 289 |
+
col_img, col_upload = st.columns([1, 1.5], gap="large")
|
| 290 |
|
| 291 |
+
with col_img:
|
| 292 |
+
try:
|
| 293 |
+
st.image("slice3-1-1536x830.png", use_container_width=True)
|
| 294 |
+
except Exception:
|
| 295 |
+
st.empty()
|
| 296 |
+
|
| 297 |
with col_upload:
|
| 298 |
+
st.subheader("π Upload Dataset Sentimen")
|
| 299 |
+
st.markdown("<p style='color: #6b7280;'>Unggah file ekstensi .txt yang berisi history tweet untuk dianalisis secara masal.</p>", unsafe_allow_html=True)
|
| 300 |
tweet_files = st.file_uploader("Pilih file Tweet (.txt)", type=['txt'], accept_multiple_files=True)
|
| 301 |
+
|
| 302 |
with st.expander("π Lihat Format TXT yang Benar"):
|
| 303 |
st.code("username | 2024-03-01 14:00:00\nIsi tweet baris pertama di sini\n\nusername2 | 2024-03-01 15:30:00\nIsi tweet baris kedua di sini", language="text")
|
| 304 |
|
|
|
|
| 419 |
st.warning("β οΈ Data Harga API kosong setelah di-filter. Pastikan format penulisan tanggal di .txt sesuai (yyyy-mm-dd).")
|
| 420 |
else:
|
| 421 |
st.markdown("---")
|
| 422 |
+
st.header("π Ringkasan Data Pembentuk Pipeline")
|
|
|
|
|
|
|
| 423 |
|
| 424 |
+
# TABEL 1: SENTIMEN MENTAH
|
| 425 |
+
st.markdown("#### π£οΈ Data Sentimen Mentah")
|
| 426 |
+
st.caption("Tweet asli, hasil preprocessing, dan label prediksi dari 5 model NLP sebelum konversi ke numerik.")
|
| 427 |
+
raw_display_cols = ["date", "raw_tweet", "cleaned_tweet", "vader", "textblob", "bertweet", "roberta", "roberta_large"]
|
| 428 |
+
st.dataframe(df[raw_display_cols], use_container_width=True, hide_index=True)
|
| 429 |
|
| 430 |
# KONVERSI LABEL SENTIMEN KE ANGKA
|
| 431 |
sentiment_map = {"positive": 1, "neutral": 0, "negative": -1}
|
|
|
|
| 444 |
for col in models:
|
| 445 |
daily_display_cols.extend([col, f"{col}_label"])
|
| 446 |
|
| 447 |
+
# TABEL 2: AGREGASI HARIAN
|
| 448 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 449 |
+
st.markdown("#### π’ Agregasi Sentimen Harian")
|
| 450 |
+
st.caption("Rata-rata skor sentimen harian yang dikonversi ke representasi metrik.")
|
| 451 |
+
st.dataframe(df_sentiment_daily[daily_display_cols], use_container_width=True, hide_index=True)
|
| 452 |
|
| 453 |
+
# TABEL 3: HARGA BITCOIN
|
| 454 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 455 |
+
st.markdown("#### βΏ Historis Harga & Volatilitas Bitcoin")
|
| 456 |
+
st.caption("Data pergerakan rata-rata harga, persentase perubahan, dan Log Return (CoinGecko API).")
|
| 457 |
+
st.dataframe(df_price[["date", "price", "pct_change", "log_return"]], use_container_width=True, hide_index=True)
|
| 458 |
|
| 459 |
# MERGE KEDUA TABEL
|
| 460 |
df_merged = pd.merge(df_price, df_sentiment_daily, on="date", how="inner")
|
| 461 |
|
| 462 |
+
st.markdown("---")
|
| 463 |
+
st.markdown("### ποΈ Dataset Final (Tabel Terintegrasi Siap Uji)")
|
| 464 |
final_display_cols = ["date", "price", "pct_change", "log_return"] + [c for c in daily_display_cols if c != "date"]
|
| 465 |
+
st.dataframe(df_merged[final_display_cols], use_container_width=True, hide_index=True)
|
| 466 |
|
| 467 |
+
# Export Buttons
|
| 468 |
col_dl1, col_dl2, _ = st.columns([1, 1, 2])
|
| 469 |
csv_data = df_merged.to_csv(index=False).encode('utf-8')
|
| 470 |
col_dl1.download_button("π₯ Download CSV", data=csv_data, file_name="sentiment_volatility.csv", mime="text/csv")
|
|
|
|
| 516 |
st.subheader("π Trend Analisis: Sentiment vs BTC Volatility")
|
| 517 |
|
| 518 |
fig_line, ax_line = plt.subplots(figsize=(14, 6))
|
| 519 |
+
|
| 520 |
+
# Warna garis BTC (Bitcoin Orange)
|
| 521 |
ax_line.plot(df_merged["date"], df_merged["log_return"], label="BTC Log Return", color="#F7931A", linewidth=3, linestyle="-")
|
| 522 |
|
| 523 |
+
# Palet warna baru menyesuaikan ilustrasi (Ungu tua, Hijau terang, Pink salem, Biru toska, Indigo)
|
| 524 |
+
colors = ["#4F46E5", "#10B981", "#F472B6", "#14B8A6", "#6366F1"]
|
| 525 |
for idx, method in enumerate(["vader", "textblob", "roberta", "roberta_large", "bertweet"]):
|
| 526 |
ax_line.plot(df_merged["date"], df_merged[method], label=f"Sentiment: {method.upper()}", color=colors[idx], linewidth=1.5, linestyle="--", alpha=0.8)
|
| 527 |
|
| 528 |
+
ax_line.set_title("Pergerakan Rata-Rata Sentimen Harian Terhadap Volatilitas Harga Bitcoin", color="#111827", fontsize=14, pad=15, fontweight='bold')
|
| 529 |
+
ax_line.set_xlabel("Tanggal", color="#4b5563", fontsize=11)
|
| 530 |
+
ax_line.set_ylabel("Nilai (Value)", color="#4b5563", fontsize=11)
|
| 531 |
+
ax_line.legend(loc='upper left', bbox_to_anchor=(1, 1), frameon=True, facecolor='white', edgecolor='#e5e7eb')
|
| 532 |
plt.tight_layout()
|
| 533 |
st.pyplot(fig_line)
|
| 534 |
|
|
|
|
| 544 |
for idx, method in enumerate(models_list):
|
| 545 |
with cols[idx % 3]:
|
| 546 |
fig_scatter, ax_scatter = plt.subplots(figsize=(5, 4))
|
| 547 |
+
# Menggunakan warna Ungu Gelap (dari ilustrasi celana/tombol) dan Oranye Terang (garis)
|
| 548 |
sns.regplot(data=df_merged, x=method, y="log_return", ax=ax_scatter,
|
| 549 |
+
scatter_kws={"s": 50, "color": "#4F46E5", "alpha": 0.6},
|
| 550 |
+
line_kws={"color": "#F7931A", "linewidth": 2.5})
|
| 551 |
+
ax_scatter.set_title(f"{method.upper()} vs Log Return", color="#111827", fontweight='bold')
|
| 552 |
+
ax_scatter.set_xlabel("Skor Sentimen", color="#4b5563")
|
| 553 |
+
ax_scatter.set_ylabel("Log Return", color="#4b5563")
|
| 554 |
plt.tight_layout()
|
| 555 |
st.pyplot(fig_scatter)
|
| 556 |
|
| 557 |
with st.expander("π Panduan Membaca Grafik"):
|
| 558 |
st.write("- **Garis Orange (Trendline):** Menunjukkan arah korelasi (Naik = Positif, Turun = Negatif).")
|
| 559 |
+
st.write("- **Titik Ungu:** Sebaran data, semakin merapat ke garis orange berarti korelasi semakin kuat.")
|
| 560 |
|
| 561 |
# ==============================
|
| 562 |
# KESIMPULAN & PEMBAHASAN AKHIR
|