Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Hands-on Machine Learning with JavaScript

You're reading from   Hands-on Machine Learning with JavaScript Solve complex computational web problems using machine learning

Arrow left icon
Product type Paperback
Published in May 2018
Publisher Packt
ISBN-13 9781788998246
Length 356 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Burak Kanber Burak Kanber
Author Profile Icon Burak Kanber
Burak Kanber
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Exploring the Potential of JavaScript FREE CHAPTER 2. Data Exploration 3. Tour of Machine Learning Algorithms 4. Grouping with Clustering Algorithms 5. Classification Algorithms 6. Association Rule Algorithms 7. Forecasting with Regression Algorithms 8. Artificial Neural Network Algorithms 9. Deep Neural Networks 10. Natural Language Processing in Practice 11. Using Machine Learning in Real-Time Applications 12. Choosing the Best Algorithm for Your Application 13. Other Books You May Enjoy

Example 1 – k-means on simple 2D data

We've got our implementation of the k-means algorithm written and coded, so now it's time to see how it works. In our first example, we'll run our algorithm against a simple dataset of two-dimensional data. The data itself will be contrived so that the algorithm can easily find three distinct clusters.

First, modify the data.js file to add the following data, anywhere preceding the export default line:

const example_2d3k = [
[1, 2], [2, 3], [2, 5], [1, 6], [4, 6],
[3, 5], [2, 4], [4, 3], [5, 2], [6, 9],
[4, 4], [3, 3], [8, 6], [7, 5], [9, 6],
[9, 7], [8, 8], [7, 9], [11, 3], [11, 2],
[9, 9], [7, 8], [6, 8], [12, 2], [14, 3],
[15, 1], [15, 4], [14, 2], [13, 1], [16, 4]
];

Then, update the final export line to look like this:

export default {
example_randomCentroids,
example_2d3k
};

If we were to graph...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime