Python scikit-learn SVM Classifier “ValueError: Found array with dim 3. Expected <= 2”

前端 未结 2 518
囚心锁ツ
囚心锁ツ 2020-12-10 13:47

I am trying to implement SVM Classifier over MNIST dataset. As my parameters are 3 dimensional its throwing the following error:

ValueError: Found array with         


        
2条回答
  •  一个人的身影
    2020-12-10 14:20

    One option for fixing the problem would be to reshape the input data into a 2-dimensional array.

    Let's assume that your training data consists of 10 images which are each represented as an 3x3 matrix and therefore your input data is 3-dimensional.

    [ [[1,2,3],   [[1,2,3],           [
       [4,5,6],    [4,5,6],            image 10 
       [7,8,9]] ,  [7,8,9]]  , ... ,           ] ]
    

    We can turn each image into an array of 9 elements in order to convert the dataset into 2-dimensions.

    dataset_size = len(training_images)
    TwoDim_dataset = dataset.reshape(dataset_size,-1)
    

    This would turn the data into the following shape:

    [ [1,2,3,4,5,6,7,8,9]  ,  [1,2,3,4,5,6,7,8,9]  , ... ,  [image 10] ]
    

提交回复
热议问题