Learn how you can become a Python programmer in just 12 weeks.

    We respect your privacy. Unsubscribe at anytime.

    Master Unsupervised Learning with k-Means Clustering

    Why it’s great to master Unsupervised Learning?

    Mastering Unsupervised Learning offers several benefits and expands your skills in the field of machine learning:

    • Broaden your understanding: Unsupervised Learning takes you beyond the boundaries of traditional supervised learning. By mastering this approach, you can explore and analyze large amounts of unlabeled data, uncovering hidden patterns and structures that may not be evident through other methods.
    • Organize data without prior knowledge: Unsupervised Learning enables you to organize and make sense of data without relying on predefined labels or prior knowledge. This capability is particularly valuable when working with unstructured or unlabeled datasets, providing insights into the underlying structure and relationships within the data.
    • Learn k-Means Clustering: In this lesson, you will gain a solid understanding of k-Means Clustering, a popular unsupervised learning algorithm. You will learn how it works and how to apply it to cluster data points based on their similarity, allowing you to identify distinct groups or clusters within your dataset.
    • Train a k-Means Cluster model: Through practical exercises, you will have the opportunity to train your own k-Means Cluster model. This hands-on experience will deepen your understanding of the algorithm and equip you with the skills to apply it to real-world datasets.

    By mastering Unsupervised Learning and specifically k-Means Clustering, you will unlock new possibilities for data exploration, pattern discovery, and knowledge extraction from unlabeled data.

    Watch tutorial

    Step 1: What is Unsupervised Learning?

    Machine Learning is often divided into 3 main categories.

    • Supervised: where you tell the algorithm what categories each data item is in. Each data item from the training set is tagged with the right answer.
    • Unsupervised: is when the learning algorithm is not told what to do with it and it should make the structure itself.
    • Reinforcement: teaches the machine to think for itself based on past action rewards.

    Where we see that Unsupervised is one of the main groups.

    Unsupervised learning is a type of algorithm that learns patterns from untagged data. The hope is that through mimicry, which is an important mode of learning in people, the machine is forced to build a compact internal representation of its world and then generate imaginative content from it. In contrast to supervised learning where data is tagged by an expert, e.g. as a “ball” or “fish”, unsupervised methods exhibit self-organization that captures patterns as probability densities…


    Step 2: k-Means Clustering

    What is clustering?

    Organize a set of objects into groups in such a way that similar objects tend to be in the same group.

    What is k-Means Clustering?

    Algorithm for clustering data based on repeatedly assigning points to clusters and updating those clusters’ centers.

    Example of how it works in steps.
    • First we chose random cluster centroids (hollow point), then assign points to neareast centroid.
    • Then we update the centroid to be centered to the points.
    • Repeat

    This can be repeated a specific number of times or until only small change in centroids positions.

    Step 3: Create an Example

    Let’s create some random data to demonstrate it.

    import numpy as np
    import pandas as pd
    from sklearn.cluster import KMeans
    import matplotlib.pyplot as plt
    # Generate some numbers
    data = np.random.randn(400,2)
    data[:100] += 5, 5
    data[100:200] += 10, 10
    data[200:300] += 10, 5
    data[300:] += 5, 10
    fig, ax = plt.subplots()
    ax.scatter(x=data[:,0], y=data[:,1])

    This shows some random data in 4 clusters.

    Then the following code demonstrates how it works. You can change max_iter to be the number iteration – try to do it for 1, 2, 3, etc.

    model = KMeans(n_clusters=4, init='random', random_state=42, max_iter=10, n_init=1)
    y_pred = model.predict(data)
    fig, ax = plt.subplots()
    ax.scatter(x=data[:,0], y=data[:,1], c=y_pred)
    ax.scatter(x=model.cluster_centers_[:,0], y=model.cluster_centers_[:,1], c='r')
    After 1st iteration – the cluster centers are are no optimal
    After 10 iteration it is all in place

    Want to learn more?

    In the next lesson you will learn about Artificial Neural Network.

    This is part of a FREE 10h Machine Learning course with Python.

    • 15 video lessons – which explain Machine Learning concepts, demonstrate models on real data, introduce projects and show a solution (YouTube playlist).
    • 30 JuPyter Notebooks – with the full code and explanation from the lectures and projects (GitHub).
    • 15 projects – with step guides to help you structure your solutions and solution explained in the end of video lessons (GitHub).

    Python for Finance: Unlock Financial Freedom and Build Your Dream Life

    Discover the key to financial freedom and secure your dream life with Python for Finance!

    Say goodbye to financial anxiety and embrace a future filled with confidence and success. If you’re tired of struggling to pay bills and longing for a life of leisure, it’s time to take action.

    Imagine breaking free from that dead-end job and opening doors to endless opportunities. With Python for Finance, you can acquire the invaluable skill of financial analysis that will revolutionize your life.

    Make informed investment decisions, unlock the secrets of business financial performance, and maximize your money like never before. Gain the knowledge sought after by companies worldwide and become an indispensable asset in today’s competitive market.

    Don’t let your dreams slip away. Master Python for Finance and pave your way to a profitable and fulfilling career. Start building the future you deserve today!

    Python for Finance a 21 hours course that teaches investing with Python.

    Learn pandas, NumPy, Matplotlib for Financial Analysis & learn how to Automate Value Investing.

    “Excellent course for anyone trying to learn coding and investing.” – Lorenzo B.

    Leave a Comment