gpt4 book ai didi

machine-learning - TFlearn 准确率

转载 作者:行者123 更新时间:2023-11-30 09:51:45 28 4
gpt4 key购买 nike

使用 TFlearn 构建 DNN 后,我想计算网络的准确性。

这是代码:

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()

# train model with train sets & evaluate on test sets
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 y

network = create_model()
net = tflearn.regression(network, optimizer='RMSprop', metric='accuracy', loss='categorical_crossentropy')

model = tflearn.DNN(net, show_metric=True, tensorboard_verbose=3)

关于machine-learning - TFlearn 准确率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43894357/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com