TOPIC
Logistic Regression via Keras & Tensorflow (Python)
CODE
# -*- coding: utf-8 -*-
"""nipa_aiwebdev_ai_fashion.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1dLQFkikURzUPWJXz91owv-wlN_wCLZhK
# 인공 신경망
<table align="left">
<td>
<a target="_blank" href="https://colab.research.google.com/github/rickiepark/hg-mldl/blob/master/7-1.ipynb"><img src="https://www.tensorflow.org/images/colab_logo_32px.png" />구글 코랩에서 실행하기</a>
</td>
</table>
## 패션 MNIST
Keras 패션 데이터셋 import
"""
from tensorflow import keras
(train_input, train_target), (test_input, test_target) = keras.datasets.fashion_mnist.load_data()
"""Training Set Shape 확인"""
print(train_input.shape, train_target.shape)
"""Test Set Shape 확인"""
print(test_input.shape, test_target.shape)
"""Fashion Dataset 이미지 표시"""
import matplotlib.pyplot as plt
fig, axs = plt.subplots(1, 10, figsize=(10,10))
for i in range(10):
axs[i].imshow(train_input[i], cmap='gray_r')
axs[i].axis('off')
plt.show()
"""Training Set 나열"""
print([train_target[i] for i in range(10)])
"""Training Set에서 중복 원소 없애기"""
import numpy as np
print(np.unique(train_target, return_counts=True))
"""## 로지스틱 회귀로 패션 아이템 분류하기
Logistic Regression을 통해 패션 아이템 분류
"""
train_scaled = train_input / 255.0
train_scaled = train_scaled.reshape(-1, 28*28)
print(train_scaled.shape)
from sklearn.model_selection import cross_validate
from sklearn.linear_model import SGDClassifier
sc = SGDClassifier(loss='log', max_iter=5, random_state=42)
scores = cross_validate(sc, train_scaled, train_target, n_jobs=-1)
print(np.mean(scores['test_score']))
"""## 인공신경망
### 텐서플로와 케라스
"""
import tensorflow as tf
from tensorflow import keras
"""## 인공신경망으로 모델 만들기"""
from sklearn.model_selection import train_test_split
train_scaled, val_scaled, train_target, val_target = train_test_split(
train_scaled, train_target, test_size=0.2, random_state=42)
print(train_scaled.shape, train_target.shape)
print(val_scaled.shape, val_target.shape)
dense = keras.layers.Dense(10, activation='softmax', input_shape=(784,))
model = keras.Sequential(dense)
"""## 인공신경망으로 패션 아이템 분류하기"""
model.compile(loss='sparse_categorical_crossentropy', metrics='accuracy')
print(train_target[:10])
model.fit(train_scaled, train_target, epochs=5)
model.evaluate(val_scaled, val_target)
Further explanation will be provided.
——————————————————————————
본 후기는 정보통신산업진흥원(NIPA)에서 주관하는 <AI 서비스 완성! AI+웹개발 취업캠프 - 프론트엔드&백엔드> 과정 학습/프로젝트/과제 기록으로 작성 되었습니다. #정보통신산업진흥원 #NIPA #AI교육 #프로젝트 #유데미 #IT개발캠프 #개발자부트캠프 #프론트엔드 #백엔드 #AI웹개발취업캠프 #취업캠프 #개발취업캠프