YouTube2Text

Gradient Boost Part 1 (of 4): Regression Main Ideas — Transcript

by StatQuest with Josh Starmer · 2,029 words · 378 segments · language en · Watch on YouTube

Full transcript

  1. 0:01Gradient Boost, part one.
  2. 0:04Regression main ideas.
  3. 0:07StatQuest.
  4. 0:10Hello, I'm Josh Starmer and welcome to
  5. 0:13StatQuest. Today, we're going to talk
  6. 0:15about the gradient boost machine
  7. 0:17learning algorithm. Specifically, we're
  8. 0:19going to focus on how gradient boost is
  9. 0:21used for regression.
  10. 0:24Note, this StatQuest assumes you already
  11. 0:27understand decision trees. So, if you're
  12. 0:29not already down with those, check out
  13. 0:32the quest.
  14. 0:33This StatQuest also assumes that you are
  15. 0:36familiar with AdaBoost and the trade-off
  16. 0:38between bias and variance. If not, check
  17. 0:42out the quests. The links are in the
  18. 0:44description below.
  19. 0:46This StatQuest is the first part in a
  20. 0:49series that explains how the gradient
  21. 0:51boost machine learning algorithm works.
  22. 0:54Specifically, we'll use this data
  23. 0:57where we have the height measurements
  24. 0:59from six people, their favorite colors,
  25. 1:02their genders,
  26. 1:04and their weights.
  27. 1:07And we'll walk through, step-by-step,
  28. 1:09the most common way that gradient boost
  29. 1:11fits a model to this training data.
  30. 1:14Note, when gradient boost is used to
  31. 1:17predict a continuous value, like weight,
  32. 1:20we say that we are using gradient boost
  33. 1:22for regression.
  34. 1:24Using gradient boost for regression is
  35. 1:27different from doing linear regression.
  36. 1:29So, while the two methods are related,
  37. 1:31don't get them confused with each other.
  38. 1:34Part two in this series will dive deep
  39. 1:37into the math behind the gradient boost
  40. 1:39algorithm for regression, walking
  41. 1:41through it step-by-step and proving that
  42. 1:43what we covered today is correct.
  43. 1:47Part three in this series shows how
  44. 1:49gradient boost can be used for
  45. 1:51classification.
  46. 1:53Specifically, we'll walk through,
  47. 1:55step-by-step, the most common way
  48. 1:58gradient boost can classify someone as
  49. 2:00either loving the movie Troll 2 or not
  50. 2:03loving Troll 2.
  51. 2:05Part four will return to the math behind
  52. 2:08gradient boost, this time focusing on
  53. 2:10classification, walking through it
  54. 2:12step-by-step.
  55. 2:14Note, the gradient boost algorithm looks
  56. 2:17complicated because it was designed to
  57. 2:19be configured in a wide variety of ways.
  58. 2:24But, the reality is that 99% of the time
  59. 2:27only one configuration is used to
  60. 2:29predict continuous values like weight,
  61. 2:32and one configuration is used to
  62. 2:34classify samples into different
  63. 2:36categories.
  64. 2:38This StatQuest focuses on showing you
  65. 2:40the most common way gradient boost is
  66. 2:42used to predict a continuous value like
  67. 2:45weight.
  68. 2:47If you are familiar with AdaBoost, then
  69. 2:49a lot of gradient boost will seem very
  70. 2:51similar.
  71. 2:53So, let's briefly compare and contrast
  72. 2:55AdaBoost and gradient boost.
  73. 2:59If we want to use these measurements to
  74. 3:00predict weight,
  75. 3:02then AdaBoost starts by building a very
  76. 3:05short tree called a stump from the
  77. 3:07training data.
  78. 3:09And then the amount of say that the new
  79. 3:11stump has on the final output is based
  80. 3:14on how well it compensated for those
  81. 3:16previous errors.
  82. 3:19Then AdaBoost builds the next stump
  83. 3:21based on errors that the previous stump
  84. 3:23made.
  85. 3:25In this example, the new stump did a
  86. 3:27poor job compensating for the previous
  87. 3:30stump's errors, and its size reflects
  88. 3:32its reduced amount of say.
  89. 3:35Then AdaBoost builds another stump based
  90. 3:38on the errors made by the previous
  91. 3:40stump.
  92. 3:41And this stump did a little better than
  93. 3:43the last stump, so it's a little larger.
  94. 3:47Then AdaBoost continues to make stumps
  95. 3:49in this fashion until it has made the
  96. 3:51number of stumps you asked for or it has
  97. 3:54a perfect fit.
  98. 3:56In contrast, gradient boost starts by
  99. 3:59making a single leaf instead of a tree
  100. 4:01or stump.
  101. 4:04This leaf represents an initial guess
  102. 4:06for the weights for all of the samples.
  103. 4:10When trying to predict a continuous
  104. 4:12value like weight, the first guess is
  105. 4:14the average value.
  106. 4:17Then gradient boost builds a tree.
  107. 4:20Like AdaBoost, this tree is based on the
  108. 4:23errors made by the previous tree.
  109. 4:26But unlike AdaBoost, this tree is
  110. 4:28usually larger than a stump.
  111. 4:31That said, gradient boost still
  112. 4:33restricts the size of the tree.
  113. 4:36In the simple example that we will go
  114. 4:38through in this stat quest, we will
  115. 4:40build trees with up to four leaves, but
  116. 4:43no larger.
  117. 4:45However, in practice, people often set
  118. 4:48the maximum number of leaves to be
  119. 4:50between eight and 32.
  120. 4:53Thus, like AdaBoost, gradient boost
  121. 4:56builds fixed-size trees based on the
  122. 4:58previous trees' errors, but unlike
  123. 5:00AdaBoost, each tree can be larger than a
  124. 5:03stump.
  125. 5:05Also, like AdaBoost, gradient boost
  126. 5:08scales the trees. However, gradient
  127. 5:11boost scales all trees by the same
  128. 5:14amount.
  129. 5:16Then gradient boost builds another tree
  130. 5:18based on the errors made by the previous
  131. 5:20tree.
  132. 5:22And then it scales the tree.
  133. 5:25And gradient boost continues to build
  134. 5:27trees in this fashion until it has made
  135. 5:29the number of trees you asked for or
  136. 5:32additional trees fail to improve the
  137. 5:34fit.
  138. 5:36Now that we know the main similarities
  139. 5:38and differences between gradient boost
  140. 5:40and AdaBoost,
  141. 5:42let's see how the most common gradient
  142. 5:44boost configuration would use this
  143. 5:47training data to predict weight.
  144. 5:50The first thing we do is calculate the
  145. 5:52average weight.
  146. 5:54This is the first attempt at predicting
  147. 5:57everyone's weight.
  148. 5:59In other words, if we stopped right now,
  149. 6:02we would predict that everyone weighed
  150. 6:0471.2 kg.
  151. 6:08However, gradient boost doesn't stop
  152. 6:10here.
  153. 6:12The next thing we do is build a tree
  154. 6:15based on the errors from the first tree.
  155. 6:18The errors that the previous tree made
  156. 6:20are the differences between the observed
  157. 6:23weights and the predicted weight, 71.2.
  158. 6:28So, let's start by plugging in 71.2
  159. 6:31for the predicted weight.
  160. 6:34And then plug in the first observed
  161. 6:36weight.
  162. 6:38And do the math.
  163. 6:41And save the difference, which is called
  164. 6:43a pseudo residual, in a new column.
  165. 6:47Note, the term pseudo residual is based
  166. 6:50on linear regression, where the
  167. 6:52difference between the observed values
  168. 6:54and the predicted values results in
  169. 6:56residuals.
  170. 6:59The pseudo part of pseudo residual is a
  171. 7:02reminder that we are doing gradient
  172. 7:03boost, not linear regression, and is
  173. 7:06something I'll talk more about in part
  174. 7:08two of this series when we go through
  175. 7:10the math.
  176. 7:12Now, we do the same thing for the
  177. 7:14remaining weights.
  178. 7:17Now, we will build a tree using height,
  179. 7:20favorite color, and gender
  180. 7:22to predict the residuals.
  181. 7:25If it seems strange to predict the
  182. 7:27residuals instead of the original
  183. 7:29weights, just bear with me, and soon all
  184. 7:32will become clear.
  185. 7:35So, setting aside the reason why we are
  186. 7:38building a tree to predict the residuals
  187. 7:40for the time being, here's the tree.
  188. 7:44Remember, in this example, we are only
  189. 7:47allowing up to four leaves.
  190. 7:49But when using a larger data set, it is
  191. 7:52common to allow anywhere from eight to
  192. 7:5432.
  193. 7:57By restricting the total number of
  194. 7:58leaves, we get fewer leaves than
  195. 8:01residuals.
  196. 8:03As a result, these two rows of data go
  197. 8:06to the same leaf.
  198. 8:08So, we replace these residuals with
  199. 8:11average.
  200. 8:13And these two rows of data go to the
  201. 8:15same leaf.
  202. 8:17So, we replace these residuals with
  203. 8:20their average.
  204. 8:22Now, we can combine the original leaf
  205. 8:25with the new tree
  206. 8:27to make a new prediction of an
  207. 8:29individual's weight from the training
  208. 8:31data.
  209. 8:33We start with the initial prediction,
  210. 8:3571.2.
  211. 8:38Then, we run the data down the tree,
  212. 8:41and we get 16.8.
  213. 8:45So, the predicted weight equals 71.2
  214. 8:49+ 16.8,
  215. 8:51which equals 88.
  216. 8:54Which is the same as the observed
  217. 8:56weight.
  218. 8:57Is this awesome?
  219. 9:00No. The model fits the training data too
  220. 9:03well.
  221. 9:05In other words, we have low bias, but
  222. 9:07probably very high variance.
  223. 9:11Gradient boost deals with this problem
  224. 9:13by using a learning rate to scale the
  225. 9:15contribution from the new tree.
  226. 9:19The learning rate is a value between
  227. 9:21zero and one.
  228. 9:24In this case, we'll set the learning
  229. 9:26rate to 0.1.
  230. 9:29Now, the predicted weight equals 71.2
  231. 9:33+ 0.1 * 16.8,
  232. 9:37which equals 72.9.
  233. 9:41With the learning rate set to 0.1,
  234. 9:44the new prediction isn't as good as it
  235. 9:46was before,
  236. 9:48but it's a little better than the
  237. 9:49prediction made with just the original
  238. 9:51leaf, which predicted that all samples
  239. 9:54would weigh 71.2.
  240. 9:57In other words, scaling the tree by the
  241. 9:59learning rate results in a small step in
  242. 10:02the right direction.
  243. 10:04According to the dude that invented
  244. 10:06gradient boost, Jerome Friedman,
  245. 10:08empirical evidence shows that taking
  246. 10:10lots of small steps in the right
  247. 10:12direction results in better predictions
  248. 10:14with a testing data set, i.e. lower
  249. 10:17variance.
  250. 10:19Bam!
  251. 10:21So, let's build another tree so we can
  252. 10:24take another small step in the right
  253. 10:26direction.
  254. 10:28Just like before, we calculate the
  255. 10:30pseudo residuals, the difference between
  256. 10:32the observed weights and our latest
  257. 10:34predictions.
  258. 10:36So, we plug in the observed weight
  259. 10:40and the new predicted weight
  260. 10:43and we get 15.1.
  261. 10:46And we save that in the column for
  262. 10:48pseudo residuals.
  263. 10:51Then we repeat for all of the other
  264. 10:53individuals in the training data set.
  265. 10:58Small bam.
  266. 11:00Note, these are the original residuals
  267. 11:03from when our prediction was simply the
  268. 11:05average overall weight.
  269. 11:08And these are the residuals after adding
  270. 11:10the new tree scaled by the learning
  271. 11:12rate.
  272. 11:14The new residuals are all smaller than
  273. 11:16before, so we've taken a small step in
  274. 11:19the right direction.
  275. 11:21Double bam!
  276. 11:24Now, let's build a new tree to predict
  277. 11:27the new residuals.
  278. 11:30And here's the new tree.
  279. 11:32Note, in this simple example, the
  280. 11:35branches are the same as before.
  281. 11:37However, in practice, the trees can be
  282. 11:40different each time.
  283. 11:43Just like before, since multiple samples
  284. 11:45ended up in these leaves, we just
  285. 11:47replace the residuals with their
  286. 11:49averages.
  287. 11:51Now we combine the new tree with the
  288. 11:54previous tree and the initial leaf.
  289. 11:58Note, we scale all of the trees by the
  290. 12:01learning rate, which we set to 0.1.
  291. 12:05And add everything together.
  292. 12:08Now we're ready to make a new prediction
  293. 12:10from the training data.
  294. 12:13Just like before, we start with the
  295. 12:15initial prediction.
  296. 12:17Then add the scaled amount from the
  297. 12:19first tree
  298. 12:21and the scaled amount from the second
  299. 12:23tree.
  300. 12:25That gives us 71.2
  301. 12:29+ 0.1 * 16.8
  302. 12:32+ 0.1 * 15.1
  303. 12:36which equals 74.4.
  304. 12:40Which is another small step closer to
  305. 12:43the observed weight.
  306. 12:45Now we use the initial leaf
  307. 12:48plus the scaled values from the first
  308. 12:50tree
  309. 12:51plus the scaled values from the second
  310. 12:53tree
  311. 12:55to calculate new residuals.
  312. 12:59Remember, these were the residuals from
  313. 13:01when we just used a single leaf to
  314. 13:04predict weight.
  315. 13:06And these were the residuals after we
  316. 13:08added the first tree to the prediction.
  317. 13:11And these are the residuals after we
  318. 13:14added the second tree to the prediction.
  319. 13:17Each time we add a tree to the
  320. 13:19prediction, the residuals get smaller.
  321. 13:23So we've taken another small step
  322. 13:25towards making good predictions.
  323. 13:28Now we build another tree to predict the
  324. 13:31new residuals.
  325. 13:34And add it to the chain of trees that we
  326. 13:36have already created.
  327. 13:39And we keep making trees until we reach
  328. 13:41the maximum specified or adding
  329. 13:43additional trees does not significantly
  330. 13:46reduce the size of the residuals.
  331. 13:49Bam.
  332. 13:50Then, when we get some new measurements,
  333. 13:54we can predict weight
  334. 13:56by starting with the initial prediction,
  335. 14:00then adding the scaled value from the
  336. 14:02first tree,
  337. 14:04and the second tree,
  338. 14:06and the third tree,
  339. 14:09et cetera, et cetera, et cetera.
  340. 14:13And once the math is all done, we are
  341. 14:15left with the predicted weight.
  342. 14:18In this case, we predicted that this
  343. 14:21person weighed 70 kg.
  344. 14:24Triple bam.
  345. 14:28In summary, when gradient boost is used
  346. 14:31for regression,
  347. 14:33we start with a leaf that is the average
  348. 14:35value of the variable we want to
  349. 14:37predict.
  350. 14:39In this case, we wanted to predict
  351. 14:42weight.
  352. 14:44Then we add a tree based on the
  353. 14:46residuals, the difference between the
  354. 14:48observed values and the predicted
  355. 14:50values.
  356. 14:52And we scale the tree's contribution to
  357. 14:55the final prediction with a learning
  358. 14:57rate.
  359. 14:59Then we add another tree based on the
  360. 15:01new residuals.
  361. 15:04And we keep adding trees based on the
  362. 15:06errors made by the previous tree.
  363. 15:09That's all there is to it.
  364. 15:12Bam.
  365. 15:14Tune in for part two in this series when
  366. 15:16we dive deep into the math behind the
  367. 15:18gradient boost algorithm for regression,
  368. 15:21walking through it step by step, and
  369. 15:23proving that it really is this simple.
  370. 15:27Hooray! We've made it to the end of
  371. 15:29another exciting StatQuest. If you like
  372. 15:32this StatQuest and want to see more,
  373. 15:34please subscribe. And if you want to
  374. 15:36support StatQuest, consider buying one
  375. 15:38of my original songs, or buying a
  376. 15:40StatQuest t-shirt or hoodie. The links
  377. 15:43are in the description below.
  378. 15:45All right. Until next time, quest on.

About this transcript

This page contains the full transcript of Gradient Boost Part 1 (of 4): Regression Main Ideas by StatQuest with Josh Starmer, generated from the public captions YouTube serves with the video. The transcript has 2,029 words across 378 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.