cost 값이 변화가 없다는 것은 무엇을 의미하는 건가요?
231
작성한 질문수 1
아래는 제가 만든 텐서플로우를 이용한 로지스틱스 회귀분석의 코드입니다.
'''
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
tf.placeholder 에러
0
528
1
파이썬 3.10 버전 tensor flow 설치 문의
0
509
0
안녕하세요
0
285
0
딥러닝 vs 머신러닝
0
379
0
출력이미지 사이즈 계산법이 유다시티 강좌와 달라요
0
405
2
train 의미
0
369
0
텐서플로우
0
583
2
텐서플로1.0 -> 2.0설치로 인한 1.0 버전 에러
0
458
1
Tensorflow 설치 질문있습니다..
2
320
1
ModuleNotFoundError: No module named 'tensorflow.examples.tutorials' Error 해결법
0
2832
0
강의 잘 들었습니다!
0
301
0
파이썬을 잘 다뤄야 강의를 들을 수 있나요?
0
302
0
plot range
0
275
1
안녕하세요. 수업 너무 재미있게 보고 있던도중 오류가 생겼습니다 ㅠㅠ
0
293
2
validation set을 굳이 만들어야 되나요?
0
425
0
Epoch을 여러번 돌리면..
0
492
1
numpy로 loadtxt 할 때 이런 오류가 뜨는데 도대체 뭔가요 ㅠㅠ?
0
791
0
lab04-1 7분 30초 부분에서 hypothesis와 bias shape에 관한 질문입니다.
0
331
1
tf.train.batch 속도 질문
0
229
0
lab 04-1 multi-variable linear regression 의 cost 값 질문
0
183
1
어렵군요.
0
259
0
Minmaxscaler
0
218
0
cost구하는 공식 reduce_sum으로 되어있는거 오타인가요?
0
259
1
H(x)-y 를 제곱을 하는 이유가 궁금합니다.
0
215
0





