How to Create simulated data for clustering in Python?
0

How to Create simulated data for clustering in Python?

This recipe helps you Create simulated data for clustering in Python
In [1]:
## How to Create simulated data for clustering in Python 
def Kickstarter_Example_24():
    print()
    print(format('How to Create simulated data for clustering in Python', '*^82'))

    # Load libraries
    from sklearn.datasets import make_blobs
    import matplotlib.pyplot as plt
    import pandas as pd

    # Make the features (X) and output (y) with 200 samples,
    features, clusters = make_blobs(n_samples = 2000,
                  n_features = 10, centers = 5,
                  # with .5 cluster standard deviation,
                  cluster_std = 0.4,
                  shuffle = True)

    # View the first five observations and their 10 features
    print()
    print("Feature Matrix: ");
    print(pd.DataFrame(features, columns=['Feature 1', 'Feature 2', 'Feature 3',
         'Feature 4', 'Feature 5', 'Feature 6', 'Feature 7', 'Feature 8',
         'Feature 9', 'Feature 10']).head())

    # Create a scatterplot of the first and second features
    plt.scatter(features[:,0], features[:,1])

    # Show the scatterplot
    plt.show()

Kickstarter_Example_24()
**************How to Create simulated data for clustering in Python***************

Feature Matrix:
   Feature 1  Feature 2  Feature 3  Feature 4  Feature 5  Feature 6  \
0  -5.301777  -0.288487   4.426895  -7.346082   0.841896   7.120860
1  -2.146525   5.418930  -8.526391  -3.028764  -4.153195   9.803507
2   1.560945   6.419495  -1.759591  -9.156973   8.489981   4.229867
3   6.243948  -6.006760  -9.065597   3.672920  -1.327192   5.638014
4   5.883899   7.947210  -6.298867  -6.715524   0.361343  -5.462168

   Feature 7  Feature 8  Feature 9  Feature 10
0   5.853593  -4.528930   5.301169    4.174106
1   3.005134  -7.790637   6.252099    5.263176
2  -5.721829   5.110951  -0.667662   -2.777335
3  -9.557726  -5.902056   6.441669    2.168129
4  -2.620218  -6.522848   6.959409    5.542048
<Figure size 640x480 with 1 Axes>