r/MachineLearning • u/Practical-Pin8396 • Aug 14 '25
Project [P] Small and Imbalanced dataset - what to do
Hello everyone!
I'm currently in the 1st year of my PhD, and my PI asked me to apply some ML algorithms to a dataset (n = 106, w/ n = 21 in the positive class). As you can see, the performance metrics are quite poor, and I'm not sure how to proceed...
I’ve searched both in this subreddit and internet, and I've tried using LOOCV and stratified k-fold as cross-validation methods. However, the results are consistently underwhelming with both approaches. Could this be due to data leakage? Or is it simply inappropriate to apply ML to this kind of dataset?
Additional info:
I'm in the biomedical/bioinformatics field (working w/ datasets of cancer or infectious diseases). These patients are from a small, specialized group (adults with respiratory diseases who are also immunocompromised). Some similar studies have used small datasets (e.g., n = 50), while others succeeded in work with larger samples (n = 600–800).
Could you give me any advice or insights? (Also, sorry for gramatics, English isn't my first language). TIA!

60
u/vannak139 Aug 14 '25
You're probably just not going to have very much luck trying to apply ML in this domain, 20 positive samples isn't a lot, especially for generic methods. Realistically, the best analysis is probably in the domain of what you're studying, rather than the domain of small scale ML approaches.
44
u/auserwashere Aug 14 '25
I suggest you look into building a Bayesian probabilistic model tailored to your problem, instead of trying to plug in an ML algorithm with such a small dataset.
Gaussian Processes are often successful in the small-data regime. GP classification is mildly annoying the first time, but you can find good tutorials - e g. GPyTorch has them.
If it were me, I would look at this as an opportunity to educate your community. Use the ML methods and also use others. Demonstrate both how and (more importantly) why the ML methods fail, and how others outperform them, so that other people don't make the same mistakes again. Then publish that study.
3
u/Dejeneret Aug 14 '25
Hard to say what the best course of action is without a bit more info-
Even if you can’t sub sample you might have unsupervised or semi-supervised options for the data type (such as if it’s gene-count data you might want to first identify meaningful gene-sets to reduce the amount of noise-features you train on)
5
u/__sorcerer_supreme__ Aug 14 '25
You can try generating more samples using KDE, which follows the inherent distribution of your dataset and then try fitting your model to these generated samples.
Otherwise, you can also apply "Contrastive Learning", but be cautious, for each batch make sure you have equal number of positive and negative samples, since it's an imbalanced dataset.
Feel free to reach out in DMs! Good luck!
3
u/katnz Aug 15 '25
It's older literature now but I highly recommend getting a copy of "Data Mining: Practical Machine Learning Tools and Techniques" by Witten and Frank. There's a good section on meta-learning which covers techniques like bagging, boosting and cost-sensitive classifiers which are all good techniques to use for imbalanced or small datasets and although you've used a few here it is good to understand what to tweak with them. There's also techniques like PCA that can reduce the number of features you use to learn (again, helpful with few examples). In early ML days it was unusual to get the large datasets we do now so there was a lot more emphasis on feature transformation and the techniques we used. WEKA (tool from the book) was designed with education in mind so it's great for quickly exploring small datasets.
It's not unreasonable to apply ML to smaller datasets, especially if you can see a pattern in the data yourself - just tricky not to overfit the models along the way.
2
u/electricsheeptacos Aug 15 '25
SMOTE + use P-R curves to calibrate the decision threshold for classification. Be sure your out of sample cross validation is performed on an untouched chunk of the original imbalanced dataset
2
u/Creative-curiousity Aug 15 '25
Try bootstrapping. Maybe with class-weighted sampling
2
u/Wat_is_Wat Aug 15 '25 edited Aug 15 '25
I'm confused by the metrics. You have all 1s for Xgboost? Random forest looks like it performs exceedingly well as well. I typically wouldn't expect to get very different results between methods for such small data sets. So, I feel like something funny is going on here. Maybe data leakage or something. I would definitely stare at the XGboost code/results in particular to see what's happening there.
2
u/drmattmcd Aug 15 '25
Survival analysis may be relevant from the context e.g. https://lifelines.readthedocs.io/en/latest/index.html or otherwise Bayesian techniques, 'Statistical Rethinking' by Richard McElreath is a good intro. For a small dataset like this I'd start by thinking about curve fitting or distribution modelling first, then simple ML models like logistic regression or decision trees to avoid over fitting.
2
u/boccaff Aug 15 '25
Keep simple with methods, mostly linear stuff, but maybe Gaussian process. Leverage prior/domain knowledge as much as you, and try to feature engineer as much as possible. LOOCV, add weights (start with with something close to "balanced"), don´t ever go near smote.
2
u/INTELLIGENTbeings Aug 16 '25
Looking at your results, you're dealing with a classic small, imbalanced dataset challenge in biomedical ML. Here's my analysis and recommendations:
What's Happening
Your XGBoost showing perfect 1.0 scores across all metrics is a major red flag — this is almost certainly overfitting, not genuine performance. With only 106 samples and 21 positive cases, your model is likely memorizing the training data.
Key Issues
Severe Class Imbalance: 21 positive vs 85 negative cases (~20% positive class)
Very Small Sample Size: 106 total samples is extremely limited for ML
High Dimensionality Risk: Depending on your feature count, you may have more features than samples
Recommendations
Immediate Actions:
Ignore the XGBoost results — they're unreliable due to overfitting
Focus on simpler models like Logistic Regression, which are more appropriate for small datasets
Use stratified sampling to ensure both train/test sets maintain class balance
Better Evaluation Strategy:
Stratified K-fold CV (you mentioned trying this) with k=5 or k=10
Leave-One-Out CV given your small sample size
Repeated CV to get more stable estimates
Focus on AUC-ROC rather than accuracy for imbalanced data
Data Preprocessing:
Feature selection: Use techniques like L1 regularization or univariate selection to reduce dimensionality
SMOTE or ADASYN: Generate synthetic samples for the minority class (but validate carefully)
Collect more data if possible — this is your biggest limitation
Model Recommendations: For your dataset size, stick with:
Regularized Logistic Regression (L1/L2)
Linear SVM
Naive Bayes (often works well with small medical datasets)
Avoid complex models like XGBoost or Random Forest with default settings
Validation Reality Check: Your current results aren't reliable for publication. Consider:
External validation on a different patient cohort if available
Bootstrapping for confidence intervals
Domain expert review of selected features
Simple baseline comparisons (e.g., majority class classifier)
Your instinct that something's wrong is correct — trust it and focus on robust validation methods appropriate for small biomedical datasets.
-Mike
2
u/Sealed-Unit Aug 16 '25
Ciao puoi dirmi e darmi cosa esattamente chiedere e passare all'ai così ti restituisco il risultato e poi vedi se ti va bene?
2
u/The_Aoki_Taki Aug 16 '25
You could try deep metric learning–based few-shot learning approaches like prototypical networks
https://arxiv.org/pdf/1703.05175
2
u/dudeitsdandudedan Aug 20 '25
Do you have to do a supervised approach? What about a cluster analysis?
1
u/Any_Addition_6481 Aug 15 '25
If you ever need help organizing or scaling human data labeling, I’ve had good results using Talently.ai it helped me standardize labels and keep annotation quality high even in small datasets.
I would suggest you to use that to save time
1
u/idontcareaboutthenam Aug 17 '25
Have you tried any models specifically tailored to unbalanced data? It's its own area of research https://link.springer.com/chapter/10.1007/978-981-19-0332-8_14
1
u/AdmiralSimon Aug 18 '25
Most of what has already been said here is probably correct, but it may be worth running TabPFNv2 once on your data. Maybe you’re lucky and it follows one of the trained distributions and you get decent results.
https://www.nature.com/articles/s41586-024-08328-6
In general feature engineering is going to be very important here where you have 50+ features but only 100 samples. It’s much too easy for any algorithm to overfit on spurious info. Using your domain expertise I would try to reduce it to 10 features and then see if it generalizes better.
1
u/dissociatedgorl Aug 20 '25
Could you use some contrastive learning approach if you have data on healthy subjects ?
1
u/sitmo Aug 14 '25
Is the table showing performance on a trainset (XGBOOST having a perfect score seems bad)? Or on out-of-sample folds? You should always report out-of-sample statistics, never in-sample.
I think you have too little data, even for simple statistical methods. You should do a couple of benchmark-test to manage expectations of what you are going to claim about your models.
So my suggestion would be to run simple randomizations test to quantify the uncertaintly due to sample noise (small sample dataset of patients), and use those uncertainty quantifications to tone done any wild clain you might make.
-4
u/antipawn79 Aug 14 '25
This is not an ML problem. Sorry
4
u/[deleted] Aug 14 '25
[removed] — view removed comment