import pandas as pd from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import train_test_split import joblib # Load the data CSV data = pd.read_csv("creditcard.csv") # Features and target X = data.drop(columns=["Class"]) y = data["Class"] # Split into train and test sets (optional, good practice) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) # Train model model = RandomForestClassifier(n_estimators=100, random_state=42) model.fit(X_train, y_train) # Save the model to a file joblib.dump(model, "fraud_detector.pkl") print("Model training complete and saved as fraud_detector.pkl")