🧠 신경망 기본 이해 (딥러닝의 핵심)

신경망 기본 이해 단계에서는 퍼셉트론 → 다층 퍼셉트론 → 활성화 함수 → 손실 함수 → 역전파로 이어지는 흐름을 다루면 됩니다. 이것이 딥러닝의 뼈대 구조입니다.

📝 기본 용어 이해

💻 코드 예제 (MLP로 XOR 학습)

import numpy as np
from tensorflow.keras import models, layers

# XOR 데이터셋
X = np.array([[0,0],[0,1],[1,0],[1,1]])
y = np.array([0,1,1,0])  # XOR 결과

# 모델 생성
model = models.Sequential([
    layers.Dense(4, input_dim=2, activation='relu'),  # 은닉층
    layers.Dense(1, activation='sigmoid')            # 출력층
])

# 모델 컴파일
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])

# 학습
model.fit(X, y, epochs=100, verbose=0)

# 평가
print("정확도:", model.evaluate(X, y, verbose=0)[1])

# 예측
print("예측 결과:", model.predict(X).round())

graph LR
    subgraph "입력층"
      X1["x1 (float)"]
      X2["x2 (float)"]
    end

    subgraph "은닉층(ReLU, 4)"
      H1["뉴런1"]
      H2["뉴런2"]
      H3["뉴런3"]
      H4["뉴런4"]
    end

    subgraph "출력층(Sigmoid, 1)"
      Yhat["ŷ (0~1 확률)"]
    end

    X1 --> H1
    X1 --> H2
    X1 --> H3
    X1 --> H4
    X2 --> H1
    X2 --> H2
    X2 --> H3
    X2 --> H4

    H1 --> Yhat
    H2 --> Yhat
    H3 --> Yhat
    H4 --> Yhat

    style X1 fill:#e1f5ff,stroke:#0288d1,stroke-width:2px,color:#000
    style X2 fill:#e1f5ff,stroke:#0288d1,stroke-width:2px,color:#000
    style H1 fill:#fff8e1,stroke:#f9a825,stroke-width:2px,color:#000
    style H2 fill:#fff8e1,stroke:#f9a825,stroke-width:2px,color:#000
    style H3 fill:#fff8e1,stroke:#f9a825,stroke-width:2px,color:#000
    style H4 fill:#fff8e1,stroke:#f9a825,stroke-width:2px,color:#000
    style Yhat fill:#e8f5e9,stroke:#43a047,stroke-width:2px,color:#000

5) 🏃 실습 예제