Upload 2 files
Browse files- app.py +113 -0
- bankruptcy_model.pkl +3 -0
app.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import joblib
|
| 4 |
+
|
| 5 |
+
# --- SAYFA AYARLARI ---
|
| 6 |
+
st.set_page_config(page_title="Corporate Bankruptcy AI Analysis", layout="wide")
|
| 7 |
+
|
| 8 |
+
# --- MODEL YÜKLEME ---
|
| 9 |
+
@st.cache_resource
|
| 10 |
+
def load_model():
|
| 11 |
+
data_yuklenen = joblib.load('bankruptcy_model.pkl')
|
| 12 |
+
return data_yuklenen["model"], data_yuklenen["columns"]
|
| 13 |
+
|
| 14 |
+
model, columns = load_model()
|
| 15 |
+
feature_columns = [c for c in columns if c != 'Bankrupt?']
|
| 16 |
+
|
| 17 |
+
# --- TÜRKÇE KARŞILIKLAR ---
|
| 18 |
+
translation_map = {
|
| 19 |
+
"Net Income to Stockholder's Equity": "Özsermaye Karlılığı",
|
| 20 |
+
"Net Income to Total Assets": "Varlık Karlılığı",
|
| 21 |
+
"Borrowing dependency": "Borç Bağımlılığı",
|
| 22 |
+
"ROA(A) before interest and % after tax": "Varlık Getirisi (A) Vergi Sonrası",
|
| 23 |
+
"ROA(B) before interest and depreciation after tax": "Varlık Getirisi (B) Amortisman Sonrası",
|
| 24 |
+
"ROA(C) before interest and depreciation before interest": "Varlık Getirisi (C) Faiz Öncesi",
|
| 25 |
+
"Liability to Equity": "Borç / Özsermaye Oranı",
|
| 26 |
+
"Total debt/Total net worth": "Toplam Borç / Net Değer",
|
| 27 |
+
"Persistent EPS in the Last Four Seasons": "Süreklilik Arz Eden EPS",
|
| 28 |
+
"Net profit before tax/Paid-in capital": "Net Kâr / Ödenmiş Sermaye",
|
| 29 |
+
"Per Share Net profit before tax (Yuan ¥)": "Hisse Başı Net Kâr",
|
| 30 |
+
"Debt ratio %": "Borçlanma Oranı %",
|
| 31 |
+
"Net worth/Assets": "Net Değer / Varlıklar",
|
| 32 |
+
"Retained Earnings to Total Assets": "Dağıtılmamış Kârlar / Varlıklar",
|
| 33 |
+
"Current Liability to Equity": "Kısa Vadeli Borç / Özsermaye",
|
| 34 |
+
"Current Liabilities/Equity": "Cari Borçlar / Özsermaye",
|
| 35 |
+
"Operating Profit Per Share (Yuan ¥)": "Hisse Başı Faaliyet Kârı",
|
| 36 |
+
"Operating profit/Paid-in capital": "Faaliyet Kârı / Sermaye",
|
| 37 |
+
"Working Capital to Total Assets": "İşletme Sermayesi / Varlıklar",
|
| 38 |
+
"Working Capital/Equity": "İşletme Sermayesi / Özsermaye"
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
# --- SENARYO VERİLERİ (Dinamik Test Verileri) ---
|
| 42 |
+
safe_vals = [0.88, 0.85, 0.12, 0.82, 0.83, 0.84, 0.08, 0.09, 0.85, 0.82, 0.80, 0.15, 0.88, 0.87, 0.07, 0.06, 0.82, 0.81, 0.88, 0.89]
|
| 43 |
+
risky_vals = [0.05, 0.08, 0.92, 0.10, 0.11, 0.09, 0.95, 0.94, 0.02, 0.07, 0.08, 0.90, 0.12, 0.15, 0.96, 0.93, 0.05, 0.04, 0.09, 0.11]
|
| 44 |
+
|
| 45 |
+
# --- SIDEBAR ---
|
| 46 |
+
st.sidebar.title("🏨 Prediction Menu / Tahmin Menüsü")
|
| 47 |
+
if st.sidebar.button("✅ Load Safe Data / Güvenli Veri Yükle"):
|
| 48 |
+
for i, col in enumerate(feature_columns): st.session_state[f"field_{col}"] = safe_vals[i]
|
| 49 |
+
|
| 50 |
+
if st.sidebar.button("⚠️ Load Risky Data / Riskli Veri Yükle"):
|
| 51 |
+
for i, col in enumerate(feature_columns): st.session_state[f"field_{col}"] = risky_vals[i]
|
| 52 |
+
|
| 53 |
+
if st.sidebar.button("🔄 Reset / Verileri Sıfırla"):
|
| 54 |
+
for col in feature_columns: st.session_state[f"field_{col}"] = 0.0
|
| 55 |
+
|
| 56 |
+
st.sidebar.divider()
|
| 57 |
+
with st.sidebar.expander("📚 Glossary / Oran Sözlüğü"):
|
| 58 |
+
for eng, tr in translation_map.items(): st.write(f"**{eng}:** {tr}")
|
| 59 |
+
|
| 60 |
+
# --- ANA PANEL ---
|
| 61 |
+
st.title("Corporate Bankruptcy Prediction System / Kurumsal İflas Tahmin Sistemi")
|
| 62 |
+
st.write("---")
|
| 63 |
+
|
| 64 |
+
# Veri Giriş Alanı (Kapalı Başlar)
|
| 65 |
+
with st.expander("📊 Financial Input Fields (20 Features) / Veri Giriş Alanları", expanded=False):
|
| 66 |
+
col1, col2, col3 = st.columns(3)
|
| 67 |
+
inputs = {}
|
| 68 |
+
for i, col_name in enumerate(feature_columns):
|
| 69 |
+
if f"field_{col_name}" not in st.session_state: st.session_state[f"field_{col_name}"] = 0.0
|
| 70 |
+
label = f"{col_name} ({translation_map.get(col_name, '')})"
|
| 71 |
+
target_col = [col1, col2, col3][i % 3]
|
| 72 |
+
with target_col:
|
| 73 |
+
inputs[col_name] = st.number_input(label, format="%.4f", key=f"field_{col_name}")
|
| 74 |
+
|
| 75 |
+
# Mevcut Veri Tablosu
|
| 76 |
+
df_input = pd.DataFrame(inputs, index=["Value / Değer"])
|
| 77 |
+
st.subheader("📋 Current Data View / Mevcut Veri Tablosu")
|
| 78 |
+
st.dataframe(df_input, use_container_width=True)
|
| 79 |
+
|
| 80 |
+
# --- ANALİZ VE GRAFİK BÖLÜMÜ ---
|
| 81 |
+
if st.button("🚀 RUN STRATEGIC ANALYSIS / ANALİZİ BAŞLAT"):
|
| 82 |
+
prediction = model.predict(df_input)
|
| 83 |
+
prediction_proba = model.predict_proba(df_input)
|
| 84 |
+
|
| 85 |
+
st.divider()
|
| 86 |
+
res_col1, res_col2 = st.columns([1, 1])
|
| 87 |
+
|
| 88 |
+
with res_col1:
|
| 89 |
+
if prediction[0] == 1:
|
| 90 |
+
st.error(f"### ⚠️ RESULT: BANKRUPTCY RISK / İFLAS RİSKİ")
|
| 91 |
+
st.warning(f"Probability Score: %{prediction_proba[0][1]*100:.2f}")
|
| 92 |
+
else:
|
| 93 |
+
st.success(f"### ✅ RESULT: FINANCIALLY HEALTHY / SAĞLIKLI")
|
| 94 |
+
st.info(f"Health Score: %{prediction_proba[0][0]*100:.2f}")
|
| 95 |
+
|
| 96 |
+
with res_col2:
|
| 97 |
+
# GRAFİK EKLEME: Olasılık Dağılım Grafiği
|
| 98 |
+
st.subheader("📊 Probability Analysis / Olasılık Analizi")
|
| 99 |
+
prob_data = pd.DataFrame({
|
| 100 |
+
'Status': ['Healthy / Sağlıklı', 'Bankrupt / İflas'],
|
| 101 |
+
'Percentage (%)': [prediction_proba[0][0]*100, prediction_proba[0][1]*100]
|
| 102 |
+
})
|
| 103 |
+
st.bar_chart(data=prob_data, x='Status', y='Percentage (%)', color="#ff4b4b" if prediction[0] == 1 else "#00cc66")
|
| 104 |
+
|
| 105 |
+
# Alt Kısma Yönetici Özeti
|
| 106 |
+
st.write("---")
|
| 107 |
+
st.subheader("📝 Summary Report / Yönetici Özeti")
|
| 108 |
+
if prediction[0] == 1:
|
| 109 |
+
st.write("The AI model has detected a high correlation between your input variables and known historical bankruptcy patterns. Immediate review of liquidity and debt ratios is advised.")
|
| 110 |
+
else:
|
| 111 |
+
st.write("The company shows strong financial stability. Most ratios are within safe historical boundaries.")
|
| 112 |
+
|
| 113 |
+
st.caption("Strategic AI Model | Accuracy: %88.7 | Bilingual Support")
|
bankruptcy_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5f65fe38e117a28e021d1a4ef10abf70b27bce344af466ac9cace0c1f7aba404
|
| 3 |
+
size 532862
|