python - 尝试在训练模型上使用 predict() 函数时出现异常
问题描述
在用 pickle 保存我的模型之前,模型运行良好,而且我得到了0.80
精确度。现在,当我尝试使用该函数predict()
获取图像的预测类时,出现以下异常:
ValueError: shapes (12,1) and (12,) not aligned: 1 (dim 1) != 12 (dim 0)
请注意,我使用了对训练集进行的所有预处理,并且f_scaled
每行的大小相同,X_train
其中包含 12 个特征
features = feature_extraction(image_path)
scaler = MinMaxScaler()
f_scaled = scaler.fit_transform(features.reshape(-1, 1))
psvm_model = pickle.load(open('C:/Users/DELL/Desktop/SkinCancerDataset/psvmModel.sav', 'rb'))
print("prediction:", psvm_model.predict(np.squeeze(f_scaled).reshape(-1, 1)))
当我删除reshape(-1, 1)
内部预测函数时,我得到以下结果:
[1 1 1 1 1 1 1 1 1 1 1 1]
我猜:这意味着f_scalar
数组中的每个标量都被视为一个条目,这解释了prediction (1, 12)
它应该只给出一个标签范围[0,2]
这就是数据 ( f_scaled
) 在 pyCharm 中的显示方式:
解决方案
推荐阅读
- html - btn-group 下拉菜单不起作用,但 nav-item 下拉菜单在 Angular 中使用 bootstrap
- python-3.x - 如何为 grpc 单元测试(python)创建模拟上下文
- pandas - 在前几天随机分配值
- elasticsearch - 在 KIBANA Elasticsearch 中创建规则时字段变为空白
- reactjs - 反应钩子条件 useState - JSON.parse(...) 为空
- javascript - 如何在 CSS 中 max-width=1000px 的媒体查询中放置菜单栏
- elasticsearch - 如何将 json schema draft 7 (elasticsearch api) 转换为 swagger 2.0 (outsystems)?
- visual-studio-code - 如何将 vscode 终端更改为默认下拉样式
- scala - Xlint:在 Play 框架与隐式中未使用
- javascript - 在 Sanity Io React 中循环遍历数组