SVM分类和从txt加载数据

时间:2018-08-10 23:17:04

标签: python numpy scikit-learn

我想创建一个图像识别应用程序,在该应用程序中,用户将在文件中插入图像,并且如果图像属于1级通过或2级失败,则将显示python应用程序(在python 3中使用svm进行分类)

我用过sklearn。我正在尝试的是加载txt文件(包括提取的特征及其标签的数组),然后将这些数据包括在svm中。不过,我收到以下错误

  

ValueError:无法将字符串转换为float:'0.01982988 0.04777778 0.04508372 0.55393064]'

有人可以帮忙吗?

到目前为止,我的代码是:

nullptr

train.txt文件为:

from pyimagesearch.localbinarypatterns import LocalBinaryPatterns
from sklearn.svm import LinearSVC
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC  
from imutils import paths
import argparse
import cv2
import csv
import numpy as np
import pandas as pd

ap = argparse.ArgumentParser()
ap.add_argument("-e", "--testing", required=True, 
help="path to the tesitng images")
args = vars(ap.parse_args())


df = pd.read_csv('train.txt', sep="[;,]", engine='python')
df.head()  
X = df.drop('Class', axis=1)  
y = df['Class'] 
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.20)  
svclassifier = SVC(kernel='linear')  
svclassifier.fit(X_train, y_train)

0 个答案:

没有答案