Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,32 @@
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
# Gradio Arayüzü Fonksiyonu
|
| 4 |
def fraud_detection(accountAgeDays, numItems, localTime, paymentMethod, paymentMethodAgeDays):
|
|
@@ -31,8 +59,8 @@ def fraud_detection(accountAgeDays, numItems, localTime, paymentMethod, paymentM
|
|
| 31 |
rf_prediction = rf_model.predict(input_data)[0]
|
| 32 |
|
| 33 |
# Sonuçları formatlama
|
| 34 |
-
logreg_result = "
|
| 35 |
-
rf_result = "
|
| 36 |
|
| 37 |
return f"Logistic Regression: {logreg_result}\nRandom Forest: {rf_result}"
|
| 38 |
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import joblib
|
| 3 |
import gradio as gr
|
| 4 |
+
from sklearn.preprocessing import OneHotEncoder
|
| 5 |
+
from sklearn.impute import SimpleImputer
|
| 6 |
+
|
| 7 |
+
# Modeli, encoder'ı ve imputer'ı yükleme
|
| 8 |
+
logreg_model = joblib.load('logreg_model.pkl')
|
| 9 |
+
rf_model = joblib.load('rf_model.pkl')
|
| 10 |
+
encoder = joblib.load('encoder.pkl')
|
| 11 |
+
imputer = joblib.load('imputer.pkl')
|
| 12 |
+
|
| 13 |
+
# Veri setini yükleme ve ön işleme fonksiyonu
|
| 14 |
+
def load_and_preprocess(csv_file_path):
|
| 15 |
+
df = pd.read_csv(csv_file_path)
|
| 16 |
+
df.fillna({"paymentMethod": "UNKNOWN"}, inplace=True)
|
| 17 |
+
df["paymentMethod"] = df["paymentMethod"].map({
|
| 18 |
+
"creditcard": 1,
|
| 19 |
+
"paypal": 2,
|
| 20 |
+
"storecredit": 3,
|
| 21 |
+
"UNKNOWN": 0
|
| 22 |
+
})
|
| 23 |
+
return df
|
| 24 |
+
|
| 25 |
+
# payment_fraud.csv dosyasını yükle
|
| 26 |
+
data = load_and_preprocess("payment_fraud.csv")
|
| 27 |
+
|
| 28 |
+
# Kategorik sütunları tanımla
|
| 29 |
+
categorical_cols = ['paymentMethod']
|
| 30 |
|
| 31 |
# Gradio Arayüzü Fonksiyonu
|
| 32 |
def fraud_detection(accountAgeDays, numItems, localTime, paymentMethod, paymentMethodAgeDays):
|
|
|
|
| 59 |
rf_prediction = rf_model.predict(input_data)[0]
|
| 60 |
|
| 61 |
# Sonuçları formatlama
|
| 62 |
+
logreg_result = "Sahtekarlık Değil" if logreg_prediction == 0 else "Sahtekarlık"
|
| 63 |
+
rf_result = "Sahtekarlık Değil" if rf_prediction == 0 else "Sahtekarlık"
|
| 64 |
|
| 65 |
return f"Logistic Regression: {logreg_result}\nRandom Forest: {rf_result}"
|
| 66 |
|