TFlearn 准确率

在使用 TFlearn 构建深度神经网络后,我想计算网络的准确率。

以下是代码:

def create_model(self):    x = tf.placeholder(dtype= tf.float32, shape=[None, 6], name='x')    # Build neural network    input_layer = tflearn.input_data(shape=[None, 6])    net = input_layer    net = tflearn.fully_connected(net, 128, activation='relu')    net = tflearn.fully_connected(net, 64, activation='relu')    net = tflearn.fully_connected(net, 16, activation='relu')    net = tflearn.fully_connected(net, 2, activation='sigmoid')    net = tflearn.regression(net, optimizer='adam', loss='mean_square', metric='R2')    w = tf.Variable(tf.truncated_normal([2, 2], stddev=0.1))    b = tf.Variable(tf.constant(1.0, shape=[2]))    y = tf.nn.softmax(tf.matmul(net, w) + b, name='y')    model = tflearn.DNN(net, tensorboard_verbose=3)    return model

以下是训练部分:

train_data, train_goal, test_data, test_goal = self.normalize_data()        model = self.create_model()        # 使用训练集训练模型,并在测试集上评估        model.fit(train_data, train_goal, validation_set=0.2, n_epoch=10, show_metric=True, snapshot_epoch=True)        result = model.evaluate(test_data, test_goal)

我如何计算准确率?另外,要将其改为分类问题,我应该做哪些更改?谢谢


回答:

你可以这样做:

def create_model(self):    x = tf.placeholder(dtype= tf.float32, shape=[None, 6], name='x')    # Build neural network    input_layer = tflearn.input_data(shape=[None, 6])    net = input_layer    net = tflearn.fully_connected(net, 128, activation='relu')    net = tflearn.fully_connected(net, 64, activation='relu')    net = tflearn.fully_connected(net, 16, activation='relu')    net = tflearn.fully_connected(net, 2, activation='sigmoid')    net = tflearn.regression(net, optimizer='adam', loss='mean_square', metric='R2')    w = tf.Variable(tf.truncated_normal([2, 2], stddev=0.1))    b = tf.Variable(tf.constant(1.0, shape=[2]))    y = tf.nn.softmax(tf.matmul(net, w) + b, name='y')    return ynetwork = create_model()net = tflearn.regression(network, optimizer='RMSprop', metric='accuracy', loss='categorical_crossentropy')model = tflearn.DNN(net, show_metric=True, tensorboard_verbose=3)

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注