ESMATUGBA's picture
Upload 2 files
52d46ea verified
Raw
History Blame Contribute Delete
3.63 kB
import streamlit as st
import pandas as pd
import joblib
# =========================
# PAGE CONFIG / SAYFA AYARLARI
# =========================
st.set_page_config(page_title="Diamond Predictor", page_icon="💎", layout="wide")
# =========================
# LOAD MODEL / MODELİ YÜKLE
# =========================
@st.cache_resource
def load_model():
# Model dosyasının adını kontrol et / Check model filename
model = joblib.load('diamond_catboost_model.pkl')
return model
model = load_model()
# =========================
# HEADER / BAŞLIK
# =========================
st.title("💎 Diamond Price Prediction App")
st.subheader("TR: Elmas Fiyat Tahmini Uygulaması | EN: Diamond Price Prediction Tool")
st.write("---")
# =========================
# SIDEBAR - INPUTS / YAN PANEL - GİRDİLER
# =========================
st.sidebar.header("🔧 Input Features / Girdi Özellikleri")
def get_user_inputs():
carat = st.sidebar.number_input("Carat (Ağırlık)", 0.2, 5.0, 1.0, step=0.01)
cut = st.sidebar.selectbox("Cut (Kesim)",
["Ideal", "Premium", "Very Good", "Good", "Fair"])
color = st.sidebar.selectbox("Color (Renk)",
["D", "E", "F", "G", "H", "I", "J"])
clarity = st.sidebar.selectbox("Clarity (Berraklık)",
["IF", "VVS1", "VVS2", "VS1", "VS2", "SI1", "SI2", "I1"])
depth = st.sidebar.slider("Depth (%)", 43.0, 79.0, 61.0)
table = st.sidebar.slider("Table Width (%)", 43.0, 95.0, 57.0)
col1, col2, col3 = st.sidebar.columns(3)
x = col1.number_input("X (mm)", 0.0, 11.0, 5.0)
y = col2.number_input("Y (mm)", 0.0, 58.0, 5.0)
z = col3.number_input("Z (mm)", 0.0, 31.0, 3.0)
data = {
'carat': carat, 'cut': cut, 'color': color, 'clarity': clarity,
'depth': depth, 'table': table, 'x': x, 'y': y, 'z': z
}
return pd.DataFrame([data])
input_df = get_user_inputs()
# =========================
# MAIN DISPLAY / ANA EKRAN
# =========================
col_main1, col_main2 = st.columns([1, 1])
with col_main1:
st.markdown("### 📋 Selected Features / Seçilen Özellikler")
st.dataframe(input_df, use_container_width=True)
# =========================
# PREPROCESSING / VERİ ÖN İŞLEME
# =========================
# Create dummy variables
input_encoded = pd.get_dummies(input_df)
# Fix 'carat_group_mid' if missing (Modelin beklediği o özel sütun)
if "carat_group_mid" in model.feature_names_:
input_encoded["carat_group_mid"] = input_df["carat"].iloc[0]
# Align with model features (Modelin beklediği sütun sırasına sok)
final_df = input_encoded.reindex(columns=model.feature_names_, fill_value=0)
# =========================
# PREDICTION / TAHMİN
# =========================
with col_main2:
st.markdown("### 🎯 Prediction / Tahmin")
if st.button("Predict Price / Fiyatı Tahmin Et"):
prediction = model.predict(final_df)[0]
st.balloons()
st.success(f"💰 Estimated Price / Tahmini Fiyat: **${prediction:,.2f}**")
# Additional Info / Ek Bilgi
st.info("""
**EN:** This prediction is based on the CatBoost model with 98% accuracy.
**TR:** Bu tahmin, %98 doğruluk oranına sahip CatBoost modeli tarafından yapılmıştır.
""")
# =========================
# FOOTER / ALT BİLGİ
# =========================
st.write("---")
st.caption("Created by Esma | Diamond Price Prediction Project")