-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecond_ex.PY
More file actions
67 lines (40 loc) · 1.71 KB
/
second_ex.PY
File metadata and controls
67 lines (40 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# -*- coding: utf-8 -*-
"""Untitled0.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/16RXjDJkIS4WBz13IvKkd9eoUEKDfmRzR
"""
import tensorflow as tf
import numpy as np
# 특징 데이터 (X)
# [털, 날개]
x_data=np.array([[0,0], [1,0], [1,1], [0,0], [0,0], [0,1]])
# 레이블 데이터 (Y)
# 기타=[1,0,0]
# 포유류=[0,1,0]
# 조류=[0,0,1]
y_data=np.array([[1,0,0], [0,1,0], [0,0,1], [1,0,0], [1,0,0], [0,0,1]])
# [털, 날개]: 특징 데이터 (X) -> [기타, 포유류, 조류]: 레이블 데이터 (Y)
# [0,0] -> [1,0,0], 기타 (털도 없고, 날개도 없으면, 기타로 구분)
# [1,0] -> [0,1,0], 포유류 (털이 있고, 날개가 없으면, 포유류로 구분)
# [1,1] -> [0,0,1], 조류 (털이 있고, 날개도 있으면, 조류로 구분) *
# [0,0] -> [1,0,0], 기타 (털도 없고, 날개도 없으면, 기타로 구분)
# [0,0] -> [1,0,0], 기타 (털도 없고, 날개도 없으면, 기타로 구분)
# [0,1] -> [0,0,1], 조류 (털이 없고, 날개만 있으면, 조류로 구분) *
X=tf.placeholder(tf.float32)
Y=tf.placeholder(tf.float32)
W=tf.Variable(tf.random_uniform([2,3], -1.,1.))
b=tf.Variable(tf.zeros([3]))
L=tf.add(tf.matmul(X, W), b)
L=tf.nn.relu(L)
model=tf.nn.softmax(L)
cost=tf.reduce_mean(-tf.reduce_sum(Y*tf.log(model), axis=1))
optimizer=tf.train.GradientDescentOptimizer(learning_rate=0.01)
train_op=optimizer.minimize(cost)
init=tf.global_variables_initializer()
sess=tf.Session()
sess.run(init)
for step in range(100):
sess.run(train_op, feed_dict={X: x_data, Y: y_data})
if(step+1)%10 ==0:
print(step+1, sess.run(cost, feed_dict= {X: x_data, Y: y_data}))