会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133818个问题

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回归 6811楼


QQ截图20200510185301.png

"""测试一个经典的GUI程序的写法,使用面向对象我的方式"""
from tkinter import *
from tkinter import messagebox
class Application(Frame):
    """一个经典的GUI程序类的写法"""
    def __init__(self,master=None):
        super().__init__(master)
        self.master = master
        self.pack()

    def createWidget(self):
        """创建组件"""
        self.btn01 =Button(self)
        self.btn01["text"]="点击送花"
        self.btn01.pack()
        self.btn01["command"]=self.songhua

        #创建一个退出按钮
        self.btnQuit=Button(self,text="退出",command=root.destroy)
        self.btnQuit.pack()
    def songhua(self):
        messagebox.showinfo("送花","送你999花啊")


if __name__=='__maiin__':

root = Tk()
root.geometry("400x100+200+300")
root.title("一个经典的GUI类的测试")
app=Application(master=root)
root.mainloop()


Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 6812楼
JAVA 全系列/第四阶段:数据库与AI协同技术实战/Oracle 数据库的使用 6814楼

Enter password: ************
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 25
Server version: 5.7.36-log MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create table departments(department_id int,department_name varchar(30),location_id int);
ERROR 1046 (3D000): No database selected
mysql> create database emp default character set utf8;
Query OK, 1 row affected (0.00 sec)

mysql> use database;
ERROR 1049 (42000): Unknown database 'database'
mysql> use emp;
Database changed
mysql> create table bjsxt (employee_id int,employee_name varchar(10),employee_salary float98,2));
    ->
    -> create table bjsxt (employee_id int,employee_name varchar(10),employee_salary float(8,2));
    -> use emp;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'float98,2));

create table bjsxt (employee_id int,employee_name varchar(10' at line 1
mysql> create table bjsxt (employee_id int,employee_name varchar(10),employee_salary float(8,2));
Query OK, 0 rows affected (0.03 sec)

mysql> create   table    departments(department_id int,department_name varchar(30),location_id int);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(30),location_id int)' at line 1
mysql> use emp;
Database changed
mysql> create   table    departments(department_id int,department_name varchar(30),location_id int);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(30),location_id int)' at line 1
mysql> show tables;
+---------------+
| Tables_in_emp |
+---------------+
| bjsxt         |
+---------------+
1 row in set (0.00 sec)

mysql> use emp;
Database changed
mysql> create table departments(department_id int,department_name varchar(30),location_id int);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(30),location_id int)' at line 1
mysql> show tables;
+---------------+
| Tables_in_emp |
+---------------+
| bjsxt         |
+---------------+
1 row in set (0.00 sec)

mysql>  create table departments(department_id int,department_name varchar(30),location_id int);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(30),location_id int)' at line 1
mysql> show tables;
+---------------+
| Tables_in_emp |
+---------------+
| bjsxt         |
+---------------+
1 row in set (0.00 sec)

mysql>

我这里创建第二个表时,系统提示错误,show tables不出意外,果然只有第一个表,找不出错误点在哪?63、.png



Python 全系列/第六阶段:数据库与AI协同技术实战/MySQL数据库的使用 6817楼
JAVA 全系列/第六阶段:JavaWeb开发/Web实战案例 6818楼
Python 全系列/第一阶段:AI驱动的Python编程/序列 6825楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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