반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- vscode
- discrete_scatter
- web 용어
- postorder
- classification
- paragraph
- pycharm
- web 사진
- 대이터
- 머신러닝
- inorder
- 자료구조
- broscoding
- C언어
- web
- CES 2O21 참여
- Keras
- 웹 용어
- java역사
- cudnn
- html
- mglearn
- 데이터전문기관
- 결합전문기관
- CES 2O21 참가
- web 개발
- tensorflow
- bccard
- 재귀함수
- KNeighborsClassifier
Archives
- Today
- Total
bro's coding
tensorflow.irisdata적용 본문
반응형
# 속성 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