svm

Why does classifier.predict() method expects the number of features in the test data to be the same as in training data?

↘锁芯ラ 提交于 2019-12-05 13:13:00
I am trying to build a simple SVM document classifier using scikit-learn and I am using the following code : import os import numpy as np import scipy.sparse as sp from sklearn.metrics import accuracy_score from sklearn import svm from sklearn.metrics import classification_report from sklearn.feature_extraction.text import CountVectorizer from sklearn.feature_extraction.text import TfidfTransformer from sklearn.feature_extraction.text import TfidfVectorizer from sklearn import cross_validation from sklearn.datasets import load_svmlight_file clf=svm.SVC() path="C:\\Python27" f1=[] f2=[] data2=[

Getting an error “(subscript) logical subscript too long” while training SVM from e1071 package in R

╄→尐↘猪︶ㄣ 提交于 2019-12-05 12:35:54
问题 I am training svm using my traindata. (e1071 package in R). Following is the information about my data. > str(train) 'data.frame': 891 obs. of 10 variables: $ survived: int 0 1 1 1 0 0 0 0 1 1 ... $ pclass : int 3 1 3 1 3 3 1 3 3 2 ... $ name : Factor w/ 15 levels "capt","col","countess",..: 12 13 9 13 12 12 12 8 13 13 $ sex : Factor w/ 2 levels "female","male": 2 1 1 1 2 2 2 2 1 1 ... $ age : num 22 38 26 35 35 ... $ ticket : Factor w/ 533 levels "110152","110413",..: 516 522 531 50 473 276

Time series prediction using support vector regression

时光怂恿深爱的人放手 提交于 2019-12-05 11:07:34
I've been trying to implement time series prediction tool using support vector regression in python language. I use SVR module from scikit-learn for non-linear Support vector regression. But I have serious problem with prediction of future events. The regression line fits the original function great (from known data) but as soon as I want to predict future steps, it returns value from the last known step. My code looks like this: import numpy as np from matplotlib import pyplot as plt from sklearn.svm import SVR X = np.arange(0,100) Y = np.sin(X) svr_rbf = SVR(kernel='rbf', C=1e5, gamma=1e5) y

Import trained SVM from scikit-learn to OpenCV

﹥>﹥吖頭↗ 提交于 2019-12-05 10:25:40
I'm porting an algorithm that uses a Support Vector Machine from Python (using scikit-learn) to C++ (using the machine learning library of OpenCV). I have access to the trained SVM in Python, and I can import SVM model parameters from an XML file into OpenCV. Since the SVM implementation of both scikit-learn and OpenCV is based on LibSVM, I think it should be possible to use the parameters of the trained scikit SVM in OpenCV. The example below shows an XML file which can be used to initialize an SVM in OpenCV: <?xml version="1.0"?> <opencv_storage> <my_svm type_id="opencv-ml-svm"> <svm_type>C

LibSVM turns all my training vectors into support vectors, why?

空扰寡人 提交于 2019-12-05 10:19:53
I am trying to use SVM for News article classification. I created a table that contains the features (unique words found in the documents) as rows. I created weight vectors mapping with these features. i.e if the article has a word that is part of the feature vector table that location is marked as 1 or else 0 . Ex:- Training sample generated... 1 1:1 2:1 3:1 4:1 5:1 6:1 7:1 8:1 9:1 10:1 11:1 12:1 13:1 14:1 15:1 16:1 17:1 18:1 19:1 20:1 21:1 22:1 23:1 24:1 25:1 26:1 27:1 28:1 29:1 30:1 As this is the first document all the features are present. I am using 1 , 0 as class labels. I am using svm

AttributeError: 'module' object has no attribute 'SVM_LINEAR'

拟墨画扇 提交于 2019-12-05 09:15:03
I have installed open cv 3.0 then i installed libsvm.Then i addded that to my pycharm packages.But still when typing this code svm_params = dict( kernel_type = cv2.SVM_LINEAR, svm_type = cv2.SVM_C_SVC, C=2.67, gamma=5.383 ) it shows this error svm_params = dict( kernel_type = cv2.SVM_LINEAR, AttributeError: 'module' object has no attribute 'SVM_LINEAR' i tried import libsvm but it didn't work.please help. Is opencv 3.0 is ok should i go back to 2.4? You are accessing SVM_LINEAR with cv2 , but SVM_LINEAR is attribute of ml . You have to access SVM_LINEAR as cv2.ml.SVM_LINEAR 来源: https:/

svm 手写数字识别 MNIST数据集

萝らか妹 提交于 2019-12-05 09:06:02
利用SVM(支持向量机)和MNIST库在OpenCV环境下实现手写数字0~9的识别 六万张训练生成SVM的XML文件用了564秒,随后用训练的结果进行训练数据的测试,一万张测试图片正确的识别个数为9833,错误率为1.67%。 SVM学习笔记(二)----手写数字识别 参数选择为C=100.0, kernel=’rbf’, gamma=0.03时,预测的准确度就已经高达98.5%了。 来源: CSDN 作者: Min's Blog 链接: https://blog.csdn.net/weixin_36899784/article/details/80245592

CNN提取图片特征,之后用SVM分类

眉间皱痕 提交于 2019-12-05 08:06:09
先用CNN提取特征,之后用SVM分类,平台是TensorFlow 1.3.0-rc0,python3.6 这个是我的一个小小的测试,下面这个链接是我主要参考的, 在实现过程中,本来想使用 vgg16 或者 VGG19 做迁移来提取特征 ,但是担心自己的算力不够,还有就是 UCI 手写数据集本来就是一个不大的数据集,使用 vgg16 或 vgg19 有点杀鸡用牛刀的感觉。于是放弃做迁移。 我的代码主要是基于下面链接来的。参考链接 点击打开链接 这个代码主要是,通过一个CNN网络,在网络的第一个全连接层也就h_fc1得到的一个一维的256的一个特征向量,将这个特征向量作为的svm的输入。主要的操作是在代码行的140-146. 同时代码也实现了CNN的过程(读一下代码就知道)。 如果你要是知道你的CNN的结构,然后就知道在全连接层输出的其实就是一个特征向量。直接用这个特征向量简单处理输入到svm中就可以。 具体的参考论文和代码数据集等, 百度网盘 来源: CSDN 作者: 邓乐乐 链接: https://blog.csdn.net/qq_27756361/article/details/80479278

OpenCV 3.1.0: Save and load trained SVMs

家住魔仙堡 提交于 2019-12-05 07:01:57
问题 At the moment I am trying to train different SVMs for the recognition of different emotions. So for example to recognize the emotion happy I train a SVM with images of happy people as positives and images where people express other emotions such as anger, fear, disgust, ... as negatives. The images are stored in a database that I have partitioned in a training section and testing section. When I have trained the SVMs, I immediatly use them to test the accuracy on the test images of the

Support Vector Machine works on Training-set but not on Test-set in R (using e1071)

ぃ、小莉子 提交于 2019-12-05 07:00:13
问题 I'm using a support vector machine for my document classification task! it classifies all my Articles in the training-set, but fails to classify the ones in my test-set! trainDTM is the document term matrix of my training-set. testDTM is the one for the test-set. here's my (not so beautiful) code: # create data.frame with labelled sentences labeled <- as.data.frame(read.xlsx("C:\\Users\\LABELED.xlsx", 1, header=T)) # create training set and test set traindata <- as.data.frame(labeled[1:700,c(