我已使用以下代码导入数据,但问题是如何使用它来实现svm
。
from xlrd import open_workbook
import nltk
rb = open_workbook('/Users/tejeshwar/Downloads/Defect-Data.xlsx')
sheet = rb.sheet_by_index(0)
data = ()
for row_index in xrange(1, sheet.nrows): #train using 500
temp,add = (),()
desc,cat = 0,0 #trial
for col_index in xrange(sheet.ncols):
if col_index==2:
#print col_index
desc = sheet.cell(row_index,col_index).value
#print desc
#print cellname(row_index,col_index)
desc = "'" + desc
#temp +=(desc,)
#print temp
elif col_index==5:
#print col_index
cat = sheet.cell(row_index,col_index).value
#print cat
#print cellname(row_index,col_index)
cat = "'" + cat + "'"
add = add + (desc,cat)
#print (add)
data = data + (add,)
print 'done'
training_data = list(data)`
其中desc是描述而cat是类别
如果给出应该预测的描述或将其归类为类别,我必须以某种方式训练模型