2021年4月5日星期一

How to feed a nested array into an SVM model

my question is the following:

I have an array that has feature vectors that correspond to several audio files. So if for example there are 10 audio files than this array would have length 10.

I have a feature that is itself a list (this list comprises the information of a specific feature of the audio file) and for a given audio file the feature vector looks like this:

array([0.03861840871664194, 187.72393405210002, 62.59881268743305,         0.2911392405063291,         array([4963.40332031, 3229.98046875, 2691.65039062, 3208.44726562,         4338.94042969, 4220.5078125 , 4166.67480469, 4801.90429688,         5555.56640625, 5910.86425781, 6115.4296875 , 5706.29882812,         4984.93652344, 2756.25      , 1991.82128906, 2551.68457031,         2734.71679688, 2906.98242188, 3143.84765625, 3219.21386719,         3186.9140625 , 3165.38085938, 3068.48144531, 2465.55175781,         2110.25390625, 2508.61816406, 2993.11523438, 3843.67675781,         4715.77148438, 5652.46582031, 5480.20019531, 5792.43164062,         5932.39746094, 6244.62890625, 6072.36328125, 6201.5625    ,         6158.49609375, 6201.5625    , 6233.86230469, 6061.59667969])],        dtype=object)  

Now when I try to feed this data into the svm model:

from sklearn import svm  from sklearn.model_selection import train_test_split  from sklearn.metrics import confusion_matrix  import matplotlib.pyplot as plt      X_train, X_val, y_train, y_val = train_test_split(X,y,test_size=0.3)    model  = svm.SVC()  model.fit(X_train,y_train)    yt_p = model.predict(X_train)  yv_p = model.predict(X_val)  

I get this error ValueError: setting an array element with a sequence.

How can I structure my feature vector in order to be able to feed it to the svm?

https://stackoverflow.com/questions/66961525/how-to-feed-a-nested-array-into-an-svm-model April 06, 2021 at 09:07AM

没有评论:

发表评论