BP神经网络python简单实现2(性能优化)

这一版本主要是对 http://blog.csdn.net/net_wolf_007/article/details/52055718 实现的版本进行优化

上一版本主要是根据理论知识实现简单版本,步聚比较清晰。里面存在严重的性能问题,对激活函数的扩展问题及不能批量训练等主要问题。

性能上在 http://blog.csdn.net/net_wolf_007/article/details/52059602 实现手写识别时,只训练10轮就花费了快一个小时,这是不能接受的。这一版本通过优化方法:

  1. 去掉神经元类,把功能合并入NetLayer类中,使用矩阵计算加快速度
  2. 调整代码实现批量训练方法。
  3. 优化程序中numpy库运算顺序,避免产生中间变量。原理可见 numpy.array 操作简单总结

经过优化,同样的内容共花的时间只有20s,相对于原来的1个小时,已经很好了,而且还可以通过增加批次训练的个数来提升速度(当前一次只训练100个输入, 我试过增加到500个, 只需花10s, 准确率不变)。


激活函数扩展上,经分析调试,是由于每次权值更新的数据过大引起的,所以这版本对权值更新的数据大小进行了限制。如下代码

max_weight = max(np.amax(w_add), -np.amin(w_add)) * 2
        w_add /= max_weight

这样就可以扩展到新的激活函数上了。


同时这一版本中对除了输出层之外都加了偏置。

经过优化分,用此版本来训练手写数字识别,识别度达到了97%, 到达预期效果。


完整代码如下:

__author__ = 'xxx'
import numpy as np
from datetime import datetime
from sklearn.metrics import classification_report

def new_str():
    return datetime.now().strftime('%b-%d-%y %H:%M:%S')

def logistic(x):
    return 1 / (1 + np.exp(-x))

def logistic_derivative(x):
    tmp1 = logistic(x)
    return tmp1 - tmp1**2

def rectify(x):
    return x*(x > 0)

def rectify_derivative(x):
    x = x.copy()
    x[x > 0] = 1
    x[x < 0] = 0
    return x

class NetLayer:
    '''
    网络层封装
    管理当前网络层的神经元列表
    '''
    def __init__(self, len_node, in_count, momentum=0.9, bias=True):
        '''
        :param len_node: 当前层的神经元数
        :param in_count: 当前层的输入数
        '''
        self.nonlinear = (logistic, logistic_derivative)
        self.nonlinear = (rectify, rectify_derivative)
        self.bias = bias
        if bias:
            in_count += 1# bias

        self.weights = np.reshape(np.random.uniform(-0.05, 0.05, len_node*in_count), (len_node,  in_count))
        self.last_weight_add = np.zeros((len_node,  in_count))
        self.deltas_item = np.zeros(len_node)

        # 记录下一层的引用,方便递归操作
        self.next_layer = None
        self.input = np.array([])
        self.output = np.array([])

        self.momentum = momentum

    def calc_output(self, x):
        if self.bias:
            self.input = np.hstack((x, np.ones((len(x),1))))
        else:
            self.input = x
        self.output = self.nonlinear[0](np.dot(self.input, self.weights.T))
        if self.next_layer is not None:
            return self.next_layer.calc_output(self.output)
        return self.output

    def update_weight(self, learning_rate, target):
        '''
        更新当前网络层及之后层次的权重
        使用了递归来操作,所以要求外面调用时必须从网络层的第一层(输入层的下一层)来调用
        :param learning_rate: 学习率
        :param target: 输出值
        '''

        self.deltas_item = self.nonlinear[1](self.output)
        if self.next_layer is None:
            self.deltas_item *= (target - self.output)
        else:
            self.deltas_item *= self.next_layer.update_weight(learning_rate, target)
        w_add = np.dot(self.deltas_item.T, self.input)
        max_weight = max(np.amax(w_add), -np.amin(w_add)) * 2
        w_add /= max_weight
        w_add *= learning_rate
        self.last_weight_add *= self.momentum
        self.last_weight_add += w_add
        self.weights += self.last_weight_add

        weights = self.weights if not self.bias else self.weights[:, :-1]
        return np.dot(self.deltas_item, weights)

class NeuralNetWork:

    def __init__(self, layers):
        self.layers = []
        self.construct_network(layers)

        pass

    def construct_network(self, layers):
        last_layer = None
        for i, layer in enumerate(layers):
            if i == 0:
                continue

            cur_layer = NetLayer(layer, layers[i-1], bias=(i+1 != len(layers)))
            self.layers.append(cur_layer)
            if last_layer is not None:
                last_layer.next_layer = cur_layer

            last_layer = cur_layer

    def fit(self, x_train, y_train, x_test, y_test, learning_rate=0.1, epochs=10, shuffle=False):
        '''
        训练网络, 默认按顺序来训练
        方法 1:按训练数据顺序来训练
        方法 2: 随机选择测试
        :param x_train: 输入数据
        :param y_train: 输出数据
        :param learning_rate: 学习率
        :param epochs:权重更新次数
        :param shuffle:随机取数据训练
        '''
        indices = np.arange(len(x_train))
        length = 100
        for n in range(epochs):
            # print(new_str(), "epochs {}...".format(n))
            if shuffle:
                np.random.shuffle(indices)
            for index in range(len(indices)//length):
                indexes = indices[index*length: (index+1)*length]
                self.layers[0].calc_output(x_train[indexes])
                self.layers[0].update_weight(learning_rate, y_train[indexes])
            print(new_str(),"epochs", n)
            self.show_test( x_test, y_test)

    def show_test(self, x_test, y_test):
        predict = self.predict(x_test)
        predicts = []
        for p in predict:
            predicts.append(unformat_y(p))
        predicts = np.array(predicts)
        ok_cnt = sum([1 for i in range(len(predicts)) if predicts[i] == y_test[i]])

        print(ok_cnt, len(predicts), "%.3f" % (float(ok_cnt)/len(predicts)))
        print(classification_report(y_test, predicts))

    def predict(self, x):
        return self.layers[0].calc_output(x)

def format_y(data):
    y_tmp = np.zeros((len(data), 10))
    for i in range(len(data)):
        y_tmp[i, data[i]] = 1
    return y_tmp

def unformat_y(data):
    # return np.where(data == np.amax(data))[0]
    m = max(data)
    for j, val in enumerate(data):
        if val == m:
            return j
    return 11



测试代码如下:

def load_source(filename):
    with open(filename, "r") as file:
        lines = file.readlines()
        return lines[1:]

if __name__ == '__main__':
    print(new_str(), "test neural network")
    np.set_printoptions(precision=3, suppress=True)

    # data_lines = np.loadtxt(open("./data/train.csv","rb"),delimiter=",",skiprows=1).astype(np.int)

    data_lines = load_source("./data/train.csv")
    for i in range(len(data_lines)):
        data_lines[i] = data_lines[i].split(',')
    data_lines = np.array(data_lines).astype(np.int)

    x_data = data_lines[:, 1:]/256 #格式化数据
    y_data = data_lines[:, 0]

    TEST = -2000
    x_train = x_data[:TEST]
    y_train = y_data[:TEST]
    x_test = x_data[TEST:]
    y_test = y_data[TEST:]
    print(new_str(), "train len", len(x_train), "test len:", len(x_test))

    print(new_str(), "start train...")
    network = NeuralNetWork([28*28, 250, 100, 10])
    network.fit(x_train=x_train, y_train=format_y(y_train), x_test=x_test, y_test=y_test, learning_rate=0.01, epochs=10, shuffle=False)

结果输出:

Aug-04-16 18:59:32 test neural network
Aug-04-16 18:59:44 train len 40000 test len: 2000
Aug-04-16 18:59:44 start train...
Aug-04-16 18:59:46 epochs 0
1897 2000 0.949
             precision    recall  f1-score   support

          0       0.95      0.98      0.96       197
          1       0.96      0.98      0.97       225
          2       0.94      0.95      0.95       190
          3       0.94      0.95      0.95       198
          4       0.92      0.97      0.95       226
          5       0.95      0.88      0.91       162
          6       0.98      0.96      0.97       216
          7       0.99      0.95      0.97       202
          8       0.90      0.94      0.92       179
          9       0.96      0.90      0.93       205

avg / total       0.95      0.95      0.95      2000

Aug-04-16 18:59:48 epochs 1
1906 2000 0.953
             precision    recall  f1-score   support

          0       0.91      0.99      0.95       197
          1       0.99      0.95      0.97       225
          2       0.96      0.94      0.95       190
          3       0.93      0.95      0.94       198
          4       0.98      0.95      0.97       226
          5       0.95      0.91      0.93       162
          6       0.99      0.97      0.98       216
          7       0.98      0.96      0.97       202
          8       0.88      0.96      0.91       179
          9       0.95      0.93      0.94       205

avg / total       0.95      0.95      0.95      2000

Aug-04-16 18:59:50 epochs 2
1925 2000 0.963
             precision    recall  f1-score   support

          0       0.96      0.99      0.97       197
          1       0.99      0.97      0.98       225
          2       0.93      0.97      0.95       190
          3       0.96      0.92      0.94       198
          4       0.98      0.97      0.97       226
          5       0.95      0.93      0.94       162
          6       0.99      0.97      0.98       216
          7       0.98      0.98      0.98       202
          8       0.91      0.96      0.94       179
          9       0.96      0.96      0.96       205

avg / total       0.96      0.96      0.96      2000

Aug-04-16 18:59:52 epochs 3
1916 2000 0.958
             precision    recall  f1-score   support

          0       0.92      0.99      0.96       197
          1       0.97      0.98      0.98       225
          2       0.92      0.97      0.94       190
          3       0.96      0.92      0.94       198
          4       0.98      0.95      0.97       226
          5       0.97      0.89      0.93       162
          6       0.99      0.98      0.98       216
          7       0.99      0.97      0.98       202
          8       0.92      0.94      0.93       179
          9       0.95      0.96      0.95       205

avg / total       0.96      0.96      0.96      2000

Aug-04-16 18:59:54 epochs 4
1926 2000 0.963
             precision    recall  f1-score   support

          0       0.87      0.99      0.93       197
          1       0.99      0.96      0.98       225
          2       0.96      0.94      0.95       190
          3       0.98      0.95      0.97       198
          4       0.97      0.98      0.98       226
          5       0.99      0.92      0.95       162
          6       0.99      0.98      0.98       216
          7       0.97      0.98      0.98       202
          8       0.96      0.94      0.95       179
          9       0.97      0.96      0.96       205

avg / total       0.96      0.96      0.96      2000

Aug-04-16 18:59:56 epochs 5
1931 2000 0.966
             precision    recall  f1-score   support

          0       0.94      0.99      0.97       197
          1       0.99      0.98      0.98       225
          2       0.96      0.96      0.96       190
          3       0.96      0.95      0.96       198
          4       0.97      0.98      0.98       226
          5       0.97      0.93      0.95       162
          6       0.99      0.99      0.99       216
          7       0.99      0.96      0.97       202
          8       0.93      0.94      0.94       179
          9       0.94      0.96      0.95       205

avg / total       0.97      0.97      0.97      2000

Aug-04-16 18:59:58 epochs 6
1933 2000 0.967
             precision    recall  f1-score   support

          0       0.93      0.99      0.96       197
          1       0.99      0.96      0.98       225
          2       0.95      0.96      0.96       190
          3       0.99      0.94      0.97       198
          4       0.98      0.99      0.98       226
          5       0.98      0.93      0.95       162
          6       0.97      0.99      0.98       216
          7       0.98      0.97      0.97       202
          8       0.93      0.97      0.95       179
          9       0.96      0.96      0.96       205

avg / total       0.97      0.97      0.97      2000

Aug-04-16 19:00:00 epochs 7
1939 2000 0.970
             precision    recall  f1-score   support

          0       0.96      0.99      0.98       197
          1       0.99      0.98      0.98       225
          2       0.96      0.97      0.97       190
          3       0.95      0.96      0.96       198
          4       0.99      0.97      0.98       226
          5       0.97      0.90      0.94       162
          6       0.99      0.99      0.99       216
          7       0.99      0.98      0.98       202
          8       0.95      0.94      0.95       179
          9       0.95      0.99      0.97       205

avg / total       0.97      0.97      0.97      2000

Aug-04-16 19:00:02 epochs 8
1929 2000 0.965
             precision    recall  f1-score   support

          0       0.89      0.99      0.94       197
          1       0.99      0.97      0.98       225
          2       0.98      0.95      0.97       190
          3       0.97      0.95      0.96       198
          4       0.98      0.98      0.98       226
          5       0.96      0.93      0.94       162
          6       0.99      0.98      0.98       216
          7       0.99      0.98      0.98       202
          8       0.95      0.91      0.93       179
          9       0.96      0.98      0.97       205

avg / total       0.97      0.96      0.96      2000

Aug-04-16 19:00:04 epochs 9
1937 2000 0.969
             precision    recall  f1-score   support

          0       0.95      0.99      0.97       197
          1       0.98      0.97      0.98       225
          2       0.98      0.96      0.97       190
          3       0.96      0.97      0.96       198
          4       0.97      0.98      0.98       226
          5       0.98      0.93      0.95       162
          6       0.97      0.99      0.98       216
          7       0.98      0.98      0.98       202
          8       0.95      0.93      0.94       179
          9       0.96      0.97      0.96       205

avg / total       0.97      0.97      0.97      2000


Process finished with exit code 0


同时比较下使用 self.nonlinear = (logistic, logistic_derivative) 的结果最高只达到了88%。  而且明显看到随着训练次数的增加,识别率会往下降,这就是过拟合的原因。而采用self.nonlinear = (rectify, rectify_derivative)时,这种现象不是很明显。这估计就是不推荐用logistic做为激活函数的原因之一吧。


/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 /xxx/NeuralNetwork.py
Aug-04-16 19:05:21 test neural network
Aug-04-16 19:05:33 train len 40000 test len: 2000
Aug-04-16 19:05:33 start train...
Aug-04-16 19:05:36 epochs 0
1587 2000 0.793
             precision    recall  f1-score   support

          0       0.87      0.94      0.91       197
          1       0.92      0.96      0.94       225
          2       0.79      0.84      0.81       190
          3       0.89      0.74      0.81       198
          4       0.91      0.76      0.83       226
          5       0.57      0.28      0.38       162
          6       0.83      0.95      0.88       216
          7       0.93      0.81      0.87       202
          8       0.55      0.68      0.61       179
          9       0.63      0.83      0.72       205

avg / total       0.80      0.79      0.79      2000

Aug-04-16 19:05:38 epochs 1
1725 2000 0.863
             precision    recall  f1-score   support

          0       0.88      0.96      0.92       197
          1       0.93      0.96      0.95       225
          2       0.80      0.88      0.84       190
          3       0.89      0.76      0.82       198
          4       0.95      0.82      0.88       226
          5       0.81      0.65      0.72       162
          6       0.90      0.92      0.91       216
          7       0.95      0.93      0.94       202
          8       0.68      0.86      0.76       179
          9       0.84      0.84      0.84       205

avg / total       0.87      0.86      0.86      2000

Aug-04-16 19:05:40 epochs 2
1763 2000 0.881
             precision    recall  f1-score   support

          0       0.88      0.97      0.92       197
          1       0.98      0.92      0.95       225
          2       0.83      0.87      0.85       190
          3       0.88      0.86      0.87       198
          4       0.91      0.90      0.90       226
          5       0.89      0.65      0.75       162
          6       0.95      0.94      0.94       216
          7       0.94      0.93      0.93       202
          8       0.69      0.90      0.78       179
          9       0.89      0.83      0.86       205

avg / total       0.89      0.88      0.88      2000

Aug-04-16 19:05:43 epochs 3
1718 2000 0.859
             precision    recall  f1-score   support

          0       0.84      0.96      0.90       197
          1       0.99      0.89      0.94       225
          2       0.79      0.87      0.83       190
          3       0.88      0.83      0.85       198
          4       0.88      0.86      0.87       226
          5       0.86      0.64      0.73       162
          6       0.95      0.88      0.91       216
          7       0.95      0.92      0.93       202
          8       0.62      0.87      0.73       179
          9       0.88      0.83      0.85       205

avg / total       0.87      0.86      0.86      2000

Aug-04-16 19:05:45 epochs 4
1769 2000 0.884
             precision    recall  f1-score   support

          0       0.85      0.97      0.91       197
          1       0.98      0.95      0.96       225
          2       0.81      0.87      0.84       190
          3       0.91      0.83      0.87       198
          4       0.90      0.91      0.91       226
          5       0.83      0.72      0.77       162
          6       0.95      0.91      0.93       216
          7       0.97      0.91      0.94       202
          8       0.75      0.86      0.80       179
          9       0.88      0.86      0.87       205

avg / total       0.89      0.88      0.88      2000

Aug-04-16 19:05:47 epochs 5
1753 2000 0.876
             precision    recall  f1-score   support

          0       0.86      0.96      0.91       197
          1       0.98      0.94      0.96       225
          2       0.85      0.85      0.85       190
          3       0.90      0.84      0.87       198
          4       0.86      0.89      0.88       226
          5       0.88      0.70      0.78       162
          6       0.90      0.93      0.91       216
          7       0.96      0.90      0.93       202
          8       0.72      0.86      0.79       179
          9       0.87      0.84      0.86       205

avg / total       0.88      0.88      0.88      2000

Aug-04-16 19:05:50 epochs 6
1748 2000 0.874
             precision    recall  f1-score   support

          0       0.86      0.97      0.91       197
          1       0.97      0.93      0.95       225
          2       0.80      0.86      0.83       190
          3       0.92      0.81      0.86       198
          4       0.88      0.89      0.89       226
          5       0.92      0.64      0.76       162
          6       0.86      0.94      0.90       216
          7       0.96      0.92      0.94       202
          8       0.73      0.88      0.79       179
          9       0.88      0.83      0.85       205

avg / total       0.88      0.87      0.87      2000

Aug-04-16 19:05:52 epochs 7
1743 2000 0.872
             precision    recall  f1-score   support

          0       0.86      0.97      0.91       197
          1       0.97      0.93      0.95       225
          2       0.82      0.88      0.85       190
          3       0.93      0.83      0.88       198
          4       0.89      0.83      0.86       226
          5       0.91      0.67      0.77       162
          6       0.88      0.92      0.90       216
          7       0.95      0.92      0.93       202
          8       0.71      0.87      0.78       179
          9       0.83      0.85      0.84       205

avg / total       0.88      0.87      0.87      2000

Aug-04-16 19:05:54 epochs 8
1726 2000 0.863
             precision    recall  f1-score   support

          0       0.89      0.95      0.92       197
          1       0.98      0.94      0.96       225
          2       0.75      0.87      0.81       190
          3       0.90      0.83      0.86       198
          4       0.86      0.83      0.84       226
          5       0.88      0.68      0.77       162
          6       0.88      0.90      0.89       216
          7       0.95      0.90      0.93       202
          8       0.71      0.85      0.77       179
          9       0.85      0.84      0.85       205

avg / total       0.87      0.86      0.86      2000

Aug-04-16 19:05:57 epochs 9
1713 2000 0.857
             precision    recall  f1-score   support

          0       0.88      0.95      0.91       197
          1       0.97      0.92      0.94       225
          2       0.79      0.83      0.81       190
          3       0.88      0.78      0.83       198
          4       0.88      0.85      0.87       226
          5       0.88      0.70      0.78       162
          6       0.93      0.90      0.91       216
          7       0.94      0.88      0.91       202
          8       0.61      0.87      0.72       179
          9       0.89      0.84      0.86       205

avg / total       0.87      0.86      0.86      2000

Aug-04-16 19:05:59 epochs 10
1696 2000 0.848
             precision    recall  f1-score   support

          0       0.88      0.96      0.92       197
          1       0.96      0.91      0.93       225
          2       0.71      0.85      0.77       190
          3       0.91      0.75      0.83       198
          4       0.88      0.84      0.86       226
          5       0.87      0.64      0.74       162
          6       0.93      0.91      0.92       216
          7       0.90      0.86      0.88       202
          8       0.67      0.89      0.76       179
          9       0.84      0.82      0.83       205

avg / total       0.86      0.85      0.85      2000

Aug-04-16 19:06:02 epochs 11
1714 2000 0.857
             precision    recall  f1-score   support

          0       0.89      0.96      0.92       197
          1       0.95      0.94      0.95       225
          2       0.78      0.85      0.81       190
          3       0.92      0.78      0.85       198
          4       0.87      0.86      0.87       226
          5       0.89      0.65      0.75       162
          6       0.90      0.91      0.91       216
          7       0.87      0.88      0.87       202
          8       0.67      0.90      0.77       179
          9       0.87      0.79      0.83       205

avg / total       0.87      0.86      0.86      2000

/Users/jerome/机器学习/number/NeuralNetwork.py:10: RuntimeWarning: overflow encountered in exp
  return 1 / (1 + np.exp(-x))
Aug-04-16 19:06:04 epochs 12
1717 2000 0.859
             precision    recall  f1-score   support

          0       0.89      0.97      0.93       197
          1       0.94      0.94      0.94       225
          2       0.74      0.87      0.80       190
          3       0.91      0.78      0.84       198
          4       0.88      0.88      0.88       226
          5       0.90      0.64      0.74       162
          6       0.90      0.87      0.88       216
          7       0.90      0.91      0.90       202
          8       0.69      0.88      0.77       179
          9       0.89      0.80      0.84       205

avg / total       0.87      0.86      0.86      2000

Aug-04-16 19:06:06 epochs 13
1721 2000 0.861
             precision    recall  f1-score   support

          0       0.87      0.97      0.92       197
          1       0.94      0.95      0.94       225
          2       0.80      0.87      0.83       190
          3       0.90      0.79      0.84       198
          4       0.88      0.87      0.88       226
          5       0.87      0.66      0.75       162
          6       0.86      0.92      0.89       216
          7       0.88      0.90      0.89       202
          8       0.72      0.82      0.77       179
          9       0.89      0.80      0.84       205

avg / total       0.86      0.86      0.86      2000

Aug-04-16 19:06:09 epochs 14
1734 2000 0.867
             precision    recall  f1-score   support

          0       0.86      0.96      0.90       197
          1       0.95      0.94      0.95       225
          2       0.79      0.88      0.83       190
          3       0.90      0.81      0.85       198
          4       0.92      0.85      0.88       226
          5       0.85      0.67      0.75       162
          6       0.89      0.96      0.92       216
          7       0.91      0.91      0.91       202
          8       0.71      0.80      0.75       179
          9       0.89      0.83      0.86       205

avg / total       0.87      0.87      0.87      2000

Aug-04-16 19:06:11 epochs 15
1746 2000 0.873
             precision    recall  f1-score   support

          0       0.87      0.96      0.91       197
          1       0.95      0.93      0.94       225
          2       0.87      0.86      0.86       190
          3       0.90      0.82      0.86       198
          4       0.92      0.83      0.87       226
          5       0.86      0.70      0.77       162
          6       0.86      0.98      0.92       216
          7       0.90      0.93      0.91       202
          8       0.74      0.83      0.78       179
          9       0.85      0.85      0.85       205

avg / total       0.88      0.87      0.87      2000

Aug-04-16 19:06:13 epochs 16
1733 2000 0.867
             precision    recall  f1-score   support

          0       0.87      0.96      0.91       197
          1       0.96      0.92      0.94       225
          2       0.81      0.83      0.82       190
          3       0.87      0.84      0.86       198
          4       0.88      0.87      0.88       226
          5       0.88      0.67      0.76       162
          6       0.88      0.93      0.91       216
          7       0.95      0.90      0.92       202
          8       0.71      0.85      0.78       179
          9       0.86      0.83      0.85       205

avg / total       0.87      0.87      0.87      2000

Aug-04-16 19:06:16 epochs 17
1722 2000 0.861
             precision    recall  f1-score   support

          0       0.87      0.95      0.91       197
          1       0.95      0.94      0.94       225
          2       0.78      0.87      0.82       190
          3       0.87      0.83      0.85       198
          4       0.88      0.86      0.87       226
          5       0.91      0.65      0.76       162
          6       0.87      0.96      0.92       216
          7       0.96      0.91      0.93       202
          8       0.67      0.82      0.74       179
          9       0.88      0.76      0.82       205

avg / total       0.87      0.86      0.86      2000

Aug-04-16 19:06:18 epochs 18
1715 2000 0.858
             precision    recall  f1-score   support

          0       0.83      0.97      0.90       197
          1       0.94      0.95      0.94       225
          2       0.82      0.86      0.84       190
          3       0.88      0.83      0.85       198
          4       0.85      0.82      0.83       226
          5       0.92      0.62      0.74       162
          6       0.84      0.97      0.90       216
          7       0.97      0.91      0.94       202
          8       0.72      0.82      0.77       179
          9       0.85      0.77      0.81       205

avg / total       0.86      0.86      0.86      2000

Aug-04-16 19:06:21 epochs 19
1714 2000 0.857
             precision    recall  f1-score   support

          0       0.82      0.97      0.89       197
          1       0.92      0.96      0.94       225
          2       0.86      0.82      0.84       190
          3       0.90      0.83      0.86       198
          4       0.84      0.85      0.84       226
          5       0.86      0.62      0.72       162
          6       0.88      0.94      0.91       216
          7       0.94      0.91      0.92       202
          8       0.74      0.87      0.80       179
          9       0.82      0.73      0.78       205

avg / total       0.86      0.86      0.85      2000

Aug-04-16 19:06:23 epochs 20
1733 2000 0.867
             precision    recall  f1-score   support

          0       0.82      0.97      0.89       197
          1       0.96      0.95      0.95       225
          2       0.88      0.82      0.85       190
          3       0.91      0.85      0.88       198
          4       0.84      0.84      0.84       226
          5       0.86      0.67      0.75       162
          6       0.90      0.93      0.91       216
          7       0.94      0.92      0.93       202
          8       0.71      0.87      0.78       179
          9       0.85      0.80      0.83       205

avg / total       0.87      0.87      0.87      2000

Aug-04-16 19:06:25 epochs 21
1741 2000 0.871
             precision    recall  f1-score   support

          0       0.86      0.96      0.90       197
          1       0.93      0.95      0.94       225
          2       0.87      0.83      0.85       190
          3       0.89      0.84      0.86       198
          4       0.86      0.86      0.86       226
          5       0.89      0.71      0.79       162
          6       0.89      0.95      0.92       216
          7       0.95      0.91      0.93       202
          8       0.70      0.89      0.79       179
          9       0.89      0.76      0.82       205

avg / total       0.88      0.87      0.87      2000

Aug-04-16 19:06:28 epochs 22
1724 2000 0.862
             precision    recall  f1-score   support

          0       0.87      0.96      0.91       197
          1       0.93      0.96      0.95       225
          2       0.81      0.87      0.84       190
          3       0.91      0.82      0.86       198
          4       0.84      0.86      0.85       226
          5       0.90      0.66      0.76       162
          6       0.87      0.90      0.88       216
          7       0.94      0.91      0.92       202
          8       0.70      0.89      0.79       179
          9       0.89      0.75      0.81       205

avg / total       0.87      0.86      0.86      2000

Aug-04-16 19:06:30 epochs 23
1723 2000 0.862
             precision    recall  f1-score   support

          0       0.89      0.97      0.93       197
          1       0.93      0.93      0.93       225
          2       0.85      0.82      0.83       190
          3       0.90      0.81      0.86       198
          4       0.83      0.86      0.85       226
          5       0.93      0.70      0.80       162
          6       0.86      0.94      0.90       216
          7       0.92      0.91      0.91       202
          8       0.66      0.89      0.76       179
          9       0.92      0.74      0.82       205

avg / total       0.87      0.86      0.86      2000

Aug-04-16 19:06:32 epochs 24
1700 2000 0.850
             precision    recall  f1-score   support

          0       0.85      0.95      0.90       197
          1       0.93      0.93      0.93       225
          2       0.89      0.81      0.85       190
          3       0.89      0.84      0.86       198
          4       0.83      0.84      0.83       226
          5       0.91      0.65      0.76       162
          6       0.83      0.96      0.89       216
          7       0.91      0.90      0.90       202
          8       0.63      0.87      0.73       179
          9       0.93      0.70      0.80       205

avg / total       0.86      0.85      0.85      2000

Aug-04-16 19:06:35 epochs 25
1691 2000 0.846
             precision    recall  f1-score   support

          0       0.86      0.96      0.91       197
          1       0.94      0.93      0.94       225
          2       0.90      0.82      0.85       190
          3       0.87      0.83      0.85       198
          4       0.83      0.80      0.81       226
          5       0.89      0.62      0.73       162
          6       0.81      0.95      0.88       216
          7       0.90      0.88      0.89       202
          8       0.63      0.86      0.72       179
          9       0.92      0.75      0.82       205

avg / total       0.86      0.85      0.85      2000

Aug-04-16 19:06:37 epochs 26
1693 2000 0.847
             precision    recall  f1-score   support

          0       0.88      0.95      0.91       197
          1       0.91      0.94      0.92       225
          2       0.89      0.82      0.85       190
          3       0.83      0.85      0.84       198
          4       0.81      0.86      0.83       226
          5       0.86      0.58      0.69       162
          6       0.83      0.96      0.89       216
          7       0.91      0.88      0.89       202
          8       0.66      0.84      0.74       179
          9       0.94      0.72      0.82       205

avg / total       0.85      0.85      0.84      2000

Aug-04-16 19:06:39 epochs 27
1708 2000 0.854
             precision    recall  f1-score   support

          0       0.90      0.95      0.92       197
          1       0.93      0.95      0.94       225
          2       0.90      0.84      0.87       190
          3       0.90      0.82      0.86       198
          4       0.86      0.87      0.86       226
          5       0.87      0.54      0.67       162
          6       0.82      0.97      0.89       216
          7       0.91      0.89      0.90       202
          8       0.62      0.87      0.72       179
          9       0.92      0.77      0.84       205

avg / total       0.86      0.85      0.85      2000

Aug-04-16 19:06:42 epochs 28
1705 2000 0.853
             precision    recall  f1-score   support

          0       0.90      0.95      0.93       197
          1       0.92      0.94      0.93       225
          2       0.83      0.86      0.85       190
          3       0.87      0.77      0.82       198
          4       0.84      0.91      0.87       226
          5       0.81      0.54      0.65       162
          6       0.83      0.95      0.89       216
          7       0.93      0.88      0.91       202
          8       0.68      0.84      0.75       179
          9       0.91      0.79      0.85       205

avg / total       0.86      0.85      0.85      2000

Aug-04-16 19:06:44 epochs 29
1711 2000 0.856
             precision    recall  f1-score   support

          0       0.86      0.96      0.91       197
          1       0.92      0.94      0.93       225
          2       0.81      0.86      0.84       190
          3       0.83      0.79      0.81       198
          4       0.87      0.88      0.87       226
          5       0.84      0.59      0.70       162
          6       0.86      0.92      0.89       216
          7       0.93      0.91      0.92       202
          8       0.71      0.83      0.76       179
          9       0.92      0.81      0.86       205

avg / total       0.86      0.86      0.85      2000

Aug-04-16 19:06:46 epochs 30
1702 2000 0.851
             precision    recall  f1-score   support

          0       0.87      0.94      0.91       197
          1       0.92      0.93      0.93       225
          2       0.81      0.89      0.85       190
          3       0.82      0.76      0.79       198
          4       0.86      0.87      0.87       226
          5       0.82      0.61      0.70       162
          6       0.88      0.93      0.90       216
          7       0.96      0.87      0.91       202
          8       0.68      0.84      0.75       179
          9       0.90      0.80      0.85       205

avg / total       0.86      0.85      0.85      2000

Aug-04-16 19:06:49 epochs 31
1692 2000 0.846
             precision    recall  f1-score   support

          0       0.82      0.96      0.89       197
          1       0.93      0.95      0.94       225
          2       0.83      0.87      0.85       190
          3       0.81      0.77      0.79       198
          4       0.86      0.84      0.85       226
          5       0.86      0.59      0.70       162
          6       0.90      0.93      0.92       216
          7       0.92      0.90      0.91       202
          8       0.65      0.81      0.72       179
          9       0.89      0.78      0.83       205

avg / total       0.85      0.85      0.84      2000

Aug-04-16 19:06:51 epochs 32
1708 2000 0.854
             precision    recall  f1-score   support

          0       0.86      0.95      0.90       197
          1       0.95      0.96      0.96       225
          2       0.81      0.91      0.86       190
          3       0.81      0.76      0.78       198
          4       0.85      0.88      0.86       226
          5       0.88      0.57      0.69       162
          6       0.92      0.91      0.91       216
          7       0.96      0.89      0.93       202
          8       0.66      0.84      0.74       179
          9       0.87      0.80      0.83       205

avg / total       0.86      0.85      0.85      2000

Aug-04-16 19:06:54 epochs 33
1686 2000 0.843
             precision    recall  f1-score   support

          0       0.85      0.94      0.89       197
          1       0.92      0.96      0.94       225
          2       0.79      0.87      0.83       190
          3       0.79      0.77      0.78       198
          4       0.85      0.86      0.86       226
          5       0.78      0.64      0.70       162
          6       0.92      0.88      0.90       216
          7       0.92      0.91      0.92       202
          8       0.69      0.74      0.71       179
          9       0.88      0.77      0.82       205

avg / total       0.84      0.84      0.84      2000

Aug-04-16 19:06:56 epochs 34
1675 2000 0.838
             precision    recall  f1-score   support

          0       0.87      0.93      0.90       197
          1       0.91      0.91      0.91       225
          2       0.74      0.87      0.80       190
          3       0.79      0.80      0.79       198
          4       0.86      0.85      0.86       226
          5       0.81      0.72      0.76       162
          6       0.88      0.92      0.90       216
          7       0.95      0.86      0.90       202
          8       0.69      0.73      0.71       179
          9       0.85      0.73      0.79       205

avg / total       0.84      0.84      0.84      2000

Aug-04-16 19:06:58 epochs 35
1646 2000 0.823
             precision    recall  f1-score   support

          0       0.83      0.95      0.88       197
          1       0.87      0.95      0.91       225
          2       0.71      0.86      0.78       190
          3       0.84      0.81      0.83       198
          4       0.88      0.81      0.84       226
          5       0.86      0.59      0.70       162
          6       0.88      0.88      0.88       216
          7       0.93      0.85      0.89       202
          8       0.66      0.75      0.70       179
          9       0.81      0.72      0.76       205

avg / total       0.83      0.82      0.82      2000

Aug-04-16 19:07:01 epochs 36
1625 2000 0.812
             precision    recall  f1-score   support

          0       0.81      0.96      0.88       197
          1       0.87      0.94      0.91       225
          2       0.70      0.88      0.78       190
          3       0.84      0.75      0.79       198
          4       0.85      0.81      0.83       226
          5       0.77      0.55      0.64       162
          6       0.85      0.88      0.86       216
          7       0.91      0.84      0.87       202
          8       0.70      0.72      0.71       179
          9       0.81      0.72      0.76       205

avg / total       0.82      0.81      0.81      2000

Aug-04-16 19:07:03 epochs 37
1614 2000 0.807
             precision    recall  f1-score   support

          0       0.77      0.97      0.86       197
          1       0.88      0.93      0.90       225
          2       0.67      0.83      0.74       190
          3       0.85      0.76      0.81       198
          4       0.85      0.85      0.85       226
          5       0.81      0.51      0.63       162
          6       0.87      0.87      0.87       216
          7       0.91      0.82      0.86       202
          8       0.69      0.74      0.71       179
          9       0.80      0.71      0.75       205

avg / total       0.81      0.81      0.80      2000

Aug-04-16 19:07:06 epochs 38
1577 2000 0.788
             precision    recall  f1-score   support

          0       0.73      0.96      0.83       197
          1       0.85      0.87      0.86       225
          2       0.64      0.87      0.74       190
          3       0.80      0.74      0.77       198
          4       0.88      0.83      0.85       226
          5       0.81      0.52      0.63       162
          6       0.89      0.84      0.86       216
          7       0.91      0.82      0.86       202
          8       0.62      0.68      0.65       179
          9       0.81      0.69      0.75       205

avg / total       0.80      0.79      0.79      2000

Aug-04-16 19:07:08 epochs 39
1536 2000 0.768
             precision    recall  f1-score   support

          0       0.75      0.95      0.84       197
          1       0.84      0.86      0.85       225
          2       0.56      0.85      0.68       190
          3       0.72      0.77      0.74       198
          4       0.90      0.82      0.86       226
          5       0.80      0.50      0.62       162
          6       0.87      0.82      0.85       216
          7       0.94      0.83      0.88       202
          8       0.55      0.47      0.51       179
          9       0.80      0.70      0.75       205

avg / total       0.78      0.77      0.77      2000

Aug-04-16 19:07:10 epochs 40
1514 2000 0.757
             precision    recall  f1-score   support

          0       0.79      0.92      0.85       197
          1       0.87      0.77      0.82       225
          2       0.54      0.86      0.66       190
          3       0.67      0.75      0.71       198
          4       0.90      0.78      0.84       226
          5       0.73      0.60      0.66       162
          6       0.87      0.81      0.84       216
          7       0.95      0.85      0.90       202
          8       0.52      0.47      0.49       179
          9       0.85      0.69      0.76       205

avg / total       0.78      0.76      0.76      2000

Aug-04-16 19:07:13 epochs 41
1508 2000 0.754
             precision    recall  f1-score   support

          0       0.76      0.95      0.85       197
          1       0.90      0.72      0.80       225
          2       0.88      0.49      0.63       190
          3       0.64      0.74      0.69       198
          4       0.90      0.78      0.83       226
          5       0.80      0.56      0.66       162
          6       0.83      0.84      0.83       216
          7       0.95      0.85      0.90       202
          8       0.44      0.77      0.56       179
          9       0.74      0.80      0.77       205

avg / total       0.79      0.75      0.76      2000

Aug-04-16 19:07:15 epochs 42
1535 2000 0.767
             precision    recall  f1-score   support

          0       0.77      0.94      0.85       197
          1       0.90      0.69      0.78       225
          2       0.84      0.53      0.65       190
          3       0.64      0.77      0.70       198
          4       0.91      0.81      0.86       226
          5       0.83      0.57      0.67       162
          6       0.81      0.87      0.84       216
          7       0.94      0.87      0.90       202
          8       0.48      0.81      0.60       179
          9       0.80      0.77      0.79       205

avg / total       0.80      0.77      0.77      2000

Aug-04-16 19:07:18 epochs 43
1544 2000 0.772
             precision    recall  f1-score   support

          0       0.75      0.95      0.84       197
          1       0.75      0.93      0.83       225
          2       0.85      0.56      0.68       190
          3       0.87      0.56      0.68       198
          4       0.80      0.82      0.81       226
          5       0.81      0.57      0.67       162
          6       0.82      0.85      0.84       216
          7       0.95      0.85      0.90       202
          8       0.50      0.78      0.61       179
          9       0.83      0.77      0.79       205

avg / total       0.80      0.77      0.77      2000

Aug-04-16 19:07:20 epochs 44
1557 2000 0.778
             precision    recall  f1-score   support

          0       0.74      0.95      0.84       197
          1       0.77      0.94      0.85       225
          2       0.85      0.63      0.72       190
          3       0.88      0.58      0.70       198
          4       0.80      0.81      0.80       226
          5       0.79      0.57      0.67       162
          6       0.87      0.85      0.86       216
          7       0.94      0.83      0.88       202
          8       0.53      0.77      0.62       179
          9       0.78      0.77      0.77       205

avg / total       0.80      0.78      0.78      2000

Aug-04-16 19:07:22 epochs 45
1597 2000 0.798
             precision    recall  f1-score   support

          0       0.76      0.95      0.85       197
          1       0.87      0.92      0.89       225
          2       0.81      0.77      0.79       190
          3       0.83      0.63      0.71       198
          4       0.78      0.82      0.80       226
          5       0.88      0.54      0.67       162
          6       0.87      0.84      0.85       216
          7       0.94      0.85      0.89       202
          8       0.56      0.83      0.67       179
          9       0.82      0.77      0.79       205

avg / total       0.81      0.80      0.80      2000

Aug-04-16 19:07:25 epochs 46
1610 2000 0.805
             precision    recall  f1-score   support

          0       0.87      0.94      0.91       197
          1       0.91      0.86      0.88       225
          2       0.67      0.85      0.75       190
          3       0.82      0.63      0.71       198
          4       0.79      0.82      0.81       226
          5       0.78      0.67      0.72       162
          6       0.90      0.88      0.89       216
          7       0.96      0.87      0.91       202
          8       0.58      0.72      0.64       179
          9       0.83      0.77      0.79       205

avg / total       0.81      0.81      0.81      2000

Aug-04-16 19:07:28 epochs 47
1590 2000 0.795
             precision    recall  f1-score   support

          0       0.81      0.95      0.88       197
          1       0.85      0.96      0.90       225
          2       0.84      0.54      0.66       190
          3       0.65      0.86      0.74       198
          4       0.82      0.78      0.80       226
          5       0.85      0.62      0.72       162
          6       0.85      0.91      0.88       216
          7       0.95      0.82      0.88       202
          8       0.60      0.62      0.61       179
          9       0.79      0.79      0.79       205

avg / total       0.80      0.80      0.79      2000

Aug-04-16 19:07:30 epochs 48
1553 2000 0.776
             precision    recall  f1-score   support

          0       0.75      0.96      0.84       197
          1       0.88      0.93      0.91       225
          2       0.84      0.52      0.64       190
          3       0.60      0.87      0.71       198
          4       0.82      0.73      0.77       226
          5       0.81      0.54      0.65       162
          6       0.86      0.92      0.89       216
          7       0.94      0.83      0.88       202
          8       0.60      0.57      0.58       179
          9       0.75      0.80      0.77       205

avg / total       0.79      0.78      0.77      2000

Aug-04-16 19:07:32 epochs 49
1535 2000 0.767
             precision    recall  f1-score   support

          0       0.73      0.96      0.83       197
          1       0.90      0.88      0.89       225
          2       0.88      0.52      0.65       190
          3       0.59      0.87      0.70       198
          4       0.79      0.71      0.75       226
          5       0.93      0.46      0.62       162
          6       0.81      0.92      0.86       216
          7       0.95      0.82      0.88       202
          8       0.63      0.64      0.63       179
          9       0.71      0.80      0.75       205

avg / total       0.79      0.77      0.76      2000


Process finished with exit code 0





猜你喜欢

转载自blog.csdn.net/net_wolf_007/article/details/52121784