r/learnmachinelearning • • Nov 03 '26

I build xgboost for regression from scratch

Finally, after 5 days, XGBoost for regression is complete. Sklearnโ€™s XGBoost is still faster than mine, but the accuracy for both is almost the same. Itโ€™s Day 54 of Building Machine Learning Algorithms from Scratch.

379 Upvotes

44 comments sorted by

80

u/Sherwith2per Nov 03 '26

I'm genuinely sorry for writing ML enthusiast on my LinkedIn (how many years have you been doing ML?)

45

u/not-okarun Nov 03 '26

๐Ÿ˜‚ It's been 2 years since I started programming, but I have been learning ML for almost 2 months

27

u/Sherwith2per Nov 03 '26

There are levels to this ๐Ÿ™Œ๐Ÿป๐Ÿ˜ญ

23

u/AdministrativeTwo488 29d ago

Nevermind the other mean people man. Congrats! I remember my first model. Hidden markov model. I thought it would be difficult (and it was) but once you understand the math its easy. I love creating from scratch than using pre existing lib for academic purposes. Yk you can create your own customized lib if you write this in c++ and package it.

4

u/not-okarun 29d ago

i can use c++ builded library in python ? but I use Google colab for coding python

4

u/AdministrativeTwo488 29d ago

You write this particular xgboost code in c++. For performance. Then compile it and use a python binder to act as translator. Im not that proficient in this part unfortunately. But i do know that is how the current libs work. Ive long pivoted from heavy coding so anyone more knowledgeable could be of help. I could try researching too

2

u/Old_Cake5901 29d ago

Yeah, or if you do it in Rust, pyo3 essentially does everything for you

17

u/not-okarun 29d ago • Bravo

Well I don't care what people think I don't need praise or validation I just post to connect with people like me and build a network of people who are obsessed with coding, not just vibe coding don't get me wrong vibe coding is not a bad I'm not against it at all but tbh I love building things on my own. It's fun to build things I have completed so many algorithms and each one gets more complex than the previous one when I build something with my own hands understand things so closely to mathematics behind them I know why each thing exists and why it works the way it does many people say why are you building everything from scratch? import libraries there's no use

I'm just curious I'm trying to find answers to my own questions

One day, I was using ChatGPT and wondered how the heck did humans create something like this It's like magic and after doing a little research i realised it's not magic. It's mathematics under the hood that's the point where I started my journey in machine learning and when I started learning ML I had already made up my mind that I would build every algorithm from scratch And I'm doing it check my GitHub. I've built everything from scratch up to XGBoost regression tbh my implementations are not always optimised they're not the fastest the code structure isn't perfect and there are still bugs. but I feel proud because I built them myself ngl i do use AI sometime to fix one or two things but the rest is completely my own work sometimes building a single algorithm takes weeks even when I know all the theory figuring out where to start implementing it is a whole different challenge I try different approaches run errors, fix it, try again and repeat the same thing and somewhere along the way, I start figuring things out myself Like Oh, I got it it like this and all that's how I build things brick by brick i just want to make sure my foundation is strong enough before moving to deep learning and AI i'm not doing this to prove anything to anyone. I'm doing it because I'm genuinely curious about how things work and I love the process of figuring them out myself

It's like a journey I'm on the journey to find the answer and I don't use to post things but now I do it's like a diary, a record so ppl can see it. sometimes my post take a long because im watching one piece currently on 193ep no spoilers ๐Ÿคง

Thx for seeing my post where the grammar is broken it's because in school instead of understanding the grammar I used to read the sentence 3-4 times and which sound correct that's the answer ๐Ÿ˜ฎโ€๐Ÿ’จ. ma'am was right

2

u/Fluffy_white_fox 25d ago

Did you make it in your phone? My g collab browser rarely behaves normal for me to write anything on the phone version... How are you even doing it???

1

u/not-okarun 25d ago

idk but it works well and smooth but sometime lag

17

u/addictzz 29d ago

I really appreciate your effort for this. The work needed to understand the math and codify it is no small feat, especially if you don't use LLM to do all these.

I am learning to do the same with LLM help for transformer-based neural network.

9

u/XamanekMtz 29d ago

Building from scratch is a great exercise to learn many of the hows and whys, specially if you are more sided to the coding skills, nice job

15

u/ConsiderationNew3273 Nov 03 '26

How do we get started doing this type of thing?

21

u/pugs_daily_dose Nov 03 '26

A manageable route is to implement a small regression tree first (try candidate splits and minimize squared error), then build gradient boosting by fitting successive trees to residuals. Compare predictions against a library on a tiny fixed dataset before adding regularization and second-order gradients. Small examples where you can calculate a split by hand make debugging much easier.

5

u/Historical-Reach8587 29d ago

Nice job and post.
Have to say there are some real jerks posts in here. Some of you people must truly be miserable humans.

2

u/CSGOingInsane 29d ago

So true, itโ€™s honestly pathetic.

1

u/Natsuo_Subaru 26d ago

Actually, what's that?

1

u/not-okarun 25d ago

xgboost an machine learning algorithm

2

u/burntoutdev8291 29d ago

Nice! I remember taking a while to understand gini haha

2

u/jenalimor1 28d ago

Awesome!

2

u/Nikhilodeon1 26d ago

on a phone top bruh ๐Ÿ˜ญ๐Ÿ˜ญ

2

u/imjerusalem 26d ago

Thanks. I can goon to ts now.

1

u/shadowemperor01 25d ago

Wtf ๐Ÿ˜‚

2

u/Fickle-Tradition2107 25d ago

Hi what is your IQ to be able to do this?

2

u/BenGiii888 18d ago

It's awesome dude congrats! Yeah we do use packages but this still still shows you how they work under the hood so its definitely great!

0

u/[deleted] 29d ago

[deleted] โ€” view deleted comment

2

u/not-okarun 29d ago

ur right I also notice the delays in output compared with Sklearn's

13

u/[deleted] Nov 03 '26

[removed] โ€” view removed comment

15

u/CosmicModel 29d ago • Heartwarming

Because by implementing the algorithm in code it demonstrates you know what is going on under the hood. I think that's valuable. I appreciate seeing posts like this because hopefully it encourages others to learn by doing the same.

12

u/mimivirus2 29d ago edited 29d ago • Heartwarming

Hostile much? Have u checked the name of the subreddit? I get not being interested in the post for any reason, but u can just scroll a few millimeters down and... move on. Lots of ppl might not have an immediate social network that they can share sth like this with. According to u, they should just shut up.

47

u/pm_me_your_smth 29d ago

Some people post about their learning progression here like it's a personal diary. No idea what's the point of doing this

16

u/CSGOingInsane 29d ago

Because itโ€™s the subreddit for learn machine learning???

-1

u/RealSataan 29d ago

Why not? It's better to learn in public. You get instant feedback

3

u/Obvious-Profit-5597 29d ago

Why? Implementation of any algorithm from basic is good exercise to learn it.

1

u/[deleted] 29d ago

[removed] โ€” view removed comment

2

u/Obvious-Profit-5597 29d ago

Oh that's the problem