I have started using Scikit-learn and I am trying to train and predict a Gaussian Naive Bayes classificator. I don't know what I'm doing very well and I would like if someone could help me.
PROBLEM: I enter X quantity of items of type 1 and i have as response that they are of type 0
HOW I DID IT: In order to generate the data for training I make this:
#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)
I label the data by this weak 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)
And I generate the data for testing like this:
#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)
After that, I use train
and listLabel
to train the classifier:
vec = DictVectorizer()
X=vec.fit_transform(train)
gnb = GaussianNB()
trained=gnb.fit(X.toarray(),listLabel)
Once I have trained the classifier I use the data for testing
testX=vec.fit_transform(test)
predicted=trained.predict(testX.toarray())
Finally the results are always 0
. Could you tell me what I did wrong and how to fix it please?