반응형
Notice
Recent Posts
Recent Comments
Link
관리 메뉴

bro's coding

tensorflow.irisdata적용 본문

[AI]/python.tensorflow

tensorflow.irisdata적용

givemebro 2020. 5. 11. 18:21
반응형
# 속성 1개

from sklearn.datasets import load_iris
iris=load_iris()
X=tf.constant(iris.data[:,2],dtype=tf.float32)
y=tf.constant(iris.data[:,3],dtype=tf.float32)

w=tf.Variable(tf.random.normal([]))
b=tf.Variable(tf.random.normal([]))

pred_y=w*X+b
mse=tf.reduce_mean(tf.square(y-pred_y))

optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.01)
train_op=optimizer.minimize(mse)

costs=[]

tf.global_variables_initializer().run()

for i in range(30):
    sess.run(train_op)
    costs.append(mse.eval())
plt.plot(costs)

# 속성 3개

from sklearn.datasets import load_iris
iris=load_iris()
X=tf.constant(iris.data[:,[0,1,2]],dtype=tf.float32)
y=tf.constant(iris.data[:,3],dtype=tf.float32)

w=tf.Variable(tf.random.normal([3,1]))
b=tf.Variable(tf.random.normal([]))

pred_y=X@w+b
mse=tf.reduce_mean(tf.square(y-pred_y))

optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.01)
train_op=optimizer.minimize(mse)

costs=[]

tf.global_variables_initializer().run()

for i in range(30):
    sess.run(train_op)
    costs.append(mse.eval())
plt.plot(costs)

# 속성 3개
# 중간층 1개
from sklearn.datasets import load_iris
iris=load_iris()
X=tf.placeholder(dtype=tf.float32)
y=tf.constant(iris.data[:,3],dtype=tf.float32)

w=tf.Variable(tf.random.normal([3,10]))
b=tf.Variable(tf.random.normal([10]))

u=tf.nn.relu(X@w+b)

ww=tf.Variable(tf.random.normal([10,1]))
bb=tf.Variable(tf.random.normal([]))

pred_y=u@ww+bb

mse=tf.reduce_mean(tf.square(y-pred_y))

optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.001)
train_op=optimizer.minimize(mse)

costs=[]

tf.global_variables_initializer().run()

for i in range(30):
    sess.run(train_op,)
    costs.append(mse.eval())
plt.plot(costs)

# 속성 3개
# 중간층
from sklearn.datasets import load_iris
iris=load_iris()
X=tf.constant(iris.data[:,[0,1,2]],dtype=tf.float32)
y=tf.constant(iris.data[:,3],dtype=tf.float32)

w=tf.Variable(tf.random.normal([3,5]))
b=tf.Variable(tf.random.normal([5]))

u=tf.nn.relu(X@w+b)
# 150x5
ww=tf.Variable(tf.random.normal([5,5]))
bb=tf.Variable(tf.random.normal([5]))

uu=tf.nn.relu(u@ww+bb)

www=tf.Variable(tf.random.normal([5,1]))
bbb=tf.Variable(tf.random.normal([]))

pred_y=uu@www+bbb

mse=tf.reduce_mean(tf.square(y-pred_y))

optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.001)
train_op=optimizer.minimize(mse)

costs=[]

tf.global_variables_initializer().run()

for i in range(300):
    sess.run(train_op)
    costs.append(mse.eval())
plt.plot(costs)

반응형

'[AI] > python.tensorflow' 카테고리의 다른 글

tensorflow.분류(중간층)  (0) 2020.05.12
tensorflow.분류(중간층).relu,sigmoid 비교  (0) 2020.05.12
tensorflow.분류(중간층X)  (0) 2020.05.12
tensorflow.placeholder  (0) 2020.05.11
tensorflow.optimizer  (0) 2020.05.11
tensorflow.행렬곱,전치행렬  (0) 2020.05.11
tensorflow.Session/InteractiveSession  (0) 2020.05.11
tensorflow.basic  (0) 2020.05.11
Comments