【发布时间】:2015-09-16 04:29:55
【问题描述】:
我已经开始使用 Scikit-learn,我正在尝试训练和预测一个高斯朴素贝叶斯分类器。我不知道我做得很好,我希望有人可以帮助我。
问题:我输入了 X 个类型 1 的项目,我得到的响应是它们是类型 0
我是怎么做到的: 为了生成训练数据,我这样做:
#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)
我用这个弱条件标记数据:
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。你能告诉我我做错了什么以及如何解决它吗?
【问题讨论】:
-
如果对你有帮助,请采纳答案,让其他人也可以借鉴...
标签: python machine-learning scikit-learn