- Несоответствие размеров: я не уверен, что размеры входных данных X_scale< /code> (5000 образцов, 17 функций) правильно совпадают с весами весовой матрицы (2x17).
- Отображение веса внутри цикла: I я не уверен, отображаются ли веса внутри цикл обучения — наиболее эффективный способ отслеживать их прогресс.
Вот код Я работаю с:
import numpy as np
class Kohonen:
def __init__(self, weights):
self.weights = weights
def win(self, sample):
distances = np.sum((sample - self.weights)**2, axis=1)
return np.argmin(distances)
def update(self, sample, k, alpha):
self.weights[k] += alpha * (sample - self.weights[k])
# Initialize weights for the neural network
weights = np.random.normal(size=(2, 17), loc=0, scale=1)
# Create the Kohonen model
kohonen = Kohonen(weights)
# Number of epochs and learning rate
epochs = 260
alpha = 0.1
# Input data (ensure dimensions are consistent)
X_scaled = np.random.random((5000, 17)) # Replace with actual data
# Training loop
for epoch in range(epochs):
print(f"Epoch: {epoch}")
for sample in X_scaled:
winner = kohonen.win(sample)
kohonen.update(sample, winner, alpha)
print(kohonen.weights) # Display weights after each epoch`
Подробнее здесь: https://stackoverflow.com/questions/792 ... onen-neura