>>> import tensorflow.compat.v1 as tf
>>> tf.disable_v2_behavior()
>>> import numpy as np
>>> array1 = np.array([[30, 0, 4, 5, 7, 8, 7.5, 8, 8, 8.5, 4, 3, 1]
... ,[30, 0, 4, 5, 7, 8, 8, 8.5, 4, 3, 1,0,0]
... ,[30, 0.5, 3, 4.85, 6.5, 8, 8.23, 8.5, 5, 4.5, 3.2, 1, 0]
... ,[30, 0.5, 3, 6, 8.23, 7.5, 5, 4.5, 3.2, 1, 0, 0, 0]
... ,[30, 0.5, 3, 3.85, 5.57, 7.52, 8.23, 8.5, 5, 4.5, 3.2, 1, 0]
... ,[30, 0.5, 3, 5, 8, 5, 3.2, 1,1.521,1.22,0,0,0]
... ,[40, 0, 3, 6, 7, 9, 9, 9.5, 7, 4, 2,1,0]
... ,[40, 1.5, 2, 3.85, 5.5, 8, 9.23, 9.5, 8, 6.5, 5.2, 3, 2]
... ,[40, 1.25, 4, 6, 8.23, 8.5, 7, 5.5, 4.2, 1, 2, 1, 0]
... ,[50, 1.2345, 4, 4.85, 6.57, 8.52, 9.23, 9.5, 6, 5.5, 4.2, 2, 1]
... ,[50, 1, 4.52, 7, 9, 8, 4.2, 3,2.56,2,1,0,0]])
#분리
>>> X_data = array1[:,1:]
>>> Y_data = array1[:,:1]
>>>
>>> X = tf.placeholder(tf.float32, shape = [None, X_data.shape[1]])
>>> Y = tf.placeholder(tf.float32, shape = [None, 1])
>>> W = tf.Variable(tf.random_normal([X_data.shape[1],1]), name = 'weight')
>>> b = tf.Variable(tf.random_normal([1]), name = 'bias')
>>>
>>> hypothesis = tf.matmul(X, W) +b
>>> cost = tf.reduce_mean(tf.square(hypothesis - Y))
>>> optimizer = tf.train.GradientDescentOptimizer(learning_rate = 1e-5)
>>> train = optimizer.minimize(cost)
>>> sess = tf.compat.v1.Session()
>>> sess.run(tf.global_variables_initializer())
#학습
>>> for step in range(2001):
... cost_val , hy_val,_ = sess.run([cost, hypothesis, train], feed_dict = {X:X_data, Y:Y_data})
... if step % 100 == 0:
... print("[", step, "] Cost:" , cost_val, "[prediction: ",hy_val,"\n")
...
#임의의 데이터 넣기
>>> one = np.array([0,3,4,5,7,8.56, 8, 8, 7.5, 4, 3,1])
>>> pre = sess.run(hypothesis, feed_dict = {X:one.reshape(1,X_data.shape[1])})
>>>
>>> pre
array([[38.37631]], dtype=float32)
# 확인
>>> pre = sess.run(hypothesis, feed_dict = {X:X_data[2].reshape(1,X_data.shape[1])})
>>> X_data[2]
array([0.5 , 3. , 4.85, 6.5 , 8. , 8.23, 8.5 , 5. , 4.5 , 3.2 , 1. ,
0. ])
>>> pre
array([[33.43629]], dtype=float32)
#넣은 데이터 확인
>>> for step in range(X_data.shape[0]):
... pre = sess.run(hypothesis, feed_dict = {X:X_data[step].reshape(1,X_data.shape[1])})
... print("\n Pre : [" , pre, "]")
다시
a = [[30, 0, 4, 5, 7, 8, 7.5, 8, 8, 8.5, 4, 3, 1]
,[30, 0, 4, 5, 7, 8, 8, 8.5, 4, 3, 1,0,0]
,[30, 0.5, 3, 4.85, 6.5, 8, 8.23, 8.5, 5, 4.5, 3.2, 1, 0]
,[30, 0.5, 3, 6, 7.23, 7.5, 5, 4.5, 3.2, 1, 0, 0, 0]
,[30, 0.5, 3, 4.85, 6.5, 7, 8.23, 8.5, 5, 4.5, 3.2, 1, 0]
,[30, 0.5, 3, 6, 8.23, 7.5, 5, 4.5, 3.2, 1, 0, 0, 0]
,[30, 0.5, 3, 3.85, 5.57, 7.52, 8.23, 8.5, 5, 4.5, 3.2, 1, 0]
,[30, 0.5, 3, 5, 8, 5, 3.2, 1,1.521,1.22,0,0,0]
,[30, 0.5, 3, 5, 8, 7, 3.2, 1,1.521,1.22,0,0,0]
,[40, 0, 3, 6, 7, 9, 9, 9.5, 7, 4, 2,1,0]
,[40, 1.5, 2, 3.85, 5.5, 8, 9.23, 9.5, 8, 6.5, 5.2, 3, 2]
,[40, 1, 3, 6, 7, 9, 9, 9.5, 7, 4, 2,1,0]
,[40, 1.5, 2, 3.85, 5.5, 7, 9.23, 9.5, 8, 6.5, 5.2, 3, 2]
,[40, 1.25, 4, 6, 8.23, 8.5, 7, 5.5, 4.2, 1, 2, 1, 0]
,[40, 1.25, 4, 6, 8.23, 8.5, 7, 5.5, 3.2, 1, 2, 1, 0]
,[40, 1.5, 4, 4.85, 5.57, 6.52, 7.23, 8.5, 7, 5.5, 4.2, 2, 1]
,[40, 1.25, 4, 6, 8.23, 7.5, 7, 5.5, 4.2, 1, 2, 1, 0]
,[30, 0.5, 3, 3.85, 6.57, 7.52, 8.23, 8.5, 5, 4.5, 3.2, 2, 1]
,[50, 1.2345, 4, 4.85, 6.57, 8.52, 9.23, 9.5, 6, 5.5, 4.2, 3, 1]
,[50, 1, 4.52, 7, 9, 8, 4.2, 3,2.56,2,1,3,0]
,[50, 1, 4, 7, 7.55, 8, 9, 9.5, 8, 6, 5,4,2]
,[50, 1.5, 3, 3.85, 4.5, 7, 8.23, 9.5, 9, 8.5, 7.2, 3, 2]
,[50, 1.5, 2, 3.85, 4.5, 7, 8.23, 9.5, 9, 8.5, 7.2, 4, 2]
,[50, 1.5, 3, 3.85, 5.5, 7, 8.23, 9.5, 9, 8.5, 7.2, 5, 2]
,[50, 1.5, 3, 3.85, 6.5, 7, 8.23, 9.5, 9, 8.5, 7.2, 4, 2]
,[50, 1.5, 3, 4.85, 5.5, 7, 8.23, 9.5, 9, 8.5, 7.2, 3, 2]
,[50, 1, 4, 6, 7.55, 8, 9, 9.5, 8, 6, 5,4,2]]
학습을 한 뒤,
각 열의 값을 다시 넣어서 값 프린트 해봤더니
Pre : [ [[46.75972]] ]
Pre : [ [[31.548428]] ]
Pre : [ [[36.98503]] ]
Pre : [ [[25.189035]] ]
Pre : [ [[36.26932]] ]
Pre : [ [[26.260065]] ]
Pre : [ [[34.01662]] ]
Pre : [ [[21.888231]] ]
Pre : [ [[23.319647]] ]
Pre : [ [[34.956734]] ]
Pre : [ [[42.601963]] ]
Pre : [ [[35.308285]] ]
Pre : [ [[41.886253]] ]
Pre : [ [[32.351498]] ]
Pre : [ [[34.157917]] ]
Pre : [ [[39.24333]] ]
Pre : [ [[31.63579]] ]
Pre : [ [[38.625755]] ]
Pre : [ [[47.11372]] ]
Pre : [ [[42.02036]] ]
Pre : [ [[53.128895]] ]
Pre : [ [[46.02556]] ]
Pre : [ [[48.576]] ]
Pre : [ [[53.40608]] ]
Pre : [ [[51.32236]] ]
Pre : [ [[48.725395]] ]
Pre : [ [[51.50008]] ]
나왔다. 그냥 데이터가 많으면 잘 될 것 같다.
[0,3,4,5,7,8,6,5,4,3.2, 2,1]
이 데이터를 넣어서 함 봤더니
array([[32.406696]], dtype=float32)
나왔다
'project > tansorflow' 카테고리의 다른 글
tensorflow (Python 3.7 cpu)실습4 - 값 넣기(복습) (0) | 2020.07.11 |
---|---|
tensorflow (Python 3.7 cpu) 실습3 - 값 넣어주기 (0) | 2020.07.11 |
tensorflow (Python 3.7 cpu)실습2 - graph그리기 (0) | 2020.07.10 |
Tensorflow (python 3.7) 실습1 (0) | 2020.07.08 |