In [22]:
from sklearn import preprocessing, datasets as d
import numpy as np
import scipy
In [8]:
boston = d.load_boston()
X, y = boston.data, boston.target
In [9]:
X[:, :3].mean(axis=0)
Out[9]:
In [10]:
X[:, :3].std(axis=0)
Out[10]:
In [11]:
X_2 = preprocessing.scale(X[:, :3])
In [12]:
X_2.mean(axis=0)
Out[12]:
In [13]:
X_2.std(axis=0)
Out[13]:
In [14]:
normalized_X = preprocessing.normalize(X[:, :3])
In [16]:
normalized_X.mean(axis=0)
Out[16]:
In [17]:
normalized_X.std(axis=0)
Out[17]:
In [19]:
test_x = [[1.0,1.0,0.0], [3.0,3.0,0.0], [1.0,-1.0, 0.0]]
normalized_test = preprocessing.normalize(test_x)
In [20]:
normalized_test
Out[20]:
In [21]:
## handling sparse imputations
In [23]:
matrix = scipy.sparse.eye(1000)
In [25]:
preprocessing.scale(matrix, with_mean=False)
Out[25]:
In [ ]: