示例#1
0
文件: MLP.py 项目: whirlp00l/ML
 def load_data(self):
     mn = MNIST('.')
     mn.test()
     data = mn.train_images
     data = np.array(data)
     
     data.astype(np.float32)
     data = data/255.0
     return data
示例#2
0
文件: MLP.py 项目: whirlp00l/ML
 def load_targets(self):
     mn = MNIST('.')
     mn.test()
     targets = []
     for t in mn.train_labels:
         #print t
         out = np.zeros(self.output)
         out[t] = 1
         targets.append(out)
     targets = np.array(targets)
     return targets
示例#3
0
文件: MLP.py 项目: whirlp00l/ML
        data = data/255.0
        return data

    def load_targets(self):
        mn = MNIST('.')
        mn.test()
        targets = []
        for t in mn.train_labels:
            #print t
            out = np.zeros(self.output)
            out[t] = 1
            targets.append(out)
        targets = np.array(targets)
        return targets




if __name__ == '__main__':
    mn = MNIST('.')
    mn.test()
    MLP = MLP_Classifier(28*28+1,40,10)
    datas = MLP.load_data()
    targets = MLP.load_targets()
    MLP.fit(datas,targets)
    result = MLP.predict(mn.test_images)
    accurate = 0
    for i in range(len(result)):
        if result[i] == mn.test_labels[i]:
            accurate+=1
    print accurate