How to Create simulated data for regression in Python?

How to Create simulated data for regression in Python?

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

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

    # Create Simulated Data
    # Generate fetures, outputs, and true coefficient of 100 samples,
    features, output, coef = make_regression(n_samples = 100, n_features = 3,
                                n_informative = 3, n_targets = 1,
                                noise = 0.0, coef = True)

    # View Simulated Data
    # View the features of the first five rows
    print()
    print(pd.DataFrame(features, columns=['Feature 1', 'Feature 2', 'Feature 3']).head())

    # View the output of the first five rows
    print()
    print(pd.DataFrame(output, columns=['Target']).head())

    # View the actual, true coefficients used to generate the data
    print()
    print(pd.DataFrame(coef, columns=['True Coefficient Values']))

Kickstarter_Example_22()
**************How to Create simulated data for regression in Python***************

   Feature 1  Feature 2  Feature 3
0  -1.361349   1.982526  -1.144529
1  -0.925345  -0.861086   0.137837
2   0.419575  -1.925695  -0.178226
3   0.053922  -0.520252  -0.386195
4  -0.397518   1.220856  -0.893696

       Target
0 -145.429093
1  -51.263123
2  -30.024469
3  -43.656632
4  -84.419295

   True Coefficient Values
0                52.736720
1                18.208275
2                95.877359


Stuck at work?
Can't find the recipe you are looking for. Let us know and we will find an expert to create the recipe for you. Click here
Companies using this Recipe
1 developer from HCL
1 developer from MudraCircle
1 developer from Altimetrik
1 developer from HvH
1 developer from Vodafone
1 developer from ANAC
1 developer from KPMG
1 developer from YASH Technologies
1 developer from Embicon
1 developer from LTI