<jupyter_start><jupyter_text>인공 신경망       구글 코랩에서 실행하기    패션 MNIST<jupyter_code>from tensorflow import keras

(train_input, train_target), (test_input, test_target) = keras.datasets.fashion_mnist.load_data()
print(train_input.shape, train_target.shape)
print(test_input.shape, test_target.shape)
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()
print([train_target[i] for i in range(10)])
import numpy as np

print(np.unique(train_target, return_counts=True))<jupyter_output>(array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=uint8), array([6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000, 6000]))<jupyter_text>로지스틱 회귀로 패션 아이템 분류하기<jupyter_code>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']))<jupyter_output>0.8195666666666668<jupyter_text>인공신경망  텐서플로와 케라스<jupyter_code>import tensorflow as tf
from tensorflow import keras<jupyter_output><empty_output><jupyter_text>인공신경망으로 모델 만들기<jupyter_code>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)<jupyter_output><empty_output><jupyter_text>인공신경망으로 패션 아이템 분류하기<jupyter_code>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)<jupyter_output>375/375 [==============================] - 1s 1ms/step - loss: 0.4470 - accuracy: 0.8507
{'fraction_non_alphanumeric': 0.13863744640304906, 'fraction_numerical': 0.05812291567413054, 'mean_word_length': 8.210526315789474, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '87130', 'license': 'MIT', 'n_tokens_mistral': 961, 'n_tokens_neox': 918, 'n_words': 144, 'path': '7-1.ipynb', 'repo_name': 'whpark70/hg-mldl', 'size': '2099'}