predicting class for new data using neuralnet
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
Predicting classes for new samples with a neural network is straightforward once you separate three steps: preprocessing, model training, and postprocessing of outputs. Most mistakes come from applying different transforms at prediction time than at training time. A robust workflow keeps both paths identical and converts probabilities to class labels in one place.
Build a Repeatable Training Pipeline
The example below uses R with the neuralnet package, which returns raw network outputs that you map back to class labels. The key is to normalize input features once and reuse the same scaling values for all future predictions.
This creates a binary classifier that outputs values close to zero or one.
Predict Classes for New Data Correctly
At inference time, scale new inputs with the same mins and maxs from training. Do not recompute scaling from the new batch, because that shifts the feature space and changes decision boundaries.
For multiclass models, your network usually has one output neuron per class. In that case, choose the class index with the highest score.
Validate Before Deployment
Do not rely only on training accuracy. Create a validation split and track confusion matrix metrics so you understand class-specific behavior. For imbalanced data, precision and recall are usually more informative than global accuracy.
A simple deployment checklist:
- Save model object and scaling parameters together.
- Validate incoming data schema before scoring.
- Log prediction probabilities for monitoring drift.
- Re-evaluate threshold values for business tradeoffs.
These operational details often matter more than architecture tweaks when your goal is stable production predictions.
Production Readiness Checklist
A model that works in a notebook may still fail in production if input quality changes. Validate numeric ranges before scoring, reject malformed rows explicitly, and log both prediction labels and confidence values. Keep a sample of scored requests for periodic review with domain experts. This gives you a feedback loop for recalibration and retraining, which is critical when real world data slowly drifts away from the training distribution.
Common Pitfalls
- Recomputing normalization values from new data instead of reusing training statistics.
- Using a threshold of
0.5blindly without testing precision and recall impact. - Treating multiclass scores as binary outputs and assigning invalid labels.
- Training with one feature order and predicting with another feature order.
- Saving only model weights but not the preprocessing configuration needed for inference.
Summary
- Keep preprocessing and prediction steps tightly coupled to the training setup.
- Reuse the same scaling parameters from training for all new samples.
- Convert network outputs to labels using thresholding for binary or argmax for multiclass.
- Evaluate performance on validation data, not only training data.
- Package model and preprocessing artifacts together for reliable deployment.
Related reading
- Predicting the next word using the LSTM ptb model tensorflow example
- Prediction from model saved with tf.estimator.Estimator in Tensorflow
- Preload whole dataset on gpu for training Keras model
- Prevent over-fitting of text classification using Word embedding with LSTM
- Predicting how long an scikit-learn classification will take to run
- Predicting Missing Words in a sentence - Natural Language Processing Model
- Prevent TensorFlow from accessing the GPU?
- Prevention of overfitting in convolutional layers of a CNN
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.