会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133494个问题
JAVA 全系列/第六阶段:JavaWeb开发/Ajax技术详解(旧) 12886楼

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.

请老师看看为啥创建模型这里报错了

Python 全系列/第二十三阶段:人工智能基础_机器学习理论和实战(旧)/Softmax回归 12888楼

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/sigmoid/asdsada.py
C:\Users\LENOVO\PycharmProjects\ai_tensorflow2.6\sigmoid\asdsada.py:20: 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\sigmoid\asdsada.py", line 25, 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.

进程已结束,退出代码1

请老师帮我看看为啥报错了

Python 全系列/第二十三阶段:人工智能基础_机器学习理论和实战(旧)/Softmax回归 12889楼
JAVA 全系列/第九阶段:Spring Boot实战/Spring Boot 12890楼
Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/Flask数据库 12891楼
JAVA 全系列/第九阶段:Spring Boot实战/Spring Boot 12892楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 12897楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 12898楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 12899楼
Python 全系列/第十六阶段:Python 爬虫开发/scrapy框架使用(旧) 12900楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637