私は22行から、次のエラーを取得NB分類器とイムをテストするために(下)いくつかのサンプルコードを使用しています:csv.Error:改行文字
_csv.Error: new-line character seen in unquoted field - do you need to open the file in universal-newline mode?
これは、CSVのサンプル列でありますファイル:コードの
b8:27:eb:38:72:a7,df598b5eb8f4,5/9/16 14:47,154aec250ef6,-84,outside
サンプル:
from sklearn.preprocessing import LabelBinarizer
import numpy as np
from sklearn import naive_bayes
import csv
import random
from sklearn import metrics
import urllib
url = "example.com"
webpage = urllib.urlopen(url)
# download the file
#raw_data = urllib.urlopen(url)
datareader = csv.reader(webpage) #line 22 is this one
ct = 0;
for row in datareader:
ct = ct+1
webpage = urllib.urlopen(url)
datareader = csv.reader(webpage)
data = np.array(-1*np.ones((ct,6),float),object);
k=0;
for row in datareader:
data[k,:] = np.array(row)
k = k+1;
featnames = np.array(['unti','dongle','timestamp','tracker','rssi','label'],str)
keys = [[]]*np.size(data,1)
numdata = -1*np.ones_like(data);
for k in range(np.size(data,1)):
keys[k],garbage,numdata[:k] = np.unique(data[:,k],True,True)
numrows = np.size(numdata,0);
numcols = np.size(numdata,1);
numdata = np.array(numdata, int)
xdata = numdata[:,:-1]
ydata = numdata[:,-1]
lbin = LabelBinarizer();
for k in range(np.size(xdata,1)):
if k==0:
xdata_ml = lbin.fit_transform(xdata[:,k]);
else:
xdata_ml = np.hstack((xdata_ml,lbin.fit_transform(xdata[:,k])))
ydata_ml = lbin.fit_transform(ydata)
allIDX = np.arrange(numrows);
random.shuffle(allIDX);
holdout_number = numrows/10;
testIDX = allIDX[0:holdout_number];
trainIDX = allIDX[holdout_number:];
xtest = xdata_ml[testIDX,:];
xtrain = xdata_ml[trainIDX,:];
ytest = ydata[testIDX];
ytrain = ydata[trainIDX];
mnb = naive_bayes.MultinomialNB();
mnb.fit(xtrain,ytrain);
print "Classification accuracy of MNB =", mnb.score(xtest,ytest)
誰も私がエラーを見つけて修正を提案助けることができますか?
nope - macのAnaconda – DataGuy
hm ..奇妙な..あなたは 'dialect' kwargを追加しようとしましたか? – silviomoreto
はい私はそれを試してみました – DataGuy