반응형
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
- classification
- web 용어
- 웹 용어
- 데이터전문기관
- C언어
- 머신러닝
- CES 2O21 참여
- KNeighborsClassifier
- discrete_scatter
- broscoding
- 재귀함수
- html
- Keras
- web 개발
- 자료구조
- tensorflow
- paragraph
- java역사
- vscode
- web 사진
- CES 2O21 참가
- inorder
- pycharm
- mglearn
- web
- postorder
- bccard
- 결합전문기관
- 대이터
- cudnn
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