首页 > 解决方案 > 拟合 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'))

标签: pythonmachine-learningimage-processingcomputer-vision

解决方案


看起来您的泡菜文件保存为字符串,而不是浮点数组。SKlearn 正在尝试将字符串用作浮点数组,但它失败了,因为您的字符串是: ["array([0.30067509, 0.11679184, 0.01250501 ..

看起来您有一个作为浮点数组的功能列表,但未能对其进行腌制。

因此,最好也看到酸洗部分。有关您的设置的更多信息可能会有所帮助


推荐阅读