0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ポケモン種族値で学ぶニューラルネットワークAIの基礎

Posted at

ポケモン種族値で学ぶニューラルネットワークAIの基礎

「ニューラルネットワークとは何か?」
その問いに対して、本記事ではポケモンの種族値の合計が560を超えるかどうかを判定するシンプルな分類問題を題材に、ニューラルネットワークの基本を直感的に理解できる方法を紹介します。


ニューラルネットワークの構造

使用するのは1層・シグモイド活性化関数付きの非常に単純な構造です:

  • 入力層:6つの種族値(H, A, B, C, D, S)
  • 重み(Weights):すべて1(単純に合計を取る)
  • バイアス(Bias):-560(=しきい値)
  • 活性化関数:シグモイド関数(確率に変換)

数式モデル

出力は次のように計算されます:

$$
z = \sum_{i=1}^{6} x_i - 560
\quad \Rightarrow \quad
\text{Probability} = \sigma(z) = \frac{1}{1 + e^{-z}}
$$

  • $x_i$:6つの種族値
  • $\sigma(z)$:シグモイド関数

判定ルール

  • 出力値 ≥ 0.5 → 種族値合計は560以上の可能性あり(分類:1
  • 出力値 < 0.5 → 種族値合計は560未満と予測(分類:0

実例:ウインディ(種族値合計 555)

# Program Name: sigmoid_species_classifier_plot.py
# Creation Date: 20250601
# Overview: Classify Pokémon base stats using sigmoid, plot activation and its derivative
# Usage: Run the script to classify input stats and visualize sigmoid + derivative

# ライブラリのインストール / Install required libraries
!pip install numpy matplotlib

# ライブラリのインポート / Import libraries
import numpy as np
import matplotlib.pyplot as plt

# ---------- シグモイド関数とその微分 / Sigmoid and its derivative ----------
def sigmoid(z):
    """シグモイド活性化関数 / Sigmoid activation function"""
    return 1 / (1 + np.exp(-z))

def sigmoid_derivative(z):
    """シグモイド関数の導関数 / Derivative of sigmoid"""
    s = sigmoid(z)
    return s * (1 - s)

# ---------- ニューラルネットワーク判定関数 / Classifier function ----------
def classify_with_sigmoid(base_stats):
    weights = np.ones(6)
    bias = -560
    z = np.dot(weights, base_stats) + bias
    return sigmoid(z), z

# ---------- ウインディの種族値 / Arcanine base stats ----------
arcanine_stats = [90, 110, 80, 100, 80, 95]  # total = 555
prob, z_val = classify_with_sigmoid(arcanine_stats)

# ---------- 結果出力 / Output result ----------
print(f"確率(Probability): {prob:.4f}")
print("判定(Classification):", "はい (1)" if prob >= 0.5 else "いいえ (0)")

# ---------- 活性化関数と微分のプロット / Plot sigmoid and its derivative ----------
z_range = np.linspace(-20, 20, 400)
sig_vals = sigmoid(z_range)
deriv_vals = sigmoid_derivative(z_range)

plt.figure(figsize=(10, 6))
plt.plot(z_range, sig_vals, label='Sigmoid', linewidth=2)
plt.plot(z_range, deriv_vals, label="Sigmoid Derivative", linestyle='--')
plt.axvline(z_val, color='gray', linestyle=':', label=f'z = {z_val:.2f}')
plt.axhline(0.5, color='lightgray', linestyle=':')
plt.title("Sigmoid Activation Function and Derivative")
plt.xlabel("z")
plt.ylabel("Value")
plt.legend()
plt.grid(True)
plt.show()

出力:

確率(Probability): 0.0067
判定(Classification): いいえ (0)

image.png


解釈と学び

  • ウインディは種族値555 → わずかに届かず ✗
  • 確率的にも0.0067と非常に低い
  • ニューラルネットワークはこのように線形和+バイアス+活性化という構成で入力を分類

応用への展開


まとめ

本モデルはシンプルながら、ニューラルネットワークの本質(加重和+バイアス+非線形変換)をしっかり体験できる教材です。
ポケモンの種族値を活用することで、AI初学者でも親しみやすく、かつ数学的な理解に橋をかける
ことが可能です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?