在sklearn中解压缩naive_bayes.py的错误

时间:2015-03-10 07:06:46

标签: python scikit-learn

我将一个arff文件作为输入并读取它的数据部分以获取训练和测试实例。我现在打算做GaussiaNB,决策树等来训练我的数据并用于预测测试数据的类。 我尝试这样做时收到以下错误: 文件" /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/sklearn/naive_bayes.py",第152行,适合     n_samples,n_features = X.shape ValueError:需要多于1个值来解压缩

以下是我的代码的详细信息: 现在我已经将我的数据集减少到只有10个实例来调试问题。(训练大小:8,测试大小:2) 课程/标签:2(好的和坏的)(这是我想用上面提到的学习者预测的)

我的输入文件:

@RELATION petsc_data
@ATTRIBUTE lambda-max-by-magnitude-im NUMERIC
 @ATTRIBUTE right-bandwidth NUMERIC
@ATTRIBUTE avgdistfromdiag NUMERIC
@ATTRIBUTE symmetry NUMERIC
@ATTRIBUTE n-dummy-rows NUME RIC
@ATTRIBUTE blocksize NUMERIC
@ATTRIBUTE max-nnzeros-per-row NUMERIC
@ATTRIBUTE diag-definite NUMERIC
@ATTRIBUTE avgnnzprow NUMERIC
@ATTRIBUTE lambda-max-by-magnitude-re NUMERIC
@ATTRIBUTE ellipse-cy NUMERIC
@ATTRIBUTE nnzup NUMERIC
@ATTRIBUTE ruhe75-bound NUMERIC
@ATTRIBUTE avg-diag-dist NUMERIC
@ATTRIBUTE nnz NUMERIC
@ATTRIBUTE lambda-min-by-magnitude-re NUMERIC
@ATTRIBUTE lambda-max-by-im-part-im NUMERIC
@ATTRIBUTE left-bandwidth NUMERIC
@ATTRIBUTE norm1 NUMERIC
@ATTRIBUTE sigma-min NUMERIC
@ATTRIBUTE upband NUMERIC
@ATTRIBUTE n-struct-unsymm NUMERIC
@ATTRIBUTE lambda-min-by-magnitude-im NUMERIC
@ATTRIBUTE diagonal-average NUMERIC
@ATTRIBUTE diagonal-dominance NUMERIC
@ATTRIBUTE dummy-rows NUMERIC
@ATTRIBUTE ritz-values-r NUMERIC
@ATTRIBUTE symmetry-snorm NUMERIC
@ATTRIBUTE symmetry-fanorm NUMERIC
@ATTRIBUTE symmetry-fsnorm NUMERIC
@ATTRIBUTE colours NUMERIC
@ATTRIBUTE lambda-max-by-im-part-re NUMERIC
@ATTRIBUTE col-variability NUMERIC
@ATTRIBUTE trace-abs NUMERIC
@ATTRIBUTE ritz-values-c NUMERIC
@ATTRIBUTE nnzeros NUMERIC
@ATTRIBUTE diag-zerostart NUMERIC
@ATTRIBUTE loband NUMERIC
@ATTRIBUTE positive-fraction NUMERIC
@ATTRIBUTE trace NUMERIC
@ATTRIBUTE min-nnzeros-per-row NUMERIC
@ATTRIBUTE diagonal-sign NUMERIC
@ATTRIBUTE row-variability NUMERIC
@ATTRIBUTE nrows NUMERIC
@ATTRIBUTE lambda-max-by-real-part-im NUMERIC
@ATTRIBUTE colour-offsets NUMERIC
@ATTRIBUTE n-colours NUMERIC
@ATTRIBUTE relsymm NUMERIC
@ATTRIBUTE diagonal-variance NUMERIC
@ATTRIBUTE departure NUMERIC
@ATTRIBUTE nnzlow NUMERIC
@ATTRIBUTE n-nonzero-diags NUMERIC
@ATTRIBUTE sigma-max NUMERIC
@ATTRIBUTE dummy-rows-kind NUMERIC
@ATTRIBUTE kappa NUMERIC
@ATTRIBUTE n-ritz-values NUMERIC
@ATTRIBUTE colour-set-sizes NUMERIC
@ATTRIBUTE sigma-diag-dist NUMERIC
@ATTRIBUTE symmetry-anorm NUMERIC
@ATTRIBUTE ellipse-ax NUMERIC
@ATTRIBUTE ellipse-ay NUMERIC
@ATTRIBUTE ellipse-cx NUMERIC
@ATTRIBUTE normF NUMERIC
@ATTRIBUTE normInf NUMERIC
@ATTRIBUTE lee95-bound NUMERIC
@ATTRIBUTE lambda-max-by-real-part-re NUMERIC
@ATTRIBUTE nnzdia NUMERIC
@ATTRIBUTE trace-asquared NUMERIC
@ATTRIBUTE class {good,bad}
@DATA

?,864,4,?,84,224,36,?,4,2.871694,?,2118,0.0008016716,460.3435,5892,0.1818182,?,864,5.727397,0.0009837992,864,864,?,0.2580164,-1.0,?,?,5.727392,0.001581193,18.82156,?,2.871661,77.1378,314.78,?,5892,1154,864,0.8478261,314.78,1,1,77.1378,1220,?,?,5,0.8533605,0.2622148,0.002236145,2638,1601,2.871694,2,15767.48,46,?,475474.4,0.0007929995,1.935847,?,0.9358466,18.82156,5.727387,0.002236145,2.871694,1136,354.2513,bad

?,1801,6,?,12,76,1310,?,6,20.37621,?,5675,0.001032754,793.8216,11239,0.0003510933,?,1763,29.86749,0.001104271,1801,3320,?,0.02448411,-1.044254,?,?,29.88251,0.02161826,23.23519,?,20.37621,312.1821,44.38969,?,11239,1813,1763,0.6883117,44.38969,1,1,312.1821,1813,?,?,7,0.7046001,0.4466572,0.03032447,3763,3127,20.37621,2,284915.5,77,?,1328154.0,0.05763386,10.6881,?,9.688105,23.2352,29.9004,0.03057284,20.37621,1801,539.8737,bad

?,1800,6,?,12,76,1310,?,6,0.002150298,?,5581,0.001421109,792.7765,11107,0.0003513319,?,1763,2.957396,0.001492885,1800,3254,?,0.003899085,-1.072868,?,?,2.970288,0.02967123,4.579729,?,0.0006159784,295.84,7.069041,?,11107,1813,1763,0.7407407,7.069041,1,1,295.84,1813,?,?,7,0.7070316,0.03972554,0.04064811,3725,3123,1.610171,2,22432.44,81,?,1327519.0,0.1013244,1.30505,0.001032658,0.3050501,4.579824,2.99671,0.04196146,1.6101,1801,20.97304,bad

?,420,5,?,93,402,11,?,5,1.0,?,1000,?,244.4595,2796,-0.002928884,?,421,36627470000.0,?,420,476,?,52.27869,-72279810000.0,?,?,36139900000.0,74661510000.0,74661510000.0,?,0.5,17.79679,26714.41,?,2796,511,421,0.5055556,-26456.41,1,?,8.959519,511,?,?,7,0.8297568,799.2119,1.055873e+11,1374,74,?,?,153.0925,180,?,149749.0,36139900000.0,985536.2,21294.73,-0.2857214,1.055873e+11,72279810000.0,1.055873e+11,985535.8,422,1.812532e+13,bad

?,203,7,?,?,2,10,1,7,5.502378,?,1242,0.2296601,132.963,2860,0.3696691,?,203,8.459492,0.004077175,203,28,?,0.5420469,-2.078442,?,?,7.276228,2.224949,15.11089,?,5.502378,22.50512,216.8188,?,2860,400,203,0.952381,216.8188,2,2,22.50512,400,?,?,8,0.9902098,0.307282,3.146549,1218,27,5.732038,?,13183.07,42,?,43826.48,1.185615,2.751398,0.0005006479,2.75098,15.27381,6.325838,3.146553,5.502378,400,223.3886,bad

?,3,3,?,?,1,6,?,3,-10163.38,2.21192497951e-317,1498,?,1.5,3996,-5.004413,?,2,91554.69,?,3,998,?,2541.072,-101722.2,?,?,55944.83,886180.5,897028.1,?,4.510194,4.961678,2541072.0,?,3996,1000,2,0.16,-2541072.0,2,-2,1.255273,1000,?,?,4,0.7502503,2540.572,1253248.0,1498,6,?,?,4211.397,25,?,3.916667,45777.34,5082.587,2.21192497951e-317,-5078.077,1260942.0,101722.2,1253249.0,4.510194,1000,19343450000.0,bad

?,25,4,?,43,30,11,?,4,1.0,?,173,?,12.15152,536,-0.0004496203,?,32,6322411000.0,?,25,126,?,0.4515031,-18188610000.0,?,?,9094304000.0,10715030000.0,10715030000.0,?,0.5,17.85225,59.14691,?,536,131,32,0.5,58.85309,1,?,8.914829,131,?,?,6,0.7649254,0.4564953,15153350000.0,251,33,?,?,583.9601,180,?,426.7346,9094304000.0,119005.4,0.0006288902,-0.2509798,15153350000.0,18188610000.0,15153350000.0,119005.2,112,1.359304e+11,good

?,613,5,?,?,46,7,1,5,-0.7434779,?,1073,0.7456667,251.7556,5664,-0.7434779,?,170,1.00002,0.00643852,613,4557,?,0.1985578,-0.9999198,?,?,1.31816,10.99868,14.1318,?,0.9999465,6.747632,219.8035,?,5664,1107,170,0.8285714,219.8035,2,2,6.747632,1107,?,?,6,0.1954449,0.1780477,9.319442,3484,491,1.110239,?,1.331038,35,?,64291.71,0.99992,0.8723,0.8081785,0.1287807,17.90751,1.63631,15.55449,0.9999465,1107,78.73667,bad

?,?,3,?,1,1,9,1,3,5.0,?,?,0.5254622,169.5385,1089,3.0,?,282,7.0,1.891017,?,800,?,4.543253,1.0,?,?,7.0,15.74802,80.18105,?,5.0,0.7781513,1313.0,?,1089,289,282,1.0,1313.0,1,2,0.7781513,289,?,?,5,0.2653811,0.8639439,22.27106,800,91,6.968567,1,3.222206,103,?,122041.1,2.0,2.220928,1.56149,4.220523,81.71291,9.0,22.27106,5.0,289,6181.0,bad

?,421,10,?,?,15,41,?,10,0.6607435,?,2138,0.006626715,219.2716,4710,0.0001733472,?,421,0.9017877,0.006941337,421,?,?,0.03676872,-0.6178758,?,?,0.9017877,0.2322863,2.083392,?,0.6607435,14.44944,15.95762,?,4710,434,421,0.6097561,6.619194,4,?,14.44944,434,?,?,16,1.0,0.05632279,0.3283956,2138,475,0.6607441,?,2100.117,41,?,111615.9,0.07663028,0.3853627,0.003097666,0.2753808,2.096301,0.9017877,0.3285025,0.6607435,434,4.286565,bad

?,36,4,?,?,1,5,?,4,0.9595043,?,180,0.3898991,14.06897,876,0.9595043,?,14,1.00003,1.144799e-06,36,660,?,0.1693683,-1.000027,?,?,1.485479,9.211994,10.92025,?,0.9595043,2.012825,36.58355,?,876,216,14,0.5444444,36.58355,2,1,2.012825,216,?,?,4,0.2465753,0.3612919,13.00377,480,29,1.389959,?,8.079801,90,?,322.6492,1.000027,0.5652011,0.1484474,0.4348586,14.2868,1.970929,13.02773,1.000027,216,34.39097,good

?,1,3,?,?,1,5,?,3,-3.958133,?,399,1.006408,133.5,1201,0.0004378134,?,399,7.0,0.0009035044,1,3,?,1.995075,-5.02,?,?,5.0,3.006801,48.99961,?,0.0004378134,2.30103,798.03,?,1201,400,399,0.1190476,-797.97,2,?,2.60206,400,?,?,3,0.9975021,0.0983768,4.249774,402,6,5.004889,?,2625.836,42,?,106312.9,3.025,2.000875,0.002807219,-1.997605,49.09178,5.08,4.252258,0.0004378134,400,2391.921,good

?,101,3,?,?,2,7,1,3,0.462399,?,102,0.04648735,36.57692,421,0.2593974,?,39,1.000001,0.02902674,101,228,?,0.5508627,-0.8730153,?,?,1.230158,2.396889,6.838899,?,0.9999999,7.22472,63.34921,?,421,115,39,0.8214286,63.34921,2,2,7.22472,115,?,?,4,0.4584323,0.22237,2.186572,204,104,1.046669,?,30.90749,56,?,1936.186,0.8015867,0.6588351,0.330262,0.3413464,7.246766,1.460316,3.389713,0.9999999,115,41.02546,good

注意:'?'在文件中不是问题,因为我检查没有'?'但仍然显示相同的错误。

以下是我的代码:

from sklearn.naive_bayes import GaussianNB
from sklearn.ensemble import RandomForestClassifier
from sklearn import metrics, preprocessing
from sklearn import svm, naive_bayes, neighbors, tree
from sklearn.ensemble import AdaBoostClassifier
from sklearn import cross_validation
from tabulate import tabulate
from scipy.io.arff import loadarff
import arff
import pandas as pd
import numpy as np
import csv #not used right now
import scipy as sp
import numpy as np

filename = 'input.arff'
dataset = arff.load(open(filename, 'r'))
meta, data = loadarff(filename)
no_of_lines = len(meta)
train_size = int(0.8 * no_of_lines)

targets = []
targets = meta['nnzeros']
print(len(meta[0:70][0:train_size]))
print(meta['class'][0:train_size])
X = meta[0:70][0:train_size]
Y = meta['class'][0:train_size]
Z = meta[0:70][train_size:no_of_lines]
y_gnb = gnb.fit(X,Y).predict(Z)
print('Gaussian Naive Bayes prediction: -> ',y_gnb)

请告诉我导致此错误的原因!!

0 个答案:

没有答案