import pickle
import numpy as np
from sklearn.linear_model import LogisticRegression
X = []
Y = []
genre_list = ['blues', 'classical', 'country', "disco", 'hiphop', 'jazz', 'metal']
for g in genre_list:
for n in range(100):
rad = "d:/BaiduNetdiskDownload/trainset/" +g+'.'+str(n).zfill(5)+'.fft'+'.npy'
fft_features = np.load(rad)
X.append(fft_features)
Y.append(genre_list.index(g))
X = np.array(X)
Y = np.array(Y)
model = LogisticRegression()
model.fit(X,Y)
output = open('model.pkl', 'wb')
pickle.dump(model, output)
output.close()
D:\anaconda\envs\TF2.1\python.exe C:/Users/LENOVO/PycharmProjects/ai_tensorflow2.6/music_classify/music_classifier.py
C:\Users\LENOVO\PycharmProjects\ai_tensorflow2.6\music_classify\music_classifier.py:14: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
X = np.array(X)
TypeError: only size-1 arrays can be converted to Python scalars
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\LENOVO\PycharmProjects\ai_tensorflow2.6\music_classify\music_classifier.py", line 17, in <module>
model.fit(X,Y)
File "D:\anaconda\envs\TF2.1\lib\site-packages\sklearn\linear_model\_logistic.py", line 1508, in fit
X, y = self._validate_data(
File "D:\anaconda\envs\TF2.1\lib\site-packages\sklearn\base.py", line 581, in _validate_data
X, y = check_X_y(X, y, **check_params)
File "D:\anaconda\envs\TF2.1\lib\site-packages\sklearn\utils\validation.py", line 964, in check_X_y
X = check_array(
File "D:\anaconda\envs\TF2.1\lib\site-packages\sklearn\utils\validation.py", line 746, in check_array
array = np.asarray(array, order=order, dtype=dtype)
File "D:\anaconda\envs\TF2.1\lib\site-packages\numpy\core\_asarray.py", line 83, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: setting an array element with a sequence.
请老师看看为啥创建模型这里报错了