Quick answer: The most common machine learning fundamentals mistakes are testing on training data, leaking information before the split, trusting accuracy on uneven classes, skipping a baseline, tuning on the test set, ignoring feature scale, giving categories a false order, using future information, shuffling time data and missing overfitting. Fix most of them by splitting first, using pipelines and checking errors by hand.
Most machine learning fundamentals mistakes do not show a red error message. The code runs. The score looks great. Then the model fails on new data, and you do not know why.
This guide covers ten of these mistakes. For each one, you will see what goes wrong, why, and how to fix it. The short snippets use Python and scikit-learn. In them, X is your feature table and y is the answer column.
The ten mistakes at a glance
| # | Mistake | Quick fix |
|---|---|---|
| 1 | Testing on training data | Keep a separate test set |
| 2 | Preparing data before the split | Use a pipeline |
| 3 | Trusting accuracy alone | Check recall and precision |
| 4 | No baseline | Compare with a simple guess |
| 5 | Tuning on the test set | Use cross-validation |
| 6 | Ignoring scale | Scale for distance-based models |
| 7 | Categories with a false order | One-hot encode |
| 8 | Using future information | Ask "do I know this yet?" |
| 9 | Shuffling time data | Split by date |
| 10 | Missing overfitting | Compare train and validation scores |
Machine learning fundamentals mistakes in splitting and testing
1. Testing on training data
Wrong:
model.fit(X, y)
print(model.score(X, y))
Why it fails. The model is marked on questions it has already seen. A deep decision tree can memorise the answers and score close to 1.0.
Fix: hold back data first.
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, stratify=y, random_state=42
)
model.fit(X_train, y_train)
print(model.score(X_test, y_test))
stratify=y keeps the class mix the same in both parts. Use it for classification, not for regression.
2. Preparing data before the split
Wrong:
X_scaled = StandardScaler().fit_transform(X)
X_train, X_test, y_train, y_test = train_test_split(X_scaled, y)
Why it fails. The scaler worked out its averages from every row, including test rows. Information about the test set has leaked. With simple scaling the effect may be small. With feature selection on the full data, it can be large.
Fix: put the steps in a pipeline, after the split.
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
model = make_pipeline(StandardScaler(), LogisticRegression())
model.fit(X_train, y_train)
Now the scaler learns from training rows only, and then applies the same numbers to test rows.
3. Trusting accuracy on uneven classes
Here is a "model" that says "no" to everybody:
actual = [1] * 5 + [0] * 95
predicted = [0] * 100
correct = sum(a == p for a, p in zip(actual, predicted))
caught = sum(a == 1 and p == 1 for a, p in zip(actual, predicted))
print("accuracy:", correct / 100) # accuracy: 0.95
print("recall:", caught / 5) # recall: 0.0
Why it fails. The large class hides the errors. The model found none of the five cases that matter.
Fix: print a confusion matrix. Choose recall when a missed case costs more, and precision when a false alarm costs more.
4. Skipping the baseline
Wrong: "My model has 82% accuracy, so it works."
Why it fails. If 80% of rows share one label, a constant guess already gets about 80%. Your model added almost nothing.
Fix: score a dummy model first.
from sklearn.dummy import DummyClassifier
baseline = DummyClassifier(strategy="most_frequent")
baseline.fit(X_train, y_train)
print(baseline.score(X_test, y_test))
For regression, use DummyRegressor, which can predict the mean.
5. Tuning on the test set
Wrong: trying many settings, checking the test score each time and keeping the best.
Why it fails. You are now choosing settings that suit those exact rows. The test set has become part of training.
Fix: tune with cross-validation on training data.
from sklearn.model_selection import GridSearchCV
from sklearn.tree import DecisionTreeClassifier
search = GridSearchCV(
DecisionTreeClassifier(random_state=42),
{"max_depth": [2, 4, 6, 8]},
cv=5,
)
search.fit(X_train, y_train)
print(search.best_params_)
print(search.score(X_test, y_test)) # once, at the end
Interview note: Say it simply: "validation data helps me choose; test data helps me report."
Mistakes with features
6. Ignoring feature scale
KNN finds the closest rows. Look at three people described by age and yearly salary:
from math import dist
a = (25, 50000)
b = (60, 50100)
c = (26, 52000)
print(round(dist(a, b), 1)) # 105.9
print(round(dist(a, c), 1)) # 2000.0
Why it fails. Person c is almost the same age as a, yet b looks far closer. Salary has bigger numbers, so it drowns out age.
Fix: add StandardScaler in the pipeline for KNN, K-Means, SVM and regularised linear models. Tree models do not need it.
7. Giving categories a false order
Wrong: {"Nellore": 0, "Guntur": 1, "Kurnool": 2}
Why it fails. A linear model now believes Kurnool is "more" than Guntur. Cities have no such order.
Fix: give each city its own 0 or 1 column.
from sklearn.compose import make_column_transformer
from sklearn.preprocessing import OneHotEncoder
prep = make_column_transformer(
(OneHotEncoder(handle_unknown="ignore"), ["city"]),
remainder="passthrough",
)
handle_unknown="ignore" stops a crash when a new city appears later. Real orders, such as small, medium and large, can be numbered.
8. Using information from the future
Suppose you predict whether a customer will leave. One column is refund_after_closing. It makes the score almost perfect.
Why it fails. The refund happens after the customer leaves. You will not have it on the day you need a prediction.
Fix: write the prediction moment at the top of your notebook. For each column ask, "would I know this value then?" If not, drop it.
Common mistake: Celebrating a score of 0.99 on a hard problem. Treat it as a warning first. Find the strongest feature and ask when it was recorded.
9. Shuffling time data
Wrong: a random split on daily sales.
Why it fails. The model trains on Tuesday and Thursday, then "predicts" Wednesday. In real life, you only know the past.
Fix: sort by date and test on the latest part.
df = df.sort_values("date")
cut = int(len(df) * 0.8)
train, test = df.iloc[:cut], df.iloc[cut:]
If one day has many rows, cut at a date so that the same day does not land in both parts. Also build moving averages only from earlier days.
Mistakes with model fit
10. Missing overfitting or underfitting
Looking at one score tells you little. Look at two:
| Train score | Validation score | Likely problem | Try |
|---|---|---|---|
| High | Much lower | Overfitting | Simpler model, more data |
| Low | Low | Underfitting | Better features, stronger model |
| Good | Close to train | Healthy fit | Check errors, then test |
for depth in [2, 4, 8, None]:
tree = DecisionTreeClassifier(max_depth=depth, random_state=42)
tree.fit(X_tr, y_tr)
print(depth, tree.score(X_tr, y_tr), tree.score(X_val, y_val))
Here X_tr and X_val come from splitting the training data again. Watch for the depth where the training score keeps rising but the validation score stops.
Machine learning fundamentals debugging checklist
When a model misbehaves, go in this order:
- Labels. Read 20 random rows. Are the answers right?
- Rows. Any duplicates shared by train and test?
- Time. Any column from the future?
- Baseline. Do you beat a simple guess?
- Two scores. Is the problem overfitting or underfitting?
- Errors. Read 20 wrong predictions. Is there a pattern?
- One change. Change a single thing and measure again.
This order works because it starts with the cheap checks. Many machine learning fundamentals common errors come from the data, and no new algorithm can repair wrong labels.
Pro tip: Keep a small log with the date, the change, the validation score and what you learned. It also gives you honest stories for interviews.
How to avoid machine learning fundamentals beginner mistakes
Build the habit on one small project. Split first, set a baseline, use a pipeline, tune on training data, then test once. Do it three times with different data and it becomes automatic.
Learn the basic flow in our machine learning fundamentals tutorial. Keep the ML cheat sheet beside you for metric formulas. Then check yourself with these machine learning interview questions. If you want someone to review your notebooks, read what to look for in a machine learning course.
Frequently asked questions
Why is my model good in training but bad on new data?
The usual cause is overfitting, where the model memorises training examples. Leakage or a change in the data can also cause it. Compare training and validation scores, simplify the model, and check whether the new data differs from the training data.
What is data leakage in simple words?
It means the model gets information during training that it would not have in real use. It is like seeing part of the answer paper before an exam. Scores look great at first and fall when the model meets truly new data.
Is high accuracy always good?
No. If 95 of 100 cases belong to one class, always guessing that class gives 95 percent accuracy. Check precision, recall and the confusion matrix, and compare the result with a simple baseline.
Do all models need feature scaling?
No. KNN, K-Means, SVM and regularised linear models usually need it because they are affected by the size of values. Decision trees and random forests do not need it, since they split one feature at a time.
How do I start debugging a machine learning model?
Check the data before the algorithm. Confirm the labels, the split and the row counts. Then compare with a baseline, look at training and validation scores, and read twenty wrong predictions by hand.
Follow a clear order so you avoid these errors. Use the machine learning engineer roadmap, or book a free demo class to see how the Artificial Intelligence course teaches ML through projects.
