• 카테고리

    질문 & 답변
  • 세부 분야

    딥러닝 · 머신러닝

  • 해결 여부

    미해결

cost 값이 변화가 없다는 것은 무엇을 의미하는 건가요?

18.07.24 14:36 작성 조회수 156

0

아래는 제가 만든 텐서플로우를 이용한 로지스틱스 회귀분석의 코드입니다.

'''

import tensorflow as tf

import pandas as pd

import numpy as np

xy = np.loadtxt("D:/deep1/projectdata/sixx/test.csv", delimiter=",")

df = pd.read_csv("D:/deep1/projectdata/sixx/test.csv", encoding='mbcs')

x_data = xy[:, 10:18]

y_data = xy[:, [-1]]

column_len = len(df.columns.values.tolist()) - 1 # 맨 마지막 [-1]컬럼을 제외

column_len = 8

X = tf.placeholder(tf.float32, shape=[None, column_len])

Y = tf.placeholder(tf.float32, shape=[None, 1])

W = tf.Variable(tf.random_normal([column_len, 1]), name='weight')

b = tf.Variable(tf.random_normal([1]))

hypothesis = tf.sigmoid(tf.matmul(X, W) + b)

hypothesis = tf.clip_by_value(hypothesis,1e-5,1-(1e-5)) # 상한, 하한 설정

cost = -tf.reduce_mean(Y tf.log(hypothesis) + (1 - Y) (tf.log(1 - hypothesis)))

optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.01)

train = optimizer.minimize(cost)

sess = tf.Session()

sess.run(tf.global_variables_initializer())

for step in range(1001):

cost_val, W_val, bval, = sess.run([cost, W, b, train], feed_dict={X:x_data, Y:y_data})

if step % 100 == 0:

print('step :', step, " , cost_val :", cost_val, ' , W :', W_val, ' , b_val :', b_val)

print('step :', step, " , cost_val :", cost_val)

predicted = tf.cast(hypothesis > 0.5, dtype=tf.float32)

accuracy = tf.reduce_mean(tf.cast(tf.equal(predicted, Y), dtype=tf.float32))

h, c, a = sess.run([hypothesis, predicted, accuracy], feed_dict={X: x_data, Y:y_data})

print('n', h, 'n',c, 'n',a)

print(a)

'''

이는 제가 사용한 코드입니다.

결과는 아래와 같이 나왔습니다.

step : 0 , cost_val : 10.370755

step : 100 , cost_val : 1.0823343

step : 200 , cost_val : 1.0823343

step : 300 , cost_val : 1.0823343

step : 400 , cost_val : 1.0823343

step : 500 , cost_val : 1.0823343

step : 600 , cost_val : 1.0823343

step : 700 , cost_val : 1.0823343

step : 800 , cost_val : 1.0823343

step : 900 , cost_val : 1.0823343

step : 1000 , cost_val : 1.0823343

이는 local minimum에 도달했기 때문에 나온 현상일까요? 아니면 뭔가 다른 문제가 있는 걸까요?

또 계속 돌리다보면 아래와 같은 결과를 얻을 때도 있습니다.

step : 0 , cost_val : 10.416572

step : 100 , cost_val : 10.415087

step : 200 , cost_val : 10.412803

step : 300 , cost_val : 10.4067335

step : 400 , cost_val : 10.376276

step : 500 , cost_val : 1.0819494

step : 600 , cost_val : 1.0819463

step : 700 , cost_val : 1.0819432

step : 800 , cost_val : 1.0819402

step : 900 , cost_val : 1.0819372

step : 1000 , cost_val : 1.0819342

랜덤하게 결정된 W, b의 값 때문에 결과가 조금씩 바뀌는 것은 이해하겠지만 cost값이 1이하로 내려가지 않는다는 점이 마음에 걸립니다.

이를 해결하기 위해서는 step 1000에서 나온 W, b값을 위의 Variable객체에 넣고 learning_rate를 작게해서 돌려보면 해결 할 수 있는 걸까요?

조언을 듣고 싶습니다.

답변 0

답변을 작성해보세요.

답변을 기다리고 있는 질문이에요.
첫번째 답변을 남겨보세요!