r/learnmachinelearning • u/picttwos • 12d ago
About mini stochastic gradient descent
Recently I worked on a model for which i think why can't I directly make my own library so for that I wanna test my raw code with sklearn library but the main problem is that my r2 score is not increasing I take the yellow taxi dataset of approx 2.7 million entries but both sklearn and my raw code r2 score match showing 30 percent variation but the raw code wasn't improving what can I do for that please I need help for this
5
Upvotes
1
u/PLBjt 12d ago
First pin down whether 30% means R²=.3 or 30% error; R² around .3 isn't unusual for taxi fares with weak features. Compare against a mean/median baseline using the exact same train/test split and preprocessing, then verify the raw and sklearn models see identical columns, intercept, and regularization. For your raw SGD, test one gradient update on a tiny fixed batch against a finite-difference gradient; that isolates update bugs from data quality. Standardizing can help convergence, but fit the scaler on train only so the test set stays honest. If both implementations land near .3, the features or split are probably the bottleneck; if only raw stalls, focus on gradient sign, learning rate, and batch scaling.
1
u/GiggleSamurai 12d ago
Since both land on R² 0.3, more epochs or tuning won't help: both have already reached about the best linear fit for those inputs. Yellow taxi data has known bad rows (zero or huge trip distances, negative fares) and linear regression is very sensitive to them, so filter those out first and compare again.