Python One-Liners: Write Concise, Eloquent Python Like a Professional by Christian Mayer

Python One-Liners: Write Concise, Eloquent Python Like a Professional by Christian Mayer

Author:Christian Mayer
Language: eng
Format: mobi, epub
ISBN: 9781718500518
Publisher: No Starch Press, Inc.
Published: 2020-07-14T16:00:00+00:00


K-Means Clustering in One Line

If there’s one clustering algorithm you need to know—whether you’re a computer scientist, data scientist, or machine learning expert—it’s the K-Means algorithm. In this section, you’ll learn the general idea and when and how to use it in a single line of Python code.

The Basics

The previous sections covered supervised learning, in which the training data is labeled. In other words, you know the output value of every input value in the training data. But in practice, this isn’t always the case. Often, you’ll find yourself confronted with unlabeled data—especially in many data analytics applications—where it’s not clear what “the optimal output” means. In these situations, a prediction is impossible (because there is no output to start with), but you can still distill useful knowledge from these unlabeled data sets (for example, you can find clusters of similar unlabeled data). Models that use unlabeled data fall under the category of unsupervised learning.

As an example, suppose you’re working in a startup that serves different target markets with various income levels and ages. Your boss tells you to find a certain number of target personas that best fit your target markets. You can use clustering methods to identify the average customer personas that your company serves. Figure 4-10 shows an example.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.