ed-kyu
ee
ed-kyu
전체 방문자
오늘
어제
  • 분류 전체보기 (26)
    • 딥러닝, 머신러닝 (17)
      • NLP (0)
      • Vision (0)
      • 모두를 위한 딥러닝 강의 복습 (9)
      • Andrew Ng 강의 (0)
      • 캐글 (1)
      • 수학 (0)
      • DL Basic (5)
      • 논문 스터디 (2)
      • Product Serving (0)
    • TIL (1)
      • OS (0)
      • Network (0)
      • DB (0)
      • Docker (0)
      • Data Engineering (1)
    • 알고리즘 문제풀이 (3)
      • Baekjoon Algorithm (3)
      • Programmers (0)
    • 주제 없음 (5)
      • Python (2)
      • 기록 (1)
      • etc (2)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • 오블완
  • Kaggle
  • DeepLearningZeroToAll
  • 유기농 배추
  • ml
  • 티스토리챌린지
  • 백준
  • Python
  • 1012

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
ed-kyu

ee

딥러닝, 머신러닝/모두를 위한 딥러닝 강의 복습

TensorFlow로 파일에서 데이터 읽어오기

2022. 1. 4. 21:42

모두를 위한 딥러닝 강의 시즌1을 듣고 복습한 내용입니다.

 

numpy 활용 + slicing

import numpy as np

b = np.array([[1, 2, 3, 4], 
              [5, 6, 7, 8],
              [9, 10, 11, 12]])
              
b[:, 1]
# array([2, 6, 10])

b[-1]
# array([9, 10, 11, 12])

b[-1, :]
# array([9, 10, 11, 12])

b[-1, ...]
# array([9, 10, 11, 12])

b[0:2, :]
# array([[1, 2, 3, 4],
#        [5, 6, 7, 8]])
         

# 'data.csv'
# EXAM1, EXAM2, EXAM3, FINAL
# 73, 80, 75, 152
# 93, 88, 93, 185
# 89, 91, 90, 180

xy = np.loadtxt('data.csv', delimier=',', dtype=np.float32)
x_data = xy[:, 0:-1]
y_data = xy[:, [-1]]

 


텐서플로우 코드

import tensorflow as tf
import numpy as np

xy = np.loadtxt('../data-01-test-score.csv', delimiter=',', dtype=np.float32)
x_data = xy[:, 0:-1]
y_data = xy[:, [-1]]

# Make sure the shape and data are OK
print(x_data, "\nx_data shape:", x_data.shape)
print(y_data, "\ny_data shape:", y_data.shape)

# data output
'''
[[ 73.  80.  75.]
 [ 93.  88.  93.]
 ...
 [ 76.  83.  71.]
 [ 96.  93.  95.]] 
x_data shape: (25, 3)
[[152.]
 [185.]
 ...
 [149.]
 [192.]] 
y_data shape: (25, 1)
'''
tf.model = tf.keras.Sequential()
# activation function doesn't have to be added as a separate layer. Add it as an argument of Dense() layer
tf.model.add(tf.keras.layers.Dense(units=1, input_dim=3, activation='linear'))
# tf.model.add(tf.keras.layers.Activation('linear'))
tf.model.summary()

tf.model.compile(loss='mse', optimizer=tf.keras.optimizers.SGD(lr=1e-5))
history = tf.model.fit(x_data, y_data, epochs=2000)

# Ask my score
print("Your score will be ", tf.model.predict([[100, 70, 101]]))
print("Other scores will be ", tf.model.predict([[60, 70, 110], [90, 100, 80]]))

'딥러닝, 머신러닝 > 모두를 위한 딥러닝 강의 복습' 카테고리의 다른 글

Softmax Regression  (0) 2022.01.06
Logistic Classification, Logistic Regression의 cost 함수  (0) 2022.01.05
Multi-variable linear regression  (0) 2022.01.04
Linear Regression의 cost 최소화 알고리즘의 원리  (0) 2022.01.04
Linear Regression  (0) 2022.01.04
    '딥러닝, 머신러닝/모두를 위한 딥러닝 강의 복습' 카테고리의 다른 글
    • Softmax Regression
    • Logistic Classification, Logistic Regression의 cost 함수
    • Multi-variable linear regression
    • Linear Regression의 cost 최소화 알고리즘의 원리
    ed-kyu
    ed-kyu

    티스토리툴바