Пример #1
0
 def __test(self):
     db = get_db()
     dataList = db.sampledata.find()
     for data in dataList:
         if data['name'] == self.__data_name:
             self.__test_data = data['data']
             self.__type = data['type']
             break
     resultList = db.result.find()
     for result in resultList:
         if result['name'] == self.__test_name:
             self.__trees = result['trees']
             break
     count = 0
     for data in self.__test_data:
         vote = {}
         for tree in self.__trees:
             label = predict(tree, data)
             if label not in vote.keys():
                 vote[label] = 0
             vote[label] += 1
         max = 0
         majorityLabel = None
         for label in vote.keys():
             if vote[label] > max:
                 max = vote[label]
                 majorityLabel = label
         if majorityLabel == self.__type:
             count += 1
         else:
             self.__error_data.append(data)
     self.__correct_rate = float(count) / len(self.__test_data)
Пример #2
0
 def __test(self):
     db = get_db()
     dataList = db.sampledata.find()
     for data in dataList:
         if data['name'] == self.__data_name:
             self.__test_data = data['data']
             self.__type = data['type']
             break
     resultList = db.result.find()
     for result in resultList:
         if result['name'] == self.__test_name:
             self.__trees = result['trees']
             break
     count = 0
     for data in self.__test_data:
         vote = {}
         for tree in self.__trees:
             label = predict(tree, data)
             if label not in vote.keys():
                 vote[label] = 0
             vote[label] += 1
         max = 0
         majorityLabel = None
         for label in vote.keys():
             if vote[label] > max:
                 max = vote[label]
                 majorityLabel = label
         if majorityLabel == self.__type:
             count += 1
         else:
             self.__error_data.append(data)
     self.__correct_rate = float(count) / len(self.__test_data)
Пример #3
0
 def __init__(self):
     self.__db = get_db()
     self.__dataList = self.__db.sampledata.find()
     self.__dataDict = {}
     for data in self.__dataList:
         self.__dataDict[data['name']] = {
             'type': data['type'],
             'data': data['data'],
             'name': data['name'],
         }
Пример #4
0
def saveTrainResult(name, trees):
    """
        save the training result
        :param name: the name you want to save
        :param trees: the list of decision trees
        :return:
    """
    trainResult = get_db().result
    trainResult.insert({
        'name': name,
        'trees': trees,
    })
Пример #5
0
 def __init__(self):
     self.__db = get_db()
     self.__dataList = self.__db.sampledata.find()
     self.__dataDict = {}
     for data in self.__dataList:
         self.__dataDict[data['name']] = {
             'type': data['type'],
             'data': data['data'],
             'name': data['name'],
         }
     self.__resultList = self.__db.result.find()
     self.__resultDict = {}
     for result in self.__resultList:
         self.__resultDict[result['name']] = {'trees': result['trees']}
Пример #6
0
 def __init__(self):
     self.__db = get_db()
     self.__dataList = self.__db.sampledata.find()
     self.__dataDict = {}
     for data in self.__dataList:
         self.__dataDict[data['name']] = {
             'type' : data['type'],
             'data' : data['data'],
             'name' : data['name'],
         }
     self.__resultList = self.__db.result.find()
     self.__resultDict = {}
     for result in self.__resultList:
         self.__resultDict[result['name']] = {
             'trees' : result['trees']
         }
Пример #7
0
 def stop_sampling(self, client_mac, type):
     """
         stop sampling the given client mac
         :param client_mac: client mac you want to sample
         :param type: the type of area you define
         :return:
     """
     self.__sampling = False
     data = self.__dpm_proxy.delSampleMac(client_mac)
     print 'sample_data:'
     print data
     # write into database
     if len(data) != 0:
         db = get_db()
         sampleData = db.sampledata
         sampleData.insert({
             'name' : client_mac + '_' + type + '_' + time.strftime("%Y%m%d%H%M%S", time.localtime()),
             'type' : type,
             'data' : data
         })
Пример #8
0
 def stop_sampling(self, client_mac, type):
     """
         stop sampling the given client mac
         :param client_mac: client mac you want to sample
         :param type: the type of area you define
         :return:
     """
     self.__sampling = False
     data = self.__dpm_proxy.delSampleMac(client_mac)
     print 'sample_data:'
     print data
     # write into database
     if len(data) != 0:
         db = get_db()
         sampleData = db.sampledata
         sampleData.insert({
             'name':
             client_mac + '_' + type + '_' +
             time.strftime("%Y%m%d%H%M%S", time.localtime()),
             'type':
             type,
             'data':
             data
         })