Views
No views yet
random_state=42, use_label_encoder=False, eval_metric='logloss', colsample_bytree=0.8, learning_rate=0.01, max_depth=5, n_estimators=100, scale_pos_weight=1, subsample=0.8.| Metric | Value |
|---|---|
| Testing Accuracy | 85.2% |
| Testing Weighted Average Precision | 87% |
| Testing Weighted Average Recall | 85% |
| Testing Weighted Average F1 | 85% |
| Testing ROC-AUC | 82.5% |
1import random
2
3def test_random_samples(model, X_test, y_test, n_samples=5):
4 """
5 Selects random samples from the test set, makes predictions, and compares with actual values.
6
7 Parameters:
8 - model: Trained XGBoost classifier.
9 - X_test: Feature set for testing.
10 - y_test: True labels for testing.
11 - n_samples: Number of random samples to test.
12
13 Returns:
14 None
15 """
16 # Convert X_test and y_test to DataFrame for easier indexing
17 X_test_df = X_test.reset_index(drop=True)
18 y_test_df = y_test.reset_index(drop=True)
19
20 # Pick random indices
21 random_indices = random.sample(range(len(X_test)), n_samples)
22
23 print("Testing on Random Samples:")
24 for idx in random_indices:
25 sample = X_test_df.iloc[idx]
26 true_label = y_test_df.iloc[idx]
27
28 # Predict using the model
29 prediction = model.predict(sample.values.reshape(1, -1))
30
31 # Output results
32 print(f"Sample Index: {idx}")
33 print(f"Features: {sample.values}")
34 print(f"True Label: {true_label}, Predicted Label: {prediction[0]}")
35 print("-" * 40)
36
37# Example usage
38test_random_samples(xgb, X_test, y_test)