我已經開始使用Scikit學習我試圖訓練和預測高斯樸素貝葉斯分類器。我不知道我做得很好,我想如果有人能幫助我。SciKit學習 - 高斯樸素貝葉斯Implementingtion
問題:我輸入型1項的X數量和我有作爲迴應,他們是類型0
我怎麼沒IT: 爲了生成訓練數據我做這樣的:
#this is of type 1
ganado={
"Hora": "16:43:35",
"Fecha": "19/06/2015",
"Tiempo": 10,
"Brazos": "der",
"Sentado": "no",
"Puntuacion Final Pasteles": 50,
"Nombre": "usuario1",
"Puntuacion Final Botellas": 33
}
#this is type 0
perdido={
"Hora": "16:43:35",
"Fecha": "19/06/2015",
"Tiempo": 10,
"Brazos": "der",
"Sentado": "no",
"Puntuacion Final Pasteles": 4,
"Nombre": "usuario1",
"Puntuacion Final Botellas": 3
}
train=[]
for repeticion in range(0,400):
train.append(ganado)
for repeticion in range(0,1):
train.append(perdido)
我這個微弱condiction標籤中的數據:
listLabel=[]
for data in train:
condition=data["Puntuacion Final Pasteles"]+data["Puntuacion Final Botellas"]
if condition<20:
listLabel.append(0)
else:
listLabel.append(1)
我生成這樣的測試數據:
#this should be type 1
pruebaGanado={
"Hora": "16:43:35",
"Fecha": "19/06/2015",
"Tiempo": 10,
"Brazos": "der",
"Sentado": "no",
"Puntuacion Final Pasteles": 10,
"Nombre": "usuario1",
"Puntuacion Final Botellas": 33
}
#this should be type 0
pruebaPerdido={
"Hora": "16:43:35",
"Fecha": "19/06/2015",
"Tiempo": 10,
"Brazos": "der",
"Sentado": "no",
"Puntuacion Final Pasteles": 2,
"Nombre": "usuario1",
"Puntuacion Final Botellas": 3
}
test=[]
for repeticion in range(0,420):
test.append(pruebaGanado)
test.append(pruebaPerdido)
在那之後,我用train
和listLabel
訓練分類:
vec = DictVectorizer()
X=vec.fit_transform(train)
gnb = GaussianNB()
trained=gnb.fit(X.toarray(),listLabel)
有一次,我已經訓練我利用數據進行分類測試
testX=vec.fit_transform(test)
predicted=trained.predict(testX.toarray())
最後結果總是0
。你能告訴我我做錯了什麼,請問如何解決?
請接受答案,如果它幫助你,所以其他人也可以從中學習... – omerbp