5 kyu
Simple Linear Regression Cost Function (Machine Learning)
293 of 297Ban-Ath
Loading description...
Machine Learning
Algorithms
Mathematics
Data Science
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Rounding issues should be fixed with this kata. The user is not provided feedback on the training set used in testing. It should show expected as well as user answer, now only showing expected
Anyone stumbling upon the same problem: use Math.round(J * 1000) / 1000 for rounding to 3 decimals, not toFixed(3)
The example in the description isn't that well picked. It doesn't show the full glory of
h(x)
You expect it to equal 1.5. The error message is wrong.
Tests shouldnt use
expect
.Needs random tests.
This is nice, a first step into supervised learning. I added a translation in C++.
Basic math question on the example: Isn't
((0.5 + 9) - 8)^2
supposed to be2.25
and not6.25
? I mean neither the naive approach nor binomic formula result in 6.25 for (9.5 - 8)². Am I missing something here, that is about correct setting of braces or something?Hey, just wanted to reiterate issues that have been pointed out, in hopes this kata gets these fixes.
1st - mentioned previously by Sifawm
2nd - This second issue was brought up by JulianNicholls, in response constablebrew put forth the formatting J(θ1, θ2) = 1/(2 ⋅ m) ⋅ Σ( (h(x) - y)2 ). I see Ban-Ath that in response you choose to leave the equation as is because it stays true to material you are reading. If you would compare this
The left is probably how it is formatted in your readings and is very clear. The right does read as 0.5 * m so I hope you reconsider and go with
Thanks for listening.
I've done a related kata that involves implementing both gradient descent and a cost function - I only just saw this one after I submitted mine :-)
http://www.codewars.com/kata/linear-regression-with-one-variable/ruby
I might be not awake but: The sixth and final one would be, ((0.5 + 9) - 11)^2 = 0.25 is wrong: (9.5-11)^2=(-1.5)^2=2.25
The sample test case in the guide is incorrect.
This comment has been hidden.
a fun expansion would be to be send directly to the next part (after completing this kata) where you get to implement the gradient descent algorithm, I've done this once for a CS course, and at the time didn't understand it too well (+ it was in a weird language I barely understood), it would be fun to do in JS (I think)
as this kata stands now, it's a fun introduction, but it doesn't really teach anything about machine learning :/
+1 would love a kata like that as well. Just out of curiosity, in which language was it in your CS course ?
uhm, Octave if I'm not mistaken. it had some usefull built in stuff for Matrices and such, but the language itself was just weird, it wasn't bad, it just felt... wrong (I can't remember why, probably stuff like 1 based arrays and stuff like that)
I have a gradient descent kata for you http://www.codewars.com/kata/linear-regression-with-one-variable/ruby :-)
It's in Ruby - let me know if you'd like a js version
This comment has been hidden.
I think that you need to be a little clearer about the bracket / exponentiation placement in the description. I did interpret it correctly, but maybe something like this
is better. YMMV :-)
I agree, the description isn't very clear due to the poor formatting. Might I suggest:
J(θ1, θ2) = 1/(2 ⋅ m) ⋅ Σ( (h(x) - y)2 )
Thanks, I've updated the description with your input and walked through an example. I'm keeping (1/2m) * on the left because that is how it is represented in all the formulas for linear regression that I have seen. I'm trying to set up these Kata to bring code warriors to the next challenges in machine learning, and want to keep this as close to the material as I can. Appreciate your input though :).
Also, x,y are not coordinate pairs. X is a feature that we are tracking (can be one of many) and Y is our target. Using this cost function repeatedly in machine learning, we try to come to theta values that minimize our cost, giving us a line that fits the targets as close as we can make it.
That's so much clearer now.
In some other Kata, my code didn't work because I rounded to three decimal places using Math.round(1000*n)/1000 instead of n.toFixed(3).
Here, with this Kata, n.toFixed(3) doesn't work because it says that 1.5 isn't equal to 1.500, but Math.round(1000*n)/1000 does work.
I think Test cases for Katas that require rounding should do the rounding in the test case, provide a rounding function we should use, or just check that Math.abs(actual - expected) < 0.0005.
Thanks for pointing that out. I've updated the test cases with your suggestion.
This is because toFixed() returns a string but number is expected.
+n.toFixed(3)
works perfectly.