The error is reproducible if the array is of dtype=object:
import numpy as np
label0 = np.random.random((50, 3)).astype(object)
np.cov(label0, rowvar=False)
AttributeError: 'float' object has no attribute 'shape'
If possible you should convert it to a numeric type. For example:
np.cov(label0.astype(float), rowvar=False) # works
Note: object arrays are rarely useful (they are slow and not all NumPy functions deal gracefully with these - like in this case), so it could make sense to check where it came from and also fix that.
The error is reproducible if the array is of dtype=object:
import numpy as np
label0 = np.random.random((50, 3)).astype(object)
np.cov(label0, rowvar=False)
AttributeError: 'float' object has no attribute 'shape'
If possible you should convert it to a numeric type. For example:
np.cov(label0.astype(float), rowvar=False) # works
Note: object arrays are rarely useful (they are slow and not all NumPy functions deal gracefully with these - like in this case), so it could make sense to check where it came from and also fix that.
try
label0.astype(float32)
and then calculate your cov.
It might because your dtype is object.
Solution was linked on reshaped method on documentation page.
Insted of Y.reshape(-1,1) you need to use:
Y.values.reshape(-1,1)
The solution is indeed to do:
Y.values.reshape(-1,1)
This extracts a numpy array with the values of your pandas Series object and then reshapes it to a 2D array.
The reason you need to do this is that pandas Series objects are by design one dimensional. Another solution if you would like to stay within the pandas library would be to convert the Series to a DataFrame which would then be 2D:
Y = pd.Series([1,2,3,1,2,3,4,32,2,3,42,3])
scaler = StandardScaler()
Ys = scaler.fit_transform(pd.DataFrame(Y))