How to standardise IRIS Data in Python?

How to standardise IRIS Data in Python?

This recipe helps you standardise IRIS Data in Python
In [2]:
## How to standarise IRIS Data in Python 
def Kickstarter_Example_41():
    print()
    print(format('How to standarise IRIS Data in Python', '*^82'))
    import warnings
    warnings.filterwarnings("ignore")

    from sklearn import datasets
    from sklearn.model_selection import train_test_split
    from sklearn.preprocessing import StandardScaler

    iris = datasets.load_iris()
    X = iris.data
    y = iris.target
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3,
                                                        random_state=42)
    sc = StandardScaler()
    sc.fit(X_train)
    X_train_std = sc.transform(X_train)
    X_test_std = sc.transform(X_test)

    print(); print(X_train[0:5])
    print(); print(X_train_std[0:5])
    print(); print(X_test[0:5])
    print(); print(X_test_std[0:5])
Kickstarter_Example_41()
**********************How to standarise IRIS Data in Python***********************

[[5.5 2.4 3.7 1. ]
 [6.3 2.8 5.1 1.5]
 [6.4 3.1 5.5 1.8]
 [6.6 3.  4.4 1.4]
 [7.2 3.6 6.1 2.5]]

[[-0.4134164  -1.46200287 -0.09951105 -0.32339776]
 [ 0.55122187 -0.50256349  0.71770262  0.35303182]
 [ 0.67180165  0.21701605  0.95119225  0.75888956]
 [ 0.91296121 -0.02284379  0.30909579  0.2177459 ]
 [ 1.63643991  1.41631528  1.30142668  1.70589097]]

[[6.1 2.8 4.7 1.2]
 [5.7 3.8 1.7 0.3]
 [7.7 2.6 6.9 2.3]
 [6.  2.9 4.5 1.5]
 [6.8 2.8 4.8 1.4]]

[[ 0.3100623  -0.50256349  0.484213   -0.05282593]
 [-0.17225683  1.89603497 -1.26695916 -1.27039917]
 [ 2.23933883 -0.98228318  1.76840592  1.43531914]
 [ 0.18948252 -0.26270364  0.36746819  0.35303182]
 [ 1.15412078 -0.50256349  0.54258541  0.2177459 ]]


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 Decision Resources Group
1 developer from JP Morgan Chase
1 developer from MudraCircle
1 developer from Team247 Informatics
1 developer from YASH Technologies
1 developer from Altimetrik
1 developer from EXL Service
1 developer from KPMG
1 developer from Renovite Technologies
1 developer from Tech Mahindra