Was sind neuronale Netze?
Neuronale Netze sind Computersysteme, die von biologischen neuronalen Netzen inspiriert sind. Sie bestehen aus miteinander verbundenen Knoten (Neuronen), die in Schichten organisiert sind, die Informationen verarbeiten, um Muster aus Daten zu lernen.
Netzwerkarchitektur
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']
)
Aktivierungsfunktionen
# 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)
Schulungsprozess
# 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}')



