ML.NET interview questions for .NET developers
Reviewed by Mark Dickie · Last updated
6 questions on this page you can answer and see marked on the spot. Go to the first one
ML.NET is Microsoft's open-source machine learning framework for training and scoring models in C# and F# without leaving .NET. Interviewers usually check whether you can load data into an IDataView, build a trainer pipeline, evaluate it on held-out rows, and serve predictions safely from an ASP.NET app. Most of the questions turn on three things: how MLContext pipelines fit transforms before trainers, which metrics actually matter for your data, and why a shared PredictionEngine breaks under concurrent requests.
Which ML.NET concepts does the interview cover?
| Area | What to know | Failure mode to name |
|---|---|---|
| MLContext | Entry point that creates data views, transforms and trainers. Pass a seed for repeatable splits. | Unseeded runs give different train/test partitions each time. |
| IDataView | Column-typed, lazily evaluated data container. Load with TextLoader or LoadFromEnumerable. | Treating it like a List of objects forces full materialization and loses schema checks. |
| Transforms and trainers | Transforms such as NormalizeMinMax and OneHotEncoding learn parameters from data. Trainers such as SdcaLogisticRegression produce the model. | Fitting a normalizer on the full dataset before splitting leaks test statistics into training. |
| PredictionEngine | Single-row scoring object for one model and schema. | Not thread-safe, so one shared instance fails under concurrent ASP.NET requests. Use PredictionEnginePool. |
| Evaluate | Computes metrics such as AUC, F1 or RMSE on a held-out split. | Accuracy alone hides poor recall on a rare positive class. |
What should you practice by hand?
- Load a CSV with TextLoader, split it with TrainTestSplit, and train a binary SdcaLogisticRegression classifier.
- Add a NormalizeMinMax step, then compare the metrics when you fit it before the split versus only on the training rows.
- Save the trained model with mlContext.Model.Save and reload it, checking the input schema on load.
- Wrap a PredictionEngine in a minimal ASP.NET endpoint, then replace it with PredictionEnginePool and call the endpoint from parallel requests.
- Pick a metric for an imbalanced dataset and explain why you chose it over accuracy.
Key facts
- Tarmac has 11 .NET interview questions on this topic, 10 of them on this page, at difficulty 1–5 of 5.
- Tarmac tracked 747 job postings asking for .NET in November 2026.
- Roles asking for .NET advertise a median base salary of £70,000, across 302 job postings as of November 2026.
- Tarmac last reviewed these .NET interview questions on 30 November 2026.
At a glance
| Questions | 10 shown · 11 in the bank |
|---|---|
| Difficulty | 1–5 of 5 |
| Formats | Multiple choice, Ordering, Code output, True / false, Find the bug, Short answer, Flashcard |
What you'll review
- ml net fundamentals
- training and consuming models ml net
Practice questions
Try one before you open the answer. Pick an option and press Check; it's marked on the spot.
In ML.NET, which class is the starting point for all ML.NET operations? It provides the catalogs for data loading, transforms, trainers, and model operations.#
Options
Show answer
The MLContext class is the starting point for every ML.NET operation. It exposes catalogs such as Data, Transforms, the trainer catalogs and Model. You use these catalogs to load data, build pipelines, train models, and save or load them. Other types play narrower roles: IDataView holds the data, ITransformer is a trained model, and PredictionEngine makes single predictions.
MLContext is the shared starting point in ML.NET. Its properties expose catalogs such as Data, Transforms, Regression, BinaryClassification and Model, and these catalogs are used to load data, build pipelines, train and save models. IDataView is the abstraction for the tabular data the pipeline works on. ITransformer is the trained model, or a fitted transform, that comes out of training. PredictionEngine is a convenience class that runs one prediction at a time with an already-trained model. None of these three is where ML.NET operations start.
In ML.NET, which class do you use to make a single prediction on one input object from a trained ITransformer model?#
Options
Show answer
ML.NET uses PredictionEngine<TSrc, TDst> to make single predictions. You create it with mlContext.Model.CreatePredictionEngine<TSrc, TDst>(model) and call Predict(input), which returns one output object. This makes it a convenient API for scoring one example at a time. Batch scoring instead uses model.Transform(dataView).
You create a PredictionEngine<TSrc, TDst> with mlContext.Model.CreatePredictionEngine<TSrc, TDst>(model). Its Predict method takes one input object and returns one output object. IDataView is the lazy tabular data abstraction used for batches of rows, not a single prediction API. TextLoader reads data from files. EstimatorChain<T> is an untrained pipeline that you still have to fit.
Put these steps of a basic ML.NET workflow for training a model and then using it in the correct order.#
Put these in order
Show answer
The correct ML.NET order is: create an MLContext, load the training data into an IDataView, define the estimator pipeline and call Fit to get an ITransformer, then create a PredictionEngine and call Predict. Each step needs output from the one before it: the context supplies the data loader, fitting needs the data, and only a trained model can back a prediction engine.
The MLContext comes first because every ML.NET operation, including loading data, goes through it. The training data must be loaded before Fit can run, since Fit needs the data as input. Fitting the pipeline produces the trained ITransformer, and only that trained model can be used to create a PredictionEngine and call Predict on new data. Each of these steps consumes what the previous step produced, so this chain has one strict order.
What does this ML.NET (Microsoft.ML 3.x) program print?#
using System;
using System.Linq;
using Microsoft.ML;
using Microsoft.ML.Data;
public class Input { public float A { get; set; } public float B { get; set; } }
public class Output { [VectorType(2)] public float[] Features { get; set; } }
public static class Program
{
public static void Main()
{
var ml = new MLContext(seed: 0);
var data = ml.Data.LoadFromEnumerable(new[]
{
new Input { A = 1, B = 2 },
new Input { A = 3, B = 4 }
});
var pipeline = ml.Transforms.Concatenate("Features", "B", "A");
var transformed = pipeline.Fit(data).Transform(data);
var rows = ml.Data
.CreateEnumerable<Output>(transformed, reuseRowObject: false)
.ToList();
Console.WriteLine($"{rows.Count} {string.Join(",", rows[1].Features)}");
}
}Show answer
2 4,3
LoadFromEnumerable wraps the two input objects in an IDataView. Concatenate("Features", "B", "A") builds a new vector column, and it puts the source columns in the order you list them, so each row gets [B, A]. Fitting and transforming this pipeline keeps the row count the same. CreateEnumerable<Output> then reads the transformed view back into objects, matching the Features property by name, and returns 2 rows. The second row has A=3 and B=4, so its features are [4, 3]. The program prints 2 4,3.
In ML.NET, calling Fit() on an estimator pipeline that you built with mlContext.Transforms... returns a trained ITransformer. Calling Transform(data) on that transformer runs lazily: it returns a new IDataView straight away, and rows are processed only when something iterates over the data, for example a cursor, CreateEnumerable, or an evaluator.#
Options
Show answer
ML.NET's ITransformer.Transform() is lazy. It returns a new IDataView right away, and rows are processed only when something consumes that view through a cursor, for example CreateEnumerable, Preview, an evaluator or a downstream Fit. The real work is done by Estimator.Fit(), which trains on the data and returns the transformer. This cursor-based design lets ML.NET stream datasets that are larger than memory.
IDataView in ML.NET is designed to be lazy and cursor-based. Estimator.Fit() is the step that does the work. It reads the training data, learns the parameters and returns an ITransformer. ITransformer.Transform() does far less. It builds a new IDataView that describes how its output columns are computed from the input, and no rows are processed yet. The calculation runs only when a consumer opens a cursor over the view, such as mlContext.Data.CreateEnumerable<T>, Preview(), an evaluator like BinaryClassification.Evaluate, or a downstream trainer's Fit. This is why ML.NET can stream datasets that are larger than memory.
This ML.NET code trains a regression model and reports its R² on held-out data. The code compiles and runs, but the R² it reports is too optimistic and doesn't reflect how the model will do on unseen data. Which line contains the bug?#
var ml = new MLContext(seed: 0);
IDataView data = ml.Data.LoadFromTextFile<HouseData>("houses.csv", hasHeader: true, separatorChar: ',');
var split = ml.Data.TrainTestSplit(data, testFraction: 0.2);
var pipeline = ml.Transforms.Concatenate("Features", "Size", "Rooms")
.Append(ml.Transforms.NormalizeMinMax("Features"))
.Append(ml.Regression.Trainers.Sdca(labelColumnName: "Price"));
ITransformer model = pipeline.Fit(split.TrainSet);
IDataView predictions = pipeline.Fit(split.TestSet).Transform(split.TestSet);
var metrics = ml.Regression.Evaluate(predictions, labelColumnName: "Price");
Console.WriteLine($"R^2: {metrics.RSquared:0.###}");Show answer
The bug is on line 8.
Line 8 calls pipeline.Fit(split.TestSet), which trains a brand-new model on the test set: it fits fresh min-max normalization parameters and fresh SDCA weights from that data. It then scores the same test set it just trained on. That is data leakage, so the R² measures how well the model fits its own training data, not how well it generalizes. The trained model from line 7 is never used. The fix is IDataView predictions = model.Transform(split.TestSet);. Calling Transform on the fitted ITransformer applies the normalization and weights learned from the training set to the held-out rows. The other lines are standard: TrainTestSplit, then Concatenate and NormalizeMinMax feature preparation, then Fit on the training set and Regression.Evaluate with the right label column.
In ML.NET, a teammate builds a pipeline mlContext.Transforms.NormalizeMinMax("Features").Append(trainer) and then, to save time, calls pipeline.Fit(fullData) once, then evaluates by splitting fullData with TrainTestSplit and scoring the test portion with that already-fitted model. Explain what is wrong with this evaluation in terms of how IEstimator / ITransformer work, and how to fix it correctly (including the right way to use cross-validation).#
Show answer
Calling Fit on an estimator chain trains every estimator, including the normalizer, which learns data statistics (min/max) and the trainer which learns weights — producing an ITransformer. Because the model was fit on the full dataset, the test rows were already seen during fitting (both normalization statistics and model parameters), so evaluating on them is data leakage and gives optimistically biased metrics. Fix: call mlContext.Data.TrainTestSplit(fullData, testFraction: 0.2) first, Fit the whole pipeline on split.TrainSet only, then model.Transform(split.TestSet) and pass to mlContext.BinaryClassification.Evaluate (or relevant catalog). For cross-validation, pass the unfitted estimator pipeline to mlContext.<Task>.CrossValidate(data, pipeline, numberOfFolds: 5) so each fold refits the normalizer and trainer on only its training folds; optionally use samplingKeyColumnName to keep related rows together. Finally, refit on all data only for the production model, not for metrics.
In ML.NET an IEstimator is an untrained recipe; Fit produces an ITransformer whose learned state (normalizer min/max, model weights) depends on the data passed in. Fitting on all data before splitting means the test rows influenced both the normalization statistics and the trained parameters, which is data leakage and inflates the metrics. The correct approach is to split first and fit only on the training portion, then transform and evaluate the held-out portion. Another correct approach is to pass the unfitted pipeline to CrossValidate, which refits every stage separately inside each fold.
This ML.NET (Microsoft.ML 3.x) code trains a binary classifier, saves it, and loads it in a separate scoring process. When the scoring process runs, it throws an exception about a missing column (or a schema mismatch), even though modelInput has every raw input column. Which line causes this?#
var ml = new MLContext(seed: 1);
IDataView data = ml.Data.LoadFromTextFile<ModelInput>("train.csv", hasHeader: true, separatorChar: ',');
var featurize = ml.Transforms.Text.FeaturizeText("Features", nameof(ModelInput.Text));
IDataView featurized = featurize.Fit(data).Transform(data);
var trainer = ml.BinaryClassification.Trainers.SdcaLogisticRegression("Label", "Features");
ITransformer model = trainer.Fit(featurized);
ml.Model.Save(model, featurized.Schema, "model.zip");
// --- scoring process ---
ITransformer loaded = ml.Model.Load("model.zip", out DataViewSchema inputSchema);
var engine = ml.Model.CreatePredictionEngine<ModelInput, ModelOutput>(loaded);
var result = engine.Predict(modelInput);Options
Show answer
Line 4: the featurizer is fitted and applied outside the pipeline, so the saved model (line 6/7) contains only the trainer and expects a precomputed Features column.
The featurizer is fitted and applied by hand on line 4, then only trainer.Fit(featurized) becomes model. So the saved model holds only the logistic-regression transformer, which expects a Features vector column. Raw ModelInput objects have just Text, so scoring fails. The fix is to chain the steps with featurize.Append(trainer) and fit that on the raw data, so the saved ITransformer includes text featurization. Passing data.Schema to Save would be correct metadata, but it would not add the missing featurizer, so the wrong schema is not the cause. A new MLContext with a different seed loads fine. The inputSchema argument to CreatePredictionEngine is optional.
In ML.NET, why does IDataView use lazy, cursor-based evaluation, and what are the consequences for a pipeline that calls mlContext.Data.Cache() versus one that doesn't when training a multi-pass trainer such as SDCA?#
Show answer
IDataView works like a lazy, immutable, columnar view. Transforms run only when a cursor (GetRowCursor) iterates the data. This allows streaming of datasets larger than memory and composable transforms that are never materialized. Multi-pass trainers such as SDCA or L-BFGS iterate the data many times. Without AppendCacheCheckpoint/Cache(), every pass re-runs the whole upstream chain (file parsing, featurization, text transforms), which can be very costly. With caching, the featurized rows are materialized in memory once and later passes read from that cache. The trade-off is speed against memory: cache in front of multi-pass trainers when the data fits in memory, and skip it for single-pass trainers or very large data.
ML.NET's IDataView defers computation until a cursor pulls rows. That makes it scale well, but iterative trainers then recompute every transform on each pass unless a cache checkpoint materializes the data. Knowing where to put AppendCacheCheckpoint is a senior-level ML.NET performance concern.
In an ASP.NET Core API using ML.NET, a developer creates one PredictionEngine<TIn,TOut> at startup and registers it as a singleton. Then many concurrent requests call engine.Predict(input) on it. Under load, predictions sometimes come back corrupted or an exception is thrown. What is the underlying cause, and what does Microsoft recommend instead?#
Options
Show answer
ML.NET's PredictionEngine is not thread-safe because it reuses mutable internal buffers and cursors between Predict calls. Sharing one instance across concurrent requests can therefore corrupt results or throw. Share the immutable ITransformer instead, and use PredictionEnginePool from Microsoft.Extensions.ML. It hands each concurrent caller its own pooled engine.
PredictionEngine caches mutable state such as input/output buffers, row cursors and getters so it can avoid allocating on each prediction. Because of this, two threads using one instance at the same time can corrupt each other's results. The ITransformer returned by Fit is immutable and safe to share across threads. So the right fix is to share the transformer and give each concurrent call its own engine, which is what PredictionEnginePool does with pooled engines (it can also watch the model file for reloads). Reloading the model on every request avoids the race, but it is very slow and misidentifies the transformer as the thread-unsafe part. A new MLContext per request does nothing about the shared engine. ML.NET has no PredictAsync method.
Related interview questions
Job market
See dotnet salaries and hiring demand from live job postings.
The other 1 question
This page shows 10 and marks what you pick. That's as far as a page can go. A free account opens the other 1 and keeps every answer. What you miss comes back until it's right: after a day, then at longer gaps.
Free · the whole bank · 100 answers per 30 days, each marked with written feedback