import numpy as np 
import pandas as pd 
from sklearn.model_selection import train_test_split 
from sklearn.linear_model import LogisticRegression 
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score, confusion_matrix 
 
# Create a highly imbalanced dataset 
# 720 samples of class 0 (e.g., "not fraud") and 280 of class 1 ("fraud") 
X = np.random.rand(1000, 10) 
y = np.zeros(1000)  
y[:280] = 1  # 280 positive samples 
 
# Split data 
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) 
 
# Train a simple classifier 
model = LogisticRegression(solver='liblinear') 
model.fit(X_train, y_train) 
 
# Make predictions on the test set 
y_pred = model.predict(X_test) 
 
# Calculate and print the metrics 
print("Model Evaluation Metrics ---") 
print(f"Accuracy: {accuracy_score(y_test, y_pred):.2f}") 
print(f"Precision: {precision_score(y_test, y_pred, zero_division=0):.2f}") 
print(f"Recall: {recall_score(y_test, y_pred, zero_division=0):.2f}") 
print(f"F1-Score: {f1_score(y_test, y_pred, zero_division=0):.2f}") 
 
# Print the confusion matrix 
print("\nConfusion Matrix ---") 
cm = confusion_matrix(y_test, y_pred) 
print(cm) 
 
# Get the components from the confusion matrix 
tn, fp, fn, tp = cm.ravel() 

print(f"\nTP (True Positives): {tp}") 
print(f"FP (False Positives): {fp}") 
print(f"FN (False Negatives): {fn}") 
print(f"TN (True Negatives): {tn}") 