#### Overview of this book

Machine learning applications are highly automated and self-modifying, and continue to improve over time with minimal human intervention, as they learn from the trained data. To address the complex nature of various real-world data problems, specialized machine learning algorithms have been developed. Through algorithmic and statistical analysis, these models can be leveraged to gain new knowledge from existing data as well. Data Science Algorithms in a Week addresses all problems related to accurate and efficient data classification and prediction. Over the course of seven days, you will be introduced to seven algorithms, along with exercises that will help you understand different aspects of machine learning. You will see how to pre-cluster your data to optimize and classify it for large datasets. This book also guides you in predicting data based on existing trends in your dataset. This book covers algorithms such as k-nearest neighbors, Naive Bayes, decision trees, random forest, k-means, regression, and time-series analysis. By the end of this book, you will understand how to choose machine learning algorithms for clustering, classification, and regression and know which is best suited for your problem
Title Page
Packt Upsell
Contributors
Preface
Free Chapter
Classification Using K-Nearest Neighbors
Time Series Analysis
Python Reference
Statistics
Glossary of Algorithms and Methods in Data Science
Other Books You May Enjoy
Index

## Household incomes – clustering into k clusters

For example, let's look at households whose annual earnings in USD are \$40,000, \$55,000, \$70,000, \$100,000, \$115,000, \$130,000 and \$135,000. Then, if we were to combine those households into two clusters, taking their earnings as a measure of similarity, the first cluster would have those households earning 40 k, 55 k, and 70 k, while the second cluster would include those households earning 100 k, 115 k, 130 k, and 135 k.

This is because 40k and 135k are furthest away from each other so, because we want to have two clusters, these have to be in different clusters. 55 K is closer to 40 k than to 135 k, so 40 k and 55 k will be in the same cluster. Similarly, 130 k and 135 k will be in the same cluster. 70 K is closer to 40 k and 55 k than to 130 K and 135 k, so 70 k should be in the cluster with 40 k and 55 k. 115 K is closer to 130 k and 135 k than to the first cluster containing 40 k, 55 k, and 70 k, so it will be in the second cluster. Finally...