Rescaling data with Normalization and Standardization
# Normalize the data attributes for the Iris dataset.
from sklearn.datasets import load_iris
from sklearn import preprocessing
# load the iris dataset
iris = load_iris()
print(iris.data.shape)
# separate the data from the target attributes
X = iris.data
y = iris.target
# normalize the data attributes
normalized_X = preprocessing.normalize(X)
# Standardize the data attributes for the Iris dataset.
from sklearn.datasets import load_iris
from sklearn import preprocessing
# load the Iris dataset
iris = load_iris()
print(iris.data.shape)
# separate the data and target attributes
X = iris.data
y = iris.target
# standardize the data attributes
standardized_X = preprocessing.scale(X)
#OR
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
sc.fit(X)
X=sc.transform(X)
X_sub=sc.transform(X_sub)
X = pd.DataFrame(X)
X_sub = pd.DataFrame(X_sub)
X.head()