• Step 2: Generate random data
  • Step 3: Use Scikit-Learn
  • Step 4: Finding the centroid
  • Ma’lumotlarning intellektual tahlili fanidan yakuniy nazoratda tushadigan savollar mazmunini akslantirgan savollar banki




    Download 2.1 Mb.
    bet10/14
    Sana15.03.2023
    Hajmi2.1 Mb.
    #45527
    1   ...   6   7   8   9   10   11   12   13   14
    Bog'liq
    data mining yakiy savol javobi bilan
    VIZUAL, Taqdimot (8), @uqituvchiga hujjat Aniq fanlar metodbirlashmasi ish rejasi
    Step 1: Import libraries
    import pandas as pdimport numpy as npimport matplotlib.pyplot as pltfrom sklearn.cluster import KMeans%matplotlib inline
    As you can see from the above code, we’ll import the following libraries in our project:

    Step 2: Generate random data
    Here is the code for generating some random data in a two-dimensional space:
    X= -2 * np.random.rand(100,2)X1 = 1 + 2 * np.random.rand(50,2)X[50:100, :] = X1plt.scatter(X[ : , 0], X[ :, 1], s = 50, c = ‘b’)plt.show()
    A total of 100 data points has been generated and divided into two groups, of 50 points each.
    Here is how the data is displayed on a two-dimensional space:

    Step 3: Use Scikit-Learn
    We’ll use some of the available functions in the Scikit-learn library to process the randomly generated data.
    Here is the code:
    from sklearn.cluster import KMeansKmean = KMeans(n_clusters=2)Kmean.fit(X)
    In this case, we arbitrarily gave k (n_clusters) an arbitrary value of two.
    Here is the output of the K-means parameters we get if we run the code:
    KMeans(algorithm=’auto’, copy_x=True, init=’k-means++’, max_iter=300
    n_clusters=2, n_init=10, n_jobs=1, precompute_distances=’auto’,
    random_state=None, tol=0.0001, verbose=0)
    Step 4: Finding the centroid
    Here is the code for finding the center of the clusters:
    Kmean.cluster_centers_
    Here is the result of the value of the centroids:
    array([[-0.94665068, -0.97138368],
    [ 2.01559419, 2.02597093]])
    Let’s display the cluster centroids (using green and red color).
    plt.scatter(X[ : , 0], X[ : , 1], s =50, c=’b’)plt.scatter(-0.94665068, -0.97138368, s=200, c=’g’, marker=’s’)plt.scatter(2.01559419, 2.02597093, s=200, c=’r’, marker=’s’)plt.show()
    Here is the output:


    Download 2.1 Mb.
    1   ...   6   7   8   9   10   11   12   13   14




    Download 2.1 Mb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Ma’lumotlarning intellektual tahlili fanidan yakuniy nazoratda tushadigan savollar mazmunini akslantirgan savollar banki

    Download 2.1 Mb.