Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import pandas as pd | |
| from pycaret.classification import setup, compare_models, pull | |
| # Sütunları ve veri setini alma fonksiyonu | |
| def get_columns(dosya): | |
| if dosya is None: | |
| return gr.update(choices=[]), gr.update(choices=[]), gr.update(choices=[]), pd.DataFrame() | |
| data = pd.read_csv(dosya.name) | |
| kolonlar = data.columns.tolist() | |
| return ( | |
| gr.update(choices=kolonlar), # Hedef sütun seçenekleri | |
| gr.update(choices=kolonlar), # Sayısal sütunlar | |
| gr.update(choices=kolonlar), # Kategorik sütunlar | |
| data.head() # Veri seti ön izlemesi | |
| ) | |
| # Otomatik modelleme fonksiyonu | |
| def otoml_islemi(dosya, hedef_sutun, sayisal_sutunlar, kategorik_sutunlar, | |
| sayisal_imputasyon, kategorik_imputasyon, normalize, remove_outliers, ignore_sutunlar): | |
| # Veri setini yükleyin | |
| data = pd.read_csv(dosya.name) | |
| # PyCaret kurulumunu başlatın | |
| s = setup( | |
| data, | |
| target=hedef_sutun, | |
| numeric_features=sayisal_sutunlar if sayisal_sutunlar else None, | |
| categorical_features=kategorik_sutunlar if kategorik_sutunlar else None, | |
| ignore_features=ignore_sutunlar if ignore_sutunlar else None, | |
| numeric_imputation=sayisal_imputasyon, | |
| categorical_imputation=kategorik_imputasyon, | |
| normalize=normalize, | |
| remove_outliers=remove_outliers, | |
| ) | |
| # Modelleri karşılaştırın ve en iyisini seçin | |
| en_iyi_model = compare_models() | |
| # Model değerlendirme sonuçlarını alın | |
| degerlendirme = pull() | |
| return degerlendirme | |
| # Gradio arayüzü | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# PyCaret ile AutoML Arayüzü") | |
| with gr.Row(): | |
| dosya = gr.File(label="Veri Seti (CSV)") | |
| with gr.Row(): | |
| hedef_sutun = gr.Dropdown(label="Hedef Sütun Adı", choices=[]) | |
| with gr.Row(): | |
| sayisal_sutunlar = gr.CheckboxGroup(label="Sayısal Sütunlar", choices=[]) | |
| kategorik_sutunlar = gr.CheckboxGroup(label="Kategorik Sütunlar", choices=[]) | |
| ignore_sutunlar = gr.CheckboxGroup(label="Görmezden Gelinecek Sütunlar", choices=[]) | |
| with gr.Row(): | |
| sayisal_imputasyon = gr.Dropdown(choices=['mean', 'median', 'zero'], label="Sayısal İmputasyon Yöntemi", value='mean') | |
| kategorik_imputasyon = gr.Dropdown(choices=['mode', 'constant'], label="Kategorik İmputasyon Yöntemi", value='mode') | |
| with gr.Row(): | |
| normalize = gr.Checkbox(label="Normalize Et", value=False) | |
| remove_outliers = gr.Checkbox(label="Aykırı Değerleri Kaldır", value=False) | |
| buton = gr.Button("Otomatik Modelleme Başlat") | |
| output = gr.Dataframe(label="Model Değerlendirme Sonuçları") | |
| preview = gr.Dataframe(label="Veri Seti Ön İzlemesi") | |
| # Dosya yüklendiğinde sütunları ve veri setini al | |
| dosya.change( | |
| fn=get_columns, | |
| inputs=dosya, | |
| outputs=[hedef_sutun, sayisal_sutunlar, kategorik_sutunlar, preview] | |
| ) | |
| # Modelleme butonuna tıklandığında işlemi başlat | |
| buton.click( | |
| fn=otoml_islemi, | |
| inputs=[dosya, hedef_sutun, sayisal_sutunlar, kategorik_sutunlar, | |
| sayisal_imputasyon, kategorik_imputasyon, normalize, remove_outliers, ignore_sutunlar], | |
| outputs=output | |
| ) | |
| demo.launch(share=True) | |