Spaces:
Build error
Build error
File size: 492 Bytes
e42d338 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
import joblib
# Load dataset
df = pd.read_csv("creditcard.csv")
# Features and target
X = df.drop("Class", axis=1)
y = df["Class"]
# Train/test split
X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, random_state=42)
# Train model
model = RandomForestClassifier()
model.fit(X_train, y_train)
# Save model
joblib.dump(model, "fraud_model.pkl") |