I have a sklearn StandardScaler
saved from a previous model and am trying to apply it to new data
scaler = myOldStandardScaler
print("ORIG:", X)
print("CLASS:", X.__class__)
X = scaler.fit_transform(X)
print("SCALED:", X)
I have three observations each with 2000 features. If I run each observation separately I get an output of all zeros.
ORIG: [[ 3.19029839e-04 0.00000000e+00 1.90985485e-06 ..., 0.00000000e+00
0.00000000e+00 0.00000000e+00]]
CLASS: <class 'numpy.matrixlib.defmatrix.matrix'>
SCALED: [[ 0. 0. 0. ..., 0. 0. 0.]]
But if I append all three observations into one array, I get the results I want
ORIG: [[ 0.00000000e+00 8.69737728e-08 7.53361877e-06 ..., 0.00000000e+00
0.00000000e+00 0.00000000e+00]
[ 9.49627142e-04 0.00000000e+00 0.00000000e+00 ..., 0.00000000e+00
0.00000000e+00 0.00000000e+00]
[ 3.19029839e-04 0.00000000e+00 1.90985485e-06 ..., 0.00000000e+00
0.00000000e+00 0.00000000e+00]]
CLASS: <class 'numpy.matrixlib.defmatrix.matrix'>
SCALED: [[-1.07174217 1.41421356 1.37153077 ..., 0. 0. 0. ]
[ 1.33494964 -0.70710678 -0.98439142 ..., 0. 0. 0. ]
[-0.26320747 -0.70710678 -0.38713935 ..., 0. 0. 0. ]]
I've seen these two questions:
neither of which have an accepted answer.
I've tried:
- reshaping from (1,n) to (n,1) (this gives incorrect results)
- converting the array to
np.float32
andnp.float64
(still all zero) - creating an array of an array (again, all zero)
- creating a
np.matrix
(again, all zeros)
What am I missing? The input to fit_transform
is getting the same type, just a different size.
How do I get StandardScaler to work with a single observation?