2013-08-02 3 views
5

저는 pybrain을 사용하여 신경 네트워크를 만드는 작업을 해왔으며 어떤 이유로 네트워크 전파를 훈련 한 후 네트워크를 훈련하지 못했습니다. Out 차원에서 둘 이상의 클래스로 사용하는 모든 데이터 세트는 내 모든 관측치를 하나의 범주로 쌓을 것입니다. 왜 이런 일이 일어나는 지 아는 사람이 있습니까? 코드와 일부 출력은 아래와 같습니다.Pybrain Neural Network가 제대로 훈련하지 못했습니다.

Training Epoch #19 
Total error: 0.0968444196605 

내가 혼란 매트릭스, 정밀, 리콜을 인쇄 할 갈 때 아직, 내가 얻을 : 아래 출력과 같이

import scipy 
import numpy 
from pybrain.datasets   import ClassificationDataSet 
from pybrain.utilities   import percentError 
from pybrain.tools.shortcuts  import buildNetwork 
from pybrain.supervised.trainers import BackpropTrainer 
from pybrain.structure.modules import SoftmaxLayer 
from sklearn.metrics    import precision_score,recall_score,confusion_matrix 
def makeDataset(CSVfile,ClassFile): 
    #import the features to data, and their classes to dataClasses 
    data=numpy.genfromtxt(CSVfile,delimiter=",") 
    classes=numpy.genfromtxt(ClassFile,delimiter=",") 
    print("Building the dataset from CSV files") 
    #Initialize an empty Pybrain dataset, and populate it 
    alldata=ClassificationDataSet(len(data[0]),1,nb_classes=3) 
    for count in range(len((classes))): 
     alldata.addSample(data[count],[classes[count]]) 
    return alldata 



def makeNeuralNet(alldata,trainingPercent=.3,hiddenNeurons=5,trainingIterations=20): 
    #Divide the data set into training and non-training data  
    testData, trainData = alldata.splitWithProportion(trainingPercent) 
    testData._convertToOneOfMany() 
    trainData._convertToOneOfMany() 
    #Then build the network, and using backwards propogation to train it 
    network = buildNetwork(trainData.indim, hiddenNeurons, trainData.outdim, outclass=SoftmaxLayer) 
    trainer = BackpropTrainer(network, dataset=trainData, momentum=0.1, verbose=True, weightdecay=0.01) 
    for i in range(trainingIterations): 
     print("Training Epoch #"+str(i)) 
     trainer.trainEpochs(1) 
    return [network,trainer] 



def checkNeuralNet(trainer,alldata): 
    predictedVals=trainer.testOnClassData(alldata) 
    actualVals=list(alldata['target']) 
## for row in alldata['target']: 
##  row=list(row) 
##  index=row.index(1) 
##  actualVals+=[index] 
    print("-----------------------------") 
    print("-----------------------------") 
    print("The precision is "+str(precision_score(actualVals,predictedVals))) 
    print("The recall is "+str(recall_score(actualVals,predictedVals))) 
    print("The confusion matrix is as shown below:") 
    print(confusion_matrix(actualVals,predictedVals)) 


CSVfile="/home/ubuntu/test.csv" 
ClassFile="/home/ubuntu/test_Classes.csv" 
#Build our dataset 
alldata=makeDataset(CSVfile,ClassFile) 
#Build and train the network 
net=makeNeuralNet(alldata,trainingPercent=.7,hiddenNeurons=20,trainingIterations=20) 
network=net[0] 
trainer=net[1] 
#Check it's strength 
checkNeuralNet(trainer,alldata) 

훈련의 마지막 시대는 0.09 오류가 이 이상한 오류뿐만 아니라 다음

UserWarning: The sum of true positives and false positives are equal to zero for some labels. Precision is ill defined for those labels [1 2]. The precision and recall are equal to zero for some labels. fbeta_score is ill defined for those labels [1 2]. 
    average=average) 
The precision is 0.316635552252 
UserWarning: The sum of true positives and false positives are equal to zero for some labels. Precision is ill defined for those labels [1 2]. The precision and recall are equal to zero for some labels. fbeta_score is ill defined for those labels [1 2]. 
    average=average) 
The recall is 0.562703787309 
The confusion matrix is as shown below: 
[[4487 0 0] 
[ 987 0 0] 
[2500 0 0]] 

답변

1

나는 매우 비슷한 문제가 있고, 나는 원인으로 SoftmaxLayer을 발견했다. 다른 것으로 교체하십시오 (예 : SigmoidLayer). 귀하의 경우에도 문제가있는 경우이 클래스가 부끄럽다는 좋은 기회가 있습니다.