ニューラルネットワークとは?
ニューラルネットワークは、生物学的ニューラルネットワークに着想を得たコンピューティングシステムです。これらは、データからパターンを学習するために情報を処理するレイヤーに編成された相互接続ノード(ニューロン)で構成されています。
ネットワークアーキテクチャ
import tensorflow as tf
from tensorflow import keras
# Sequential model
model = keras.Sequential([
keras.layers.Dense(128, activation='relu', input_shape=(784,)),
keras.layers.Dropout(0.2),
keras.layers.Dense(64, activation='relu'),
keras.layers.Dense(10, activation='softmax')
])
# Compile model
model.compile(
optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy']
)
アクティベーション関数
# ReLU: most common for hidden layers
# Sigmoid: binary classification output
# Softmax: multi-class classification output
# Tanh: alternative to sigmoid
# Custom activation
def custom_activation(x):
return tf.nn.relu(x) * tf.math.tanh(x)
トレーニングプロセス
# Train the model
history = model.fit(
X_train, y_train,
epochs=10,
batch_size=32,
validation_split=0.2,
callbacks=[
keras.callbacks.EarlyStopping(patience=3),
keras.callbacks.ModelCheckpoint('best_model.h5')
]
)
# Evaluate
test_loss, test_acc = model.evaluate(X_test, y_test)
print(f'Test accuracy: {test_acc}')



