python - 拟合 svm 模型 errorValueError: could not convert string to float: '[array([0.30067509, 0.11679184, 0.01250501, 等等
问题描述
import pickle
from sklearn import svm
from sklearn.svm import LinearSVC
import numpy
def train_svm(features, labels, reg_param, kernel_type):
clf = svm.SVC(C = reg_param, kernel = kernel_type)
svm_model = clf.fit(features, labels)
print("fitting model done!")
return svm_model
features_of_images = pickle.load(open("/Users/15195/Desktop/ece613/ped_features.p", 'rb'))
labels_of_images = pickle.load(open("/Users/15195/Desktop/ece613/peds_feature_to_label.p", 'rb'))
svm_model = train_svm(features_of_images, labels_of_images, 0.01,'linear')
pickle.dump(svm_model, open("/Users/15195/Desktop/ece613/trained_svm_model.p", 'wb'))
解决方案
看起来您的泡菜文件保存为字符串,而不是浮点数组。SKlearn 正在尝试将字符串用作浮点数组,但它失败了,因为您的字符串是: ["array([0.30067509, 0.11679184, 0.01250501 ..
看起来您有一个作为浮点数组的功能列表,但未能对其进行腌制。
因此,最好也看到酸洗部分。有关您的设置的更多信息可能会有所帮助
推荐阅读
- html - DIV 元素在其余 div 元素下方对齐
- c - C语言printf函数及输出问题
- javascript - Iframe 的 SRC 中的 ID 信息
- java - SpringBoot - Message.properties 不显示法语特殊字符
- python - 包含组的元素列表的代理列表
- reactjs - window.ethereum.request get_balance 方法,如何获取特定token的token数量?
- .net - 如何使用数据库日期而不是静态数据登录
- python - Django - 更改 html 文件时不更新 StatReloader
- javascript - 如何根据Angular中的其他选择字段设置另一个字段值?
- image - 使用工业相机镜头时,像暗光这样的图像像素呈周期性是什么原因?