Сначала я использую предварительную обработку skleain для нормализации данных.
Я называю функциональную модель, где приведенный ниже код вставлен с узлами и слоем нет.
если L = 1, иначе L = 2
В соответствии с этим я определяю вес и уклон. Код работает без ошибок, но медленно с точностью до 50%.
if(L==1):
# Defining the weights and the biases for the neural network
weights = {
'w1': tf.Variable(tf.truncated_normal([r, nodes],stddev=1)),
'out': tf.Variable(tf.truncated_normal([nodes, n_class],stddev=1))
}
biases = {
'b1': tf.Variable(tf.random_normal([nodes])),
'out': tf.Variable(tf.random_normal([n_class]))
}
# Calling the defined model
y = Network(x, weights, biases, L)
#print(y.shape)
# Definning the cost function and optimizer
cost_function = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits=y, labels=y_actual))
#cost_function = tf.losses.sigmoid_cross_entropy(multi_class_labels=tf.squeeze(tf.one_hot(y, depth=2), axis=1),logits=logits)
#regularizers = tf.nn.l2_loss(weights['w1'])+tf.nn.l2_loss(weights['out'])
cost_function = tf.reduce_mean(cost_function+ beta*regularizers)
training_step = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost_function)
else:
weights = {
'w1': tf.Variable(tf.truncated_normal([r, nodes],stddev=1)),
'w2': tf.Variable(tf.truncated_normal([nodes, nodes],stddev=1)),
'out': tf.Variable(tf.truncated_normal([nodes, n_class],stddev=1))
}
biases = {
'b1': tf.Variable(tf.random_normal([nodes])),
'b2': tf.Variable(tf.random_normal([nodes])),
'out': tf.Variable(tf.random_normal([n_class]))
}
# Calling the defined model
y = Network(x, weights, biases, L)
cost_function = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits=y, labels=y_actual))
#regularizers = tf.nn.l2_loss(weights['w1'])+tf.nn.l2_loss(weights['w2'])+tf.nn.l2_loss(weights['out'])
cost_function = tf.reduce_mean(cost_function+ beta*regularizers)
training_step = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost_function)