How to Create simulated data for classification in Python?
0

How to Create simulated data for classification in Python?

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

    # Load libraries
    from sklearn.datasets import make_classification
    import pandas as pd

    # Create Simulated Data
    # Create a simulated feature matrix and output vector with 100 samples,
    features, output = make_classification(n_samples = 100,
                                       n_features = 10,
                                       n_informative = 10,
                                       n_redundant = 0,
                                       n_classes = 3,
                                       weights = [.2, .3, .8])

    # 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())

    # View the first five observation's classes
    print()
    print("Target Class: ");
    print(pd.DataFrame(output, columns=['TargetClass']).head())

Kickstarter_Example_23()
************How to Create simulated data for classification in Python*************

Feature Matrix:
   Feature 1  Feature 2  Feature 3  Feature 4  Feature 5  Feature 6  \
0  -1.867524   1.745983   2.952435  -0.177492  -3.088648   1.762311
1   0.450144  -2.106431  -1.065847  -1.958231  -0.451780  -1.990662
2  -4.647836  -4.214226  -1.830341  -1.714825  -6.590249  -0.315993
3   1.958901  -1.313546   1.409145  -2.069271   1.508912   3.774923
4   2.001750   0.879350  -2.041154   1.917629  -0.760137   1.310228

   Feature 7  Feature 8  Feature 9  Feature 10
0  -0.195266   1.029769   2.814171    0.071059
1  -2.530104  -1.377802  -0.013353   -2.849859
2   2.780038  -3.325841  -4.008319    2.001941
3   5.012315  -5.772415  -0.818187   -0.392333
4   0.671990   1.444606  -1.731576   -0.378597

Target Class:
   TargetClass
0            1
1            2
2            1
3            0
4            0