Neural Collaborative Filtering Model
It uses the neural collaborative filtering method, with the network architecture as follows: Input layer (36 dimensions) → Fully connected layer (128 neurons, ReLU activation) → Batch normalization → Dropout (0.3) → Fully connected layer (64 neurons, ReLU activation) → Dropout (0.2) → Fully connected layer (32 neurons, ReLU activation) → Output layer (1 neuron, Sigmoid activation), which is used to predict the matching probability between candidate products and the current shopping cart.
Feature Engineering and Data Augmentation
- Product features: 18-dimensional vector (6-dimensional category one-hot encoding, 1-dimensional normalized price, 11-dimensional color one-hot encoding).
- Data augmentation: For each user's N purchase records, generate all subsets of size k (1 ≤ k ≤ N-1) as shopping cart contexts. Positive samples are the remaining purchased products, and negative samples are 3 times the number of random unpurchased products. About 3000 balanced training samples are generated from data of 10 users.
Real-Time Training Visualization
During the 60 training epochs, loss values and accuracy are pushed to the frontend via Socket.io at the end of each epoch, and a line chart is updated in real-time using Chart.js to show the training progress.
System Architecture
It adopts the MVC architecture:
- Model layer: StateModel manages in-memory states (shopping cart, training model), and RecommendationModel encapsulates TensorFlow.js model logic;
- Controller layer: ProductController handles product queries, UserController manages users and shopping carts, ModelController is responsible for training and recommendation endpoints;
- View layer: A single-page application based on Bootstrap5, integrated with Chart.js for visualization.