TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

ML Basics: K Nearest Neighbors in Ruby

83 pointsby foobover 7 years ago

9 comments

apathyover 7 years ago
Just a thought:<p>When Cover &amp; Hart proved that the error for k-NN classification is no worse than twice the Bayes (optimal) error, &quot;machine learning&quot; as a phrase had not yet been observed in the wild.<p><a href="http:&#x2F;&#x2F;ieeexplore.ieee.org&#x2F;document&#x2F;1053964&#x2F;" rel="nofollow">http:&#x2F;&#x2F;ieeexplore.ieee.org&#x2F;document&#x2F;1053964&#x2F;</a><p>EE, CS, stats -- these are your fundamentals...
评论 #15251990 未加载
评论 #15249432 未加载
aswansonover 7 years ago
I love ruby, but its falling almost irretrievably behind python in data analysis&#x2F;visualization&#x2F;machine learning libraries.
评论 #15250217 未加载
评论 #15250385 未加载
评论 #15252872 未加载
wycover 7 years ago
A different kind of &quot;expressiveness.&quot;<p><pre><code> NB. naive k-nearest neighbors in J dist =: [:%:[:|[:+&#x2F;(*:@:-) NB. dyad takes two vectors, returns euclidean distance data =: 1 2 3,2 2 3,2 3 3,1 2 3,:2 3 4 query =: 1 2 3 k =: 3 k {.&quot;1 &#x2F;:&quot;1 query&amp;dist&quot;1 data</code></pre>
评论 #15255556 未加载
评论 #15250239 未加载
computerwizardover 7 years ago
Ruby is so expressive it&#x27;s a shame it isn&#x27;t used more for ML and AI.
评论 #15249613 未加载
mck-over 7 years ago
For the js crowd, here&#x27;s an implementation of KNN in Node I did a few years ago: <a href="https:&#x2F;&#x2F;github.com&#x2F;axiomzen&#x2F;Alike" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;axiomzen&#x2F;Alike</a><p>And it&#x27;s cousin KD-tree: <a href="https:&#x2F;&#x2F;github.com&#x2F;axiomzen&#x2F;look-alike" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;axiomzen&#x2F;look-alike</a>
abhghover 7 years ago
K-NN is one of the more concise classifiers to implement. I did a Python implementation a while ago that can fit into a tweet -[1]. Since maps&#x2F;lambdas are available in Ruby, this should be possible in Ruby too. Sorry for the bad presentation - I am planning to migrate soon.<p>[1] <a href="http:&#x2F;&#x2F;quipu-strands.blogspot.com&#x2F;2014&#x2F;08&#x2F;knn-classifier-in-one-line-of-python.html" rel="nofollow">http:&#x2F;&#x2F;quipu-strands.blogspot.com&#x2F;2014&#x2F;08&#x2F;knn-classifier-in-...</a>
s17nover 7 years ago
I get that this is supposed to be basic but why wouldn&#x27;t you at least observe that the sqrt call is unnecessary?
评论 #15250219 未加载
xchipover 7 years ago
KNN is quite a simple operation in ML. I might be underestimating the effort but... Why is this an achievement?
评论 #15252647 未加载
frugalmailover 7 years ago
who still thinks Ruby is a good idea for this?
评论 #15252879 未加载