python - 输入操作数 1 在其核心维度 0 中存在不匹配,具有 gufunc 签名 (n?,k),(k,m?)->(n?,m?)(大小 133896 与 133809 不同)
问题描述
我正在尝试使用 predict 函数来获取模型的输出。
我将 coo 矩阵 (x_test) 转换为 numpy(x_test_final) 并打印了它的形状。现在我正在尝试使用预测功能。
def predict1():
str_features = [str(x) for x in request.form.values()]
description= process(str_features[0])
x1_tfidf_load_sub = pickle.load(open("vocab1.pickle", 'rb'))
x2_tfidf_load_sub = pickle.load(open("vocab2.pickle", 'rb'))
description= [description]
closure= [str_features[1]]
tfidf_vectorizer1 = TfidfVectorizer(vocabulary=x1_tfidf_load_sub,use_idf=False, norm=None)
X1_test = tfidf_vectorizer1.fit_transform(description)
tfidf_vectorizer2 = TfidfVectorizer(vocabulary=x2_tfidf_load_sub,use_idf=False, norm=None)
X2_test = tfidf_vectorizer2.fit_transform(closure)
x_test = hstack((X1_test, X2_test))
x_test_final=x_test.toarray()
print('###########')
print(x_test_final.shape)
print('###########')
prediction = model.predict(x_test_final)
但我收到以下错误:
###########
(1, 133809)
###########
127.0.0.1 - - [04/May/2020 11:38:59] "[35m[1mPOST /predict HTTP/1.1[0m" 500 -
Traceback (most recent call last):
File "C:\Users\Pratiksha_S\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask\app.py", line 2464, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\Pratiksha_S\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask\app.py", line 2450, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\Pratiksha_S\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask\app.py", line 1867, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\Pratiksha_S\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\Pratiksha_S\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask\app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\Pratiksha_S\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\Pratiksha_S\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask\app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\Pratiksha_S\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\Pratiksha_S\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\Pratiksha_S\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask\app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\Pratiksha_S\Desktop\Deployment-flask-master\Deployment-flask-master\app.py", line 69, in predict1
prediction = model.predict(x_test_final)
File "C:\Users\Pratiksha_S\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\sklearn\naive_bayes.py", line 77, in predict
jll = self._joint_log_likelihood(X)
File "C:\Users\Pratiksha_S\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\sklearn\naive_bayes.py", line 770, in _joint_log_likelihood
return (safe_sparse_dot(X, self.feature_log_prob_.T) +
File "C:\Users\Pratiksha_S\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\sklearn\utils\extmath.py", line 151, in safe_sparse_dot
ret = a @ b
ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 133896 is different from 133809)
127.0.0.1 - - [04/May/2020 11:38:59] "[37mGET /predict?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1[0m" 200 -
127.0.0.1 - - [04/May/2020 11:38:59] "[37mGET /predict?__debugger__=yes&cmd=resource&f=jquery.js HTTP/1.1[0m" 200 -
127.0.0.1 - - [04/May/2020 11:38:59] "[37mGET /predict?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1[0m" 200 -
127.0.0.1 - - [04/May/2020 11:38:59] "[37mGET /predict?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1[0m" 200 -
127.0.0.1 - - [04/May/2020 11:38:59] "[37mGET /predict?__debugger__=yes&cmd=resource&f=ubuntu.ttf HTTP/1.1[0m" 200 -
133896的大小是多少?为什么会输出这个错误?
我在这里使用的模型是多项朴素贝叶斯。当我在 Jupyter Notebook 中运行这个模型时,它工作得非常好。当我导入泡菜文件并在我的烧瓶代码中使用它时,我收到了这个错误。
解决方案
推荐阅读
- office-ui-fabric - 过滤器详情列表
- java - 在 Hybris 中应用的促销活动中获取产品信息
- php - Jquery/AJAX 在 php 中处理长任务时输出数据
- java - Minecraft 插件 scheduleSyncDelayedTask 错误
- php - AngularJS POST 请求向同一个 PHP 脚本发送和接收数据
- github - github forks过滤器搜索不起作用
- java - 如何在使用出站网关上传文件之前检查 aws s3 存储桶是否可用
- python - 从元组列表构建逻辑表达式
- javascript - React Component onClick 方法不评估括号属性访问器
- vba - 删除 VBA 模块