EMBEDLIX RESEARCH · MACHINE LEARNING LABORATORY SERIES
Feedforward neural networks: implementation and learning
A six-input, two-hidden-layer classifier, capacity/scaling experiments and honest final-test interpretation.
3.1 Architecture and objective
The feedforward network asks whether nonlinear combinations of the six channels improve row-level classification. Each row enters a network with six inputs, two ReLU hidden layers, and four softmax outputs. The class mapping is walk = 0, run = 1, jump = 2, own = 3. [1,4]
ReLU supplies nonlinear transformations; softmax converts output scores into four class probabilities. Sparse categorical cross-entropy accepts the integer class labels, and Adam optimizes the weights. Unlike the GRU, this model has no temporal memory between rows.
Two hidden widths were compared: 10 neurons per layer (224 parameters) and 50 per layer (3,104 parameters). For the selected model, the counts are 350 for the first Dense layer, 2,550 for the second, and 204 for the output layer. Increased capacity is useful only if validation performance improves, not because the network is larger.
Source-derived model architecture
6 features
One standardized sensor row
50 → 50
Two ReLU hidden layers
4 outputs
Softmax activity probabilities
Original notebook cell · dependencies described above
def build_feedforward_model(hidden_neurons):
model = keras.Sequential([
keras.Input(shape=(6,), name="sensor_features"),
layers.Dense(
hidden_neurons,
activation="relu",
name="hidden_layer_1"
),
layers.Dense(
hidden_neurons,
activation="relu",
name="hidden_layer_2"
),
layers.Dense(
4,
activation="softmax",
name="class_output"
)
])
model.compile(
optimizer="adam",
loss="sparse_categorical_crossentropy",
metrics=["accuracy"]
)
return model
3.2 Four experiments: capacity and standardization
| Hidden width | Inputs | Best validation accuracy | Best epoch | Parameters |
|---|---|---|---|---|
| 10 + 10 | Unscaled | 87.56% | 50 | 224 |
| 50 + 50 | Unscaled | 93.95% | 50 | 3,104 |
| 10 + 10 | Standardized | 88.79% | 48 | 224 |
| 50 + 50 | Standardized | 94.76% | 47 | 3,104 |
Each experiment trained for up to 50 epochs with batch size 256 and a separate recording-aware validation set. Increasing the unscaled hidden width improved validation accuracy by 6.39 percentage points. Scaling the larger model added a smaller 0.81-point best-validation improvement.
The learning curves flatten as training proceeds. Training and validation remain reasonably close in these saved runs; that is not evidence that every future dataset will avoid overfitting. It shows how the selected configuration behaved under this particular split and seed.
3.3 Selecting the final model before evaluation
The 50-neuron standardized model provided the highest validation accuracy and lowest final validation loss (0.1531). Best validation accuracy occurred at epoch 47 rather than at the last epoch. The notebook recreated the network with the same random seed and trained it for 47 epochs before testing.
# Teaching summary: arrays and fitted scaler come from earlier cells.
final_model = build_feedforward_model(hidden_neurons=50)
final_model.fit(
X_train_scaled, y_train,
validation_data=(X_validation_scaled, y_validation),
epochs=47, batch_size=256
)
X_test_scaled = scaler.transform(X_test_unscaled)
The scaler is not refitted on test data. Epoch selection is based on validation, not on trying multiple final models and choosing whichever looks best on the held-out set. Recreating a network with a seed helps repeatability but does not replace multi-seed experiments or guarantee identical numerical results across different devices and software versions.
3.4 Final evaluation and the confusion matrix
The final network achieved 90.09% test accuracy, loss 0.3416, and macro F1 0.8995 on 16,042 same-person sensor rows. The test result was 4.67 points below best validation accuracy and 1.03 points below KNN test accuracy. More model capacity therefore did not produce a test advantage over the classical baseline.
Running recall was 97.48%, jumping 91.75%, forward/backward 92.62%, and walking 78.51%. Of 4,011 walking rows, 3,149 were correct; 365 became running and 333 became the fourth class.
evaluate() returns loss and aggregate metrics. predict() returns per-row probabilities; argmax selects a class index. A confusion matrix requires those individual predictions and the true labels. Its rows are actual classes and columns predicted classes.
The original notebook excerpt below carries out this prediction stage. It depends on the trained model and transformed test arrays.
Original notebook cell · dependencies described above
# Generate class probabilities for every test sample
test_probabilities = final_model.predict(
X_test_scaled,
verbose=0
)
# Convert probabilities into predicted class indices
y_test_predicted = np.argmax(
test_probabilities,
axis=1
)
# Create and display the confusion matrix
test_confusion_matrix = confusion_matrix(
y_test,
y_test_predicted,
labels=np.arange(len(CLASS_NAMES))
)
display = ConfusionMatrixDisplay(
confusion_matrix=test_confusion_matrix,
display_labels=CLASS_NAMES
)
display.plot(
cmap="Blues",
values_format="d"
)
plt.title("Final test confusion matrix")
plt.tight_layout()
plt.show()
# Detailed results for every class
print(
classification_report(
y_test,
y_test_predicted,
labels=np.arange(len(CLASS_NAMES)),
target_names=CLASS_NAMES,
digits=4
)
)
3.5 What this experiment establishes
The network learns useful nonlinear structure, and larger hidden layers are beneficial within the tested validation settings. Standardization gives a modest additional improvement. However, independent row classification loses sequence context: two activities may share instantaneous values but differ in rhythm.
The appropriate conclusion is not “deep learning is worse.” It is that this feedforward representation and training protocol did not outperform KNN on the available same-person test. A fair follow-up would compare models using matched time-window information, repeat training across seeds and preserve a final participant-held-out dataset. That motivates the GRU experiment without assuming its success in advance.