Spaces:
Runtime error
Runtime error
Download train_model.py from FuurythumbsCPT/Fraud_detection_system_3.0: direct link, hf CLI and curl.
- Browser
- Download file 684 Bytes
-
https://huggingface.co/spaces/FuurythumbsCPT/Fraud_detection_system_3.0/resolve/main/train_model.py
- Command line
-
hf download hf://spaces/FuurythumbsCPT/Fraud_detection_system_3.0/train_model.py
-
curl -L -o train_model.py https://huggingface.co/spaces/FuurythumbsCPT/Fraud_detection_system_3.0/resolve/main/train_model.py
684 Bytes
| 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") |