I've got this "error: (-215) _samples.type() == CV_32F in function cv::ml::SVMImpl::do_train",even if there is no data of the type of CV_32F
1 | initial version |
I've got this "error: (-215) _samples.type() == CV_32F in function cv::ml::SVMImpl::do_train",even if there is no data of the type of CV_32F
2 | No.2 Revision |
I've got this "error: (-215) _samples.type() == CV_32F in function cv::ml::SVMImpl::do_train",even if there is no data of the type of CV_32F
import numpy as np import cv2 as cv
pid,labels,pcl,nam,sex,age,sis,pac,tic,fare,cab,emb=np.loadtxt('train.csv' ,dtype=str,delimiter=',',usecols=(0,1,2,3,4,5,6,7,8,9,10,11),unpack=True) pid=pid[1:];labels=labels[1:];pcl=pcl[1:];nam=nam[1:]; sex=sex[1:];age=age[1:];sis=sis[1:];pac=pac[1:];tic=tic[1:];fare=fare[1:]; cab=cab[1:];emb=emb[1:]; age[np.where(age=='')]='18' cab[np.where(cab=='')]='999999' a_,b=np.loadtxt(nam,dtype=str,delimiter='-',unpack=True) nam,a_=np.loadtxt(b,dtype=str,delimiter='.',unpack=True) a_,nam=np.loadtxt(nam,dtype=str,delimiter=' ',unpack=True) nam[np.where(nam=='Miss')]=1 nam[np.where(nam=='Mr')]=2 nam[np.where(nam=='Mrs')]=3 nam[np.where(nam=='Master')]=4 nam[np.where(nam=='Rev')]=5 nam[np.where(nam=='Col')]=6 nam[np.where(nam=='Dr')]=7 nam[np.where(nam=='Mlle')]=8 nam[np.where(nam=='Lady')]=9 nam[np.where(nam=='Ms')]=10 nam[np.where(nam=='Major')]=11 nam[np.where(nam=='Sir')]=12 nam[np.where(nam=='Capt')]=13 nam[np.where(nam=='Jonkheer')]=14 nam[np.where(nam=='Mme')]=15 nam[np.where(nam=='Don')]=16 nam[np.where(nam=='the')]=17 sex[np.where(sex=='male')]=1 sex[np.where(sex=='female')]=0 emb[np.where(emb=='')]='S' emb[np.where(emb=='C')]=1 emb[np.where(emb=='S')]=2 emb[np.where(emb=='Q')]=3 pid=pid.astype(int) labels=labels.astype(int)
pcl=pcl.astype(int) nam=nam.astype(int) sex=sex.astype(int) age=age.astype(float) sis=sis.astype(int) pac=pac.astype(int) fare=fare.astype(float) emb=emb.astype(int) traindata=np.array([pcl,nam,sex,age,sis,pac,fare,emb]) traindata=traindata.astype(float) labels=labels.astype(float)
svm=cv.ml.SVM_create() svm.train(traindata,cv.ml.ROW_SAMPLE,labels)
3 | No.3 Revision |
I've got this "error: (-215) _samples.type() == CV_32F in function cv::ml::SVMImpl::do_train",even if there is no data of the type of CV_32F
import numpy as np
import cv2 as 4 | No.4 Revision |
I've got this "error: (-215) _samples.type() == CV_32F in function cv::ml::SVMImpl::do_train",even if there is no data of the type of CV_32F
import numpy as np
import cv2 as cv
#preliminary of datas
pid,labels,pcl,nam,sex,age,sis,pac,tic,fare,cab,emb=np.loadtxt('train.csv'
,dtype=str,delimiter=',',usecols=(0,1,2,3,4,5,6,7,8,9,10,11),unpack=True)
pid=pid[1:];labels=labels[1:];pcl=pcl[1:];nam=nam[1:];
sex=sex[1:];age=age[1:];sis=sis[1:];pac=pac[1:];tic=tic[1:];fare=fare[1:];
cab=cab[1:];emb=emb[1:];
age[np.where(age=='')]='18'
cab[np.where(cab=='')]='999999'
a_,b=np.loadtxt(nam,dtype=str,delimiter='-',unpack=True)
nam,a_=np.loadtxt(b,dtype=str,delimiter='.',unpack=True)
a_,nam=np.loadtxt(nam,dtype=str,delimiter=' ',unpack=True)
nam[np.where(nam=='Miss')]=1
nam[np.where(nam=='Mr')]=2
nam[np.where(nam=='Mrs')]=3
nam[np.where(nam=='Master')]=4
nam[np.where(nam=='Rev')]=5
nam[np.where(nam=='Col')]=6
nam[np.where(nam=='Dr')]=7
nam[np.where(nam=='Mlle')]=8
nam[np.where(nam=='Lady')]=9
nam[np.where(nam=='Ms')]=10
nam[np.where(nam=='Major')]=11
nam[np.where(nam=='Sir')]=12
nam[np.where(nam=='Capt')]=13
nam[np.where(nam=='Jonkheer')]=14
nam[np.where(nam=='Mme')]=15
nam[np.where(nam=='Don')]=16
nam[np.where(nam=='the')]=17
sex[np.where(sex=='male')]=1
sex[np.where(sex=='female')]=0
emb[np.where(emb=='')]='S'
emb[np.where(emb=='C')]=1
emb[np.where(emb=='S')]=2
emb[np.where(emb=='Q')]=3
pid=pid.astype(int)
labels=labels.astype(int)
#features
pcl=pcl.astype(int)
nam=nam.astype(int)
sex=sex.astype(int)
age=age.astype(float)
sis=sis.astype(int)
pac=pac.astype(int)
fare=fare.astype(float)
emb=emb.astype(int)
traindata=np.array([pcl,nam,sex,age,sis,pac,fare,emb])
traindata=traindata.astype(float)
labels=labels.astype(float)
#building SVM
svm=cv.ml.SVM_create()
svm.train(traindata,cv.ml.ROW_SAMPLE,labels)