Skip to content Skip to sidebar Skip to footer

Typeerror: Only Integer Scalar Arrays Can Be Converted To A Scalar Index , While Trying Kfold Cv

Trying to perform Kfold cv on a dataset containing 279 files , the files are of shape ( 279 , 5 , 90) after performing a k-means. I reshaped it in order to fit it on a svm. Now the

Solution 1:

y which is an list cannot be indexed like numpy arrays.

Example:

y = [1,2,3,4,6]
idx = np.array([0,1])
print (y[idx])   # This will throw an error as list cannot be index this wayprint (np.array(y)[idx]) # This is fine because it is a numpy array now 

Solution If y is a flat list then convert it into a numpy first

y = np.array([i[1] for i in dataset])  #label for the data

If y is a nested list then

y = np.array([np.array(i[1]) for i in dataset])  #label for the data

Post a Comment for "Typeerror: Only Integer Scalar Arrays Can Be Converted To A Scalar Index , While Trying Kfold Cv"