ESMATUGBA commited on
Commit
52d46ea
·
verified ·
1 Parent(s): db5ddfa

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +105 -0
  2. diamond_catboost_model.pkl +3 -0
app.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import joblib
4
+
5
+ # =========================
6
+ # PAGE CONFIG / SAYFA AYARLARI
7
+ # =========================
8
+ st.set_page_config(page_title="Diamond Predictor", page_icon="💎", layout="wide")
9
+
10
+ # =========================
11
+ # LOAD MODEL / MODELİ YÜKLE
12
+ # =========================
13
+ @st.cache_resource
14
+ def load_model():
15
+ # Model dosyasının adını kontrol et / Check model filename
16
+ model = joblib.load('diamond_catboost_model.pkl')
17
+ return model
18
+
19
+ model = load_model()
20
+
21
+ # =========================
22
+ # HEADER / BAŞLIK
23
+ # =========================
24
+ st.title("💎 Diamond Price Prediction App")
25
+ st.subheader("TR: Elmas Fiyat Tahmini Uygulaması | EN: Diamond Price Prediction Tool")
26
+ st.write("---")
27
+
28
+ # =========================
29
+ # SIDEBAR - INPUTS / YAN PANEL - GİRDİLER
30
+ # =========================
31
+ st.sidebar.header("🔧 Input Features / Girdi Özellikleri")
32
+
33
+ def get_user_inputs():
34
+ carat = st.sidebar.number_input("Carat (Ağırlık)", 0.2, 5.0, 1.0, step=0.01)
35
+
36
+ cut = st.sidebar.selectbox("Cut (Kesim)",
37
+ ["Ideal", "Premium", "Very Good", "Good", "Fair"])
38
+
39
+ color = st.sidebar.selectbox("Color (Renk)",
40
+ ["D", "E", "F", "G", "H", "I", "J"])
41
+
42
+ clarity = st.sidebar.selectbox("Clarity (Berraklık)",
43
+ ["IF", "VVS1", "VVS2", "VS1", "VS2", "SI1", "SI2", "I1"])
44
+
45
+ depth = st.sidebar.slider("Depth (%)", 43.0, 79.0, 61.0)
46
+ table = st.sidebar.slider("Table Width (%)", 43.0, 95.0, 57.0)
47
+
48
+ col1, col2, col3 = st.sidebar.columns(3)
49
+ x = col1.number_input("X (mm)", 0.0, 11.0, 5.0)
50
+ y = col2.number_input("Y (mm)", 0.0, 58.0, 5.0)
51
+ z = col3.number_input("Z (mm)", 0.0, 31.0, 3.0)
52
+
53
+ data = {
54
+ 'carat': carat, 'cut': cut, 'color': color, 'clarity': clarity,
55
+ 'depth': depth, 'table': table, 'x': x, 'y': y, 'z': z
56
+ }
57
+ return pd.DataFrame([data])
58
+
59
+ input_df = get_user_inputs()
60
+
61
+ # =========================
62
+ # MAIN DISPLAY / ANA EKRAN
63
+ # =========================
64
+ col_main1, col_main2 = st.columns([1, 1])
65
+
66
+ with col_main1:
67
+ st.markdown("### 📋 Selected Features / Seçilen Özellikler")
68
+ st.dataframe(input_df, use_container_width=True)
69
+
70
+ # =========================
71
+ # PREPROCESSING / VERİ ÖN İŞLEME
72
+ # =========================
73
+ # Create dummy variables
74
+ input_encoded = pd.get_dummies(input_df)
75
+
76
+ # Fix 'carat_group_mid' if missing (Modelin beklediği o özel sütun)
77
+ if "carat_group_mid" in model.feature_names_:
78
+ input_encoded["carat_group_mid"] = input_df["carat"].iloc[0]
79
+
80
+ # Align with model features (Modelin beklediği sütun sırasına sok)
81
+ final_df = input_encoded.reindex(columns=model.feature_names_, fill_value=0)
82
+
83
+ # =========================
84
+ # PREDICTION / TAHMİN
85
+ # =========================
86
+ with col_main2:
87
+ st.markdown("### 🎯 Prediction / Tahmin")
88
+
89
+ if st.button("Predict Price / Fiyatı Tahmin Et"):
90
+ prediction = model.predict(final_df)[0]
91
+
92
+ st.balloons()
93
+ st.success(f"💰 Estimated Price / Tahmini Fiyat: **${prediction:,.2f}**")
94
+
95
+ # Additional Info / Ek Bilgi
96
+ st.info("""
97
+ **EN:** This prediction is based on the CatBoost model with 98% accuracy.
98
+ **TR:** Bu tahmin, %98 doğruluk oranına sahip CatBoost modeli tarafından yapılmıştır.
99
+ """)
100
+
101
+ # =========================
102
+ # FOOTER / ALT BİLGİ
103
+ # =========================
104
+ st.write("---")
105
+ st.caption("Created by Esma | Diamond Price Prediction Project")
diamond_catboost_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7780073649e8a401114e3a647ac9de75450592c2bcec2d656d5faa8800e6e60e
3
+ size 1117895