텐서플로 3

keras : 단순선형회귀 모델

import tensorflow as tf from keras.models import Sequential from keras.layers import Dense from keras import optimizers import numpy as np # x_data, y_data 설정하고 상관계수 확인 x_data = [1.,2.,3.,4.,5.] y_data = [1.2,2.0,3.0,3.5,5.5] print('상관계수 : ', np.corrcoef([x_data, y_data])) # 모델 입력, 컴파일 model = Sequential() model.add(Dense(units = 1, input_dim = 1, activation = 'linear' )) model.compile(optimizer..

Tensorflow 와 Keras

# 선형회귀 분석전 실습 cost를 최소화 하는 과정을 시각화 Keras를 사용하지 않고 Tensorflow만 사용했다. import tensorflow as tf import matplotlib.pyplot as plt x = [1,2,3,4,5] y = [2,4,6,8,10] b = 0 hypothesis = w * x + b ( w : weight, b : bias) w_val = [] cost_val = [] for i in range(-30, 50): feed_w = i * 0.1 # 0.1 은 학습률(learning rate) hypothesis = tf.multiply(feed_w, x) + b # y = wx+b cost = tf.reduce_mean(tf.square(hypothesis ..

Tensorflow Basic

1. type import tensorflow as tf # tensorflow import print(tf.__version__) # version check print(1, type(1)) print(1, type([1])) print(tf.constant(1), type(tf.constant(1))) # scalar, 0 D tensor print(tf.constant([1])) # vector, 1 D tensor print(tf.constant([[1]])) # matrix, 2 D tensor print(tf.rank(tf.constant([[1]]))) # 2차원 확인 ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ 1 1 tf.Tensor(1, shape=(), dtype=int..