Analysis Results
Results update after calculation and appear above the form.
Class Distribution
Class Weights and Framework Values
Sampling Plan Comparison
Stratified Split Projection
Confusion Matrix Metrics
Recommendations and Leakage Warnings
Visualisations
Generated Machine Learning Code
Formula Used
How to Use
Enter each class name and sample count. You can also paste labels or import a CSV file. Keep class names unique for clear reports.
Choose thresholds, weight rules, and a sampling target. Configure train, validation, and test percentages. Then select your preferred code framework.
Press calculate to review imbalance, weights, sampling plans, split risks, and model guidance. Export results when your analysis is complete.
Example Data
| Class | Sample Count | Expected Percentage |
|---|---|---|
| Normal | 9,500 | 95% |
| Fraud | 500 | 5% |
This dataset has a 19:1 imbalance ratio. Balanced weights are approximately 0.5263 and 10. XGBoost scale_pos_weight equals 19.
Frequently Asked Questions
What is class imbalance?
Class imbalance occurs when labels contain very different sample counts. It can bias learning toward larger classes. Minority performance may remain hidden.
How is imbalance ratio calculated?
Divide the largest class count by the smallest positive class count. A value near one indicates balance. Larger values indicate stronger imbalance.
Is accuracy reliable for imbalanced data?
Accuracy can be misleading when one class dominates. Review recall, precision, balanced accuracy, MCC, and PR-AUC. Always inspect every important class.
Should oversampling happen before splitting?
No. Split the dataset first. Fit resampling only on training folds to prevent leakage.
When should SMOTE be used?
Use SMOTE when numeric minority examples are sufficient and meaningful interpolation is plausible. Validate carefully. Categorical data may require SMOTE-NC.
Can class weights replace resampling?
Sometimes. Weighted losses often work well with tree, linear, and neural models. Compare weighted and resampled pipelines using stratified validation.
Which metric is best?
There is no universal metric. Choose metrics around business costs and minority detection needs. PR-AUC is helpful for rare positives.
How is multiclass imbalance handled?
Inspect each class proportion, macro metrics, pairwise ratios, and class weights. Sampling targets can differ by class. Preserve test realism.
What is scale_pos_weight?
It is commonly calculated as negative samples divided by positive samples. XGBoost uses it to emphasise the positive class during learning.
Can oversampling cause overfitting?
Yes. Random duplication can amplify noise. Synthetic methods can also create unrealistic examples when classes overlap.
How many minority samples are enough?
The answer depends on feature complexity, noise, and validation stability. Very small classes need cautious claims. More representative data is preferable.
Should the test set remain imbalanced?
Usually yes. The test distribution should represent expected deployment conditions. Report per-class results and uncertainty.
What is threshold moving?
Threshold moving changes the probability cutoff used for class decisions. It trades precision against recall. Tune only with validation data.
When is anomaly detection suitable?
Consider anomaly detection when positives are extremely rare or poorly labelled. It is also useful when normal behaviour is much easier to model.
Why use stratified cross-validation?
Stratification preserves class proportions across folds. It reduces unstable evaluation caused by missing minority samples. Group constraints still need separate handling.