## Modeling 하시오
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
lm = LinearRegression()
train_set.head()
train_x = train_set[['Temperature', 'Leaflets']]
train_y = train_set[['Lemon']]

test_x = test_set[['Temperature', 'Leaflets']]
test_y = test_set[['Lemon']]

lm.fit(train_x, train_y)

y_pred = lm.predict(test_x)

mse = mean_squared_error(y_pred, test_y)

print(lm.coef_)
print(lm.intercept_)
print(mse)

'Develop > AI' 카테고리의 다른 글

MNIST  (0) 2019.07.14
placeholder / feed_dick  (0) 2019.07.14

import tensorflow as tf

# 데이터 준비
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()

x_train = x_train.reshape(-1, 28*28)
x_test = x_test.reshape(-1, 28*28)

y_train = tf.keras.utils.to_categorical(y_train)
y_test = tf.keras.utils.to_categorical(y_test)

print(x_train.shape, y_train.shape)
print(x_test.shape, y_test.shape)

# 모델 만들기
X = tf.placeholder(tf.float32, shape=[None, 784])
Y = tf.placeholder(tf.float32, shape=[None, 10])

# Hidden Layer를 위한 Weight
W1 = tf.Variable(tf.random_normal(shape=[784, 256]))
B1 = tf.Variable(tf.random_normal(shape=[256]))
H1 = tf.matmul(X, W1)+B1
H1 = tf.nn.relu(H1)

# H1의 shape: (None, 256)

W2 = tf.Variable(tf.random_normal(shape=[256, 256]))
B2 = tf.Variable(tf.random_normal(shape=[256]))
H2 = tf.matmul(H1, W2) + B2
H2 = tf.nn.relu(H2)

# H2의 shape: (None, 256)

W3 = tf.Variable(tf.random_normal(shape=[256,128]))
B3 = tf.Variable(tf.random_normal(shape=[128]))
H3 = tf.matmul(H2, W3) + B3
H3 = tf.nn.relu(H3)

# H3의 shape: (None, 128)
W4 = tf.Variable(tf.random_normal(shape=[128, 10]))
B4 = tf.Variable(tf.random_normal(shape=[10]))

logit = tf.matmul(H3, W4) + B4

loss = tf.nn.softmax_cross_entropy_with_logits(logits=logit, labels=Y)
loss = tf.reduce_mean(loss)

optimizer = tf.train.AdamOptimizer(0.01).minimize(loss)

pred = tf.nn.softmax(logit)
acc = tf.equal(tf.argmax(pred, axis=1), tf.argmax(Y, axis=1))
acc = tf.reduce_mean(tf.cast(acc, tf.float32))

# 모델 학습
sess = tf.Session()
sess.run(tf.global_variables_initializer())

epochs = 10
batch  = 512
n_batch = len(x_train) // batch
for e in range(epochs):
  for b in range(n_batch):
    x = x_train[b * batch : (b+1) * batch]
    y = y_train[b * batch : (b+1) * batch]
    sess.run(optimizer, feed_dict={X:x,Y:y})
    
#    print("{0: .2f}%".format(100 * sess.run(acc, feed_dict={X:x, Y:y})))


# 모델 평가
accuracy = sess.run(acc, feed_dict={X: x_test, Y: y_test})
print("평가")
print("{0: .2f}%".format(accuracy * 100))

import tensorflow as tf

#############
# 데이터 준비
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()

x_train = x_train.reshape(60000, 784)
x_test = x_test.reshape(10000, 784)

y_train = tf.keras.utils.to_categorical(y_train)
y_test = tf.keras.utils.to_categorical(y_test)

print(x_train.shape, y_train.shape)
print(x_test.shape, y_test.shape)

###############
# 모델 선택

# 데이터 받을 곳 정의
X = tf.placeholder(tf.float32, shape=[None, 784])
Y = tf.placeholder(tf.float32, shape=[None, 10])

# 머신이 학습할 값 정의
W = tf.Variable(tf.random_normal(shape=[784,10]))
B = tf.Variable(tf.random_normal(shape=[10]))

# logit 계산
logit = tf.matmul(X,W)+B

# 값 예측
pred = tf.nn.softmax(logit)

# loss 계산
loss = tf.nn.softmax_cross_entropy_with_logits_v2(logits = logit, labels=Y)
loss = tf.reduce_mean(loss)

# optimizer 설정
optimizer = tf.train.AdamOptimizer(0.01).minimize(loss)

# 정확도 계산
acc = tf.equal(tf.argmax(pred, axis=1), tf.argmax(Y, axis=1))
acc = tf.reduce_mean(tf.cast(acc, tf.float32))

###################
# 모델학습

# 세션 정의 및 초기화
sess = tf.Session()
sess.run(tf.global_variables_initializer())

#배치 학습
epochs = 20
batch = 512

for e in range(epochs):
  n = len (x_train) // batch
  for b in range(n):
    x = x_train[b * batch : (b+1) * batch]
    y = y_train[b * batch : (b+1) * batch]
    sess.run(optimizer, feed_dict={X:x, Y:y})
    
 #   print (sess.run(acc, feed_dict={X:x_train, Y:y_train}))

    
############
# 모델평가
print("모델평가")
print(sess.run(acc, feed_dict={X:x_test, Y:y_test}))

'Develop > AI' 카테고리의 다른 글

Scikit-learn LinearRegression  (0) 2019.07.15
placeholder / feed_dick  (0) 2019.07.14

# 데이터 준비
x = 3.0
y = 10.0

tf.reset_default_graph()
# 모델만들기
X = tf.placeholder(tf.float32, shape=())
Y = tf.placeholder(tf.float32, shape=())

W = tf.Variable(tf.random_normal(shape=()))
B = tf.Variable(tf.random_normal(shape=()))
H = tf.add(tf.multiply(x, W), B)

loss = tf.square(tf.subtract(y, H))
optimizer = tf.train.GradientDescentOptimizer(0.01).minimize(loss)

# 학습
sess = tf.Session()
sess.run(tf.global_variables_initializer())

for i in range(20):
  sess.run(optimizer, feed_dict = {X:x, Y:y})
  print(sess.run([loss, W, B], feed_dict={X:x, Y:y}))

'Develop > AI' 카테고리의 다른 글

Scikit-learn LinearRegression  (0) 2019.07.15
MNIST  (0) 2019.07.14

문쥬가 동굴에 관심을 갖기 시작해서...하지만 일반동굴은 조금더 크면 가보라는 조언에 따라 선택된 곳은 광명 동굴...

일반적인 동굴은 아니고 폐광을 동굴로 잘 꾸며놓았다고 한다. (사람들 다니기 쉽게 ㅋ)


정확히 기억나지는 않지만...나중에 알았다. 광명동굴이 2017년 대한민국에서 가봐야할 곳(?)으로 선정 했다는 것을

즉, 사람이 정말 많았다. 광명동굴 도착 300미터 전 터널부터 주차하기까지 한시간 정도 소요된 것으로 기억한다.

가려면 일찍 가는것이 좋을 것 같다.

 


 * 주차하고나서 가장처음 보인 곳은 광명시 자원회수 시설 

 


 

* 주차장부터 동굴까지 올라가는 길목

 

 



* 동굴근처까지 올라오면 큰 LED 전광판과 무대가 보인다. 공연도 진행 하는 듯 

  

 

 

* 드디어 광명동굴 입구... 한여름이었는데 안에는 꾀나 쌀쌀하다.  

  

 

 

* 동굴내부는 식물원 및 수족관, LED로 화려하게 꾸며 놓았다.

 

 

 

 * 빛나는 생명체.. 그것은 LED 조형물들... 여러 LED 작품을 볼 수 있다.

  

  

  

  

 

 

 

  

 

 

 * 가장 당황했던... 동굴 내부로 내려가면 찾을 수(?) 있는 용한마리와... 골룸! (계단 내려갔다 올라오는 길은 힘들다 ㅋ)

  

  

 


* 이것은 황금패를 구입해서 걸 수있는 소망의 벽! (물론 나는 구매하지 않았다...)

  

 

 

 

* 동굴 내부에 기다렸다가 볼 수 있는 미디어 파사드 쇼 (동굴 벽에다 쇼쇼쇼) 

 

 

 

 * 동굴탐사 후 나오면서 마주할 수 있는 와인테마 거리(?). 시음은 물론 구매도 가능하다. 

 

 

 

  

 * 동굴밖에서 주차장으로 이동하면서 만날 수 있는 재활용품을 이용한 작품들을 만나 볼 수 있다.

  

'Life > Place' 카테고리의 다른 글

2017 여수여행  (0) 2017.08.02
2017 서울 모터쇼  (0) 2017.04.13

+ Recent posts