pandas - ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0. 当从不和谐消息中获取预测数据时
问题描述
当我执行以下代码时,我收到错误:
ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 21459 is different from 1)
不和谐代码:
import discord
import joblib
from sklearn.preprocessing import OrdinalEncoder
import numpy as np
intents = discord.Intents().all()
client = discord.Client(intents=intents)
loaded_model = joblib.load("finalized_model.sav")
@client.event
async def on_ready():
print("im ready")
@client.event
async def on_message(message):
enc1 = OrdinalEncoder()
text = message.content
array = np.array(text)
array = array.reshape(1, -1)
enc1.fit(array)
await message.channel.send(loaded_model.predict(enc1.transform(array)))
client.run("the bot token")
保存训练模型的程序:
from sklearn.linear_model import LinearRegression
import pandas as pd
from joblib import parallel_backend
from sklearn.preprocessing import OrdinalEncoder
import joblib
import numpy as np
with parallel_backend('threading', n_jobs=1):
enc1 = OrdinalEncoder()
enc2 = OrdinalEncoder()
firstLine = True
model = LinearRegression()
df = pd.read_csv("Emotion_final.csv")
X = np.array(df["Text"]).reshape(1, -1)
y = np.array(df["Emotion"]).reshape(1, -1)
enc1.fit(X)
enc2.fit(y)
model.fit(enc1.transform(X), enc2.transform(y))
filename = 'finalized_model.sav'
joblib.dump(model, filename)
解决方案
推荐阅读
- python - Jenkins:如何避免“在处理上述异常期间,发生另一个异常”错误
- reactjs - 在 NextJS 中使用绝对导入后 VSCode 自动导入不起作用
- java - 为什么当我在 main() 中创建子类时,超类的构造函数会自动执行?
- javascript - “执行者”和传递给 then() 方法的函数之间有什么关系(如果有的话)?
- ffmpeg - 流式传输到 facebook rtmps 会导致 TLS 连接错误
- swift - 无法在 Xcode 中启用使用 Apple 登录
- android - 如何为 android API 22 编译 opencv 库
- python - Python:按其他数组排列数组
- android - 在传统的 android ViewPager 中滚动 LazyRow 的问题
- r - 将 SPSS (.sav) 数据集读入 R 并出现错误