Skip to content
THTECHIEHACKER
Explore menu
HomeTechnical Insights
TECHIEHACKER / TECHNICAL INSIGHTS
Technical Insights.

Explore. Learn. Build. Practical resources for the AI community.

Programmer working at a laptop
File photo · Free-Photos / Pixabay · CC0
Reading list
YOUR SAVED PAGES

Saved in this browser only.

Original page controls
TECHIEHACKER
TECHIEHACKER INSIGHTS / Machine learning

Machine Learning from First Principles

Build intuition for data, models, training, leakage and evaluation before choosing a neural network.

Original AI-assisted educational editorial · Beginner · Review before production use

What you will learn
  • Distinguish training and inference
  • Choose a baseline and metric
  • Recognize leakage

Start with a decision, not a model

Suppose a support team wants to identify tickets likely to breach their response target. A model can estimate risk from information available at ticket creation: product, severity and queue workload. The target is whether the ticket eventually breached its target. Do not include resolution timestamps or later escalation fields as inputs; they reveal the answer and produce misleading test results.

Define the decision that follows a prediction. A false positive might consume an engineer’s time; a false negative might miss an important incident. This cost determines whether you need a classification threshold, a ranking or a calibrated probability.

Training, validation and test data

Training adjusts model parameters. Validation helps select features, hyperparameters and decision thresholds. The test set is reserved for an unbiased final estimate. For time-dependent tickets, split by date rather than randomly mixing future and historical incidents. If several rows belong to the same incident, keep them together.

Start with a simple baseline: predict the majority class or use logistic regression with a small feature set. Compare more complex models to that baseline under the same split. If the improvement is small, the simpler model may be cheaper and easier to operate.

Measure what matters

Accuracy alone hides poor performance when breaches are rare. Precision is the share of flagged tickets that really breach; recall is the share of actual breaches detected. A confusion matrix reveals false positives and false negatives. Choose a threshold based on capacity and business impact, not automatically 0.5.

Track the same metrics by product, severity and time period. A useful global score can conceal weak performance on a newly introduced product. After deployment, compare live input distributions and eventual outcomes with the training baseline. Drift is a signal to investigate, not proof that retraining will help.

Operational checklist

Record the dataset snapshot, split rule, feature transformations, model version and metric definition. Fit preprocessing only on training data; apply the fitted transformation to later splits. Establish a manual fallback when input fields are missing. Log predictions and outcomes without retaining unnecessary sensitive information.

Hands-on example

Pure Python example using synthetic labels; expected precision and recall are both 2/3.

y = [1, 0, 1, 0, 0, 1]
pred = [1, 1, 1, 0, 0, 0]
tp = sum(a == b == 1 for a, b in zip(y, pred))
fp = sum(a == 0 and b == 1 for a, b in zip(y, pred))
fn = sum(a == 1 and b == 0 for a, b in zip(y, pred))
print("precision", tp / (tp + fp))
print("recall", tp / (tp + fn))

Practice & self-check

Create a synthetic ticket dataset with a rare breach class. Compare a majority baseline and a classifier; explain which errors matter.

Why is resolution time a bad feature at ticket creation?

It is unavailable then and leaks information about the target.

When can accuracy be misleading?

When the classes are imbalanced or error costs differ.

Further reading

← All insights