Last updated: 28 November 2026
To get started with machine learning, learn basic Python and a little maths, install scikit-learn, and build one small project from start to finish. Then improve it, explain your results, and move to a harder problem.
You do not need a powerful computer or advanced calculus for that first step. You do need a clear question, some data, and an honest way to check whether your model works.
What machine learning is
In traditional programming, you write the rules. In machine learning, an algorithm learns patterns from examples, and you use the resulting model to make predictions about new data.
A few terms appear everywhere:
- Features: the inputs, such as a house’s size and age.
- Label or target: the answer you want to predict, such as its price.
- Training: fitting a model to examples.
- Inference: using the fitted model on new inputs.
- Generalisation: how well the model performs on data it did not learn from.
The main problem types
| Task | What it does | Example question | Good first method | Common metric |
|---|---|---|---|---|
| Classification (supervised) | Predicts a category | Is this email spam? | Logistic regression | Precision, recall, balanced accuracy |
| Regression (supervised) | Predicts a number | What will this house sell for? | Linear regression | Mean absolute or squared error |
| Clustering (unsupervised) | Groups similar items without labels | Which customers behave alike? | k-means | Silhouette score, plus human review |
Start with supervised learning. You have known answers to compare against, so mistakes are easier to see.
Skills you need before you begin
You can learn much of this as you go. Aim for working comfort, not mastery.
- Python: functions, lists, dictionaries, loops, conditionals and list comprehensions.
- Data tools: NumPy for arrays and pandas for tables.
- Algebra: variables, linear equations, function graphs and logarithms.
- Statistics: mean, median, standard deviation, outliers and histograms.
- Later topics: matrix multiplication, derivatives, gradients and the chain rule.
Google’s free Machine Learning Crash Course publishes a similar list of prerequisites. It suggests an introductory ML lesson plus short NumPy and pandas tutorials for newcomers. Its programming exercises run in the browser through Colaboratory.
The course is organised into four areas: core models (linear regression, logistic regression and classification), data, advanced models (including neural networks, embeddings and large language models), and real-world ML (including production systems and fairness). Take the first two areas before the others.
The machine learning workflow
Most beginner projects follow the same steps. Learn them once and you can reuse them with many algorithms.

- Define the question. Say what you will predict and what decision it supports.
- Inspect the data. Look for missing values, duplicates, odd ranges and rare classes.
- Split the data. Set aside a test set before fitting any preprocessing.
- Build a baseline. Measure what a trivial guess achieves.
- Train and compare. Use cross-validation on the training data.
- Test once. Check your chosen model on the held-out set.
- Review errors. Find which cases fail and why.
Cross-validation divides the training data into several parts, called folds. The model trains on most folds and is scored on the remaining one, rotating until each fold has been used for scoring. This gives a steadier estimate than a single split.
The random split suits independent examples. For time-ordered data, or many rows from the same person or device, use a split that respects time or groups.
Set up your environment
scikit-learn is a sensible first library. It is open source, covers supervised and unsupervised learning, and uses a consistent interface. As of late November 2026, the version we checked is 1.9.1, and its package listing requires Python 3.11 or later.
Use a virtual environment so project packages stay separate. These commands have not been tested here. On macOS or Linux:
python3 -m venv sklearn-env
source sklearn-env/bin/activate
pip install -U scikit-learn
python -c "import sklearn; sklearn.show_versions()"
On Windows:
python -m venv sklearn-env
sklearn-env\Scripts\activate
pip install -U scikit-learn
python -c "import sklearn; sklearn.show_versions()"
If you prefer conda:
conda create -n sklearn-env -c conda-forge scikit-learn
conda activate sklearn-env
Activate the environment again whenever you open a new terminal.
Your first machine learning project
This example uses the breast cancer dataset bundled with scikit-learn. It has 569 samples and 30 numeric features: 212 samples are labelled malignant and 357 benign. It is a learning exercise only, not a diagnostic tool.
Save the code as first_model.py and run python first_model.py. The final test is switched off by default, so you can compare models without seeing test results. The code has not been tested here.
from sklearn.datasets import load_breast_cancer
from sklearn.dummy import DummyClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report, confusion_matrix
from sklearn.model_selection import cross_val_score, train_test_split
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
# Keep False while you compare and change models
RUN_FINAL_TEST = False
# 0 = malignant, 1 = benign
X, y = load_breast_cancer(return_X_y=True)
# Hold out 20% and keep class proportions similar
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, stratify=y, random_state=42
)
baseline = DummyClassifier(strategy="most_frequent")
model = make_pipeline(StandardScaler(), LogisticRegression(max_iter=1000))
# Cross-validation uses only the training data
for name, estimator in [("baseline", baseline), ("logistic", model)]:
scores = cross_val_score(
estimator, X_train, y_train, cv=5, scoring="balanced_accuracy"
)
print(name, scores.mean(), scores.std())
# Set this to the model you select from cross-validation
chosen_model = model
if RUN_FINAL_TEST:
chosen_model.fit(X_train, y_train)
predictions = chosen_model.predict(X_test)
print(confusion_matrix(y_test, predictions))
print(classification_report(
y_test, predictions, target_names=["malignant", "benign"]
))
else:
print("Final test skipped. Choose a model first.")
What the code does
- Estimators learn with
fit. Predictive models then usepredict. - The scaler puts features on comparable scales.
- The pipeline joins scaling and modelling, so each cross-validation fold learns its scaling from its own training portion.
- The dummy model always predicts the most common class.
- random_state makes the shuffled split repeatable.
- RUN_FINAL_TEST keeps the test predictions and reports behind a deliberate choice.
How to read the cross-validation results
Each output line shows a model’s name, its mean score across five folds, and the standard deviation of those scores. A large spread means the result varies considerably between folds, so be cautious about small differences between models.
In this dataset, about 63% of samples are benign. A model that always says “benign” could therefore look partly successful on plain accuracy while finding no malignant cases.
Balanced accuracy averages the recall of each class. An always-one-class guess scores 0.5 on a two-class problem, so your real model should do clearly better.
Best practices from the start
- Split before preprocessing. Never call
fitorfit_transformon test data. - Use pipelines. They help keep scaling, imputation and feature selection inside the correct data subset.
- Begin simple. A linear or logistic model gives you something understandable to beat.
- Choose metrics from the goal. Ask which mistakes cost the most.
- Change one thing at a time. Record the change and its cross-validation score.
- Record your setup. Save package versions, random seeds and the data source.
Common mistakes and troubleshooting
| Symptom | Likely cause | What to try |
|---|---|---|
| Scores look too good | Data leakage, duplicates, or a feature that reveals the answer | Audit features and move preprocessing into a pipeline |
| Training score high, validation score low | Overfitting | Simplify or regularise the model, or get more data |
| Both scores low | Underfitting or weak features | Improve features or try a more flexible model |
| High accuracy, rare class missed | Class imbalance | Check recall, precision and balanced accuracy |
| Convergence warning | Unscaled features or too few iterations | Scale inputs, then raise max_iter |
| Import error for sklearn | Environment inactive or package installed elsewhere | Activate it and run python -m pip show scikit-learn |
Leakage deserves special attention because it may raise no error at all. It happens when model building uses information that would not be available at prediction time. For example, selecting the “best” features using the whole dataset lets the test data influence the model.
Hands-on exercise
Spend an hour or two extending the project. Leave RUN_FINAL_TEST = False for steps 1 to 4.
- Run the script and note the baseline and logistic cross-validation scores.
- Import
RandomForestClassifierfromsklearn.ensemble. Above the loop, createforest = RandomForestClassifier(random_state=42), then add("forest", forest)to the loop’s list. - Remove
StandardScaler()from the logistic pipeline and run the script again. Observe any warnings and score changes, then restore the scaler. - Choose a model using only cross-validation results. Set
chosen_modeltomodelorforest. - When your choice is settled, set
RUN_FINAL_TEST = Trueand run the script once. Save the output, then set the switch back toFalse. - Write five sentences covering the question, data, baseline, result and one limitation.
How to read the final test results
In the confusion matrix, rows are true classes and columns are predicted classes. Check the top-right cell: with this label order, it counts malignant samples predicted as benign. In a medical setting, that error would matter greatly.
The classification report shows precision and recall for each class. Malignant recall tells you what share of the malignant test samples the model found.
If you keep changing the model after seeing these results, the test set no longer gives a fresh estimate. Treat later scores with caution, or evaluate on new data that played no part in your choices.
A suggested study plan
This is an example schedule for a part-time learner. Adjust it to your background.
| Weeks | Focus | Output |
|---|---|---|
| 1–2 | Python, NumPy, pandas | A short data exploration notebook |
| 3–4 | Regression, classification, metrics | One model compared with a baseline |
| 5–6 | Data preparation, overfitting, pipelines | A project using mixed numeric and categorical data |
| 7–8 | Tree ensembles, parameter search | A written comparison of models |
| Afterwards | Neural networks or deployment | A project matched to your goals |
For parameter search, try RandomizedSearchCV on your training data and pass it the whole pipeline. For mixed column types, learn ColumnTransformer.
FAQ
Can I learn machine learning without strong maths?
You can start with basic algebra and statistics. Study linear algebra and calculus as you need to understand training methods in more depth.
Do I need a GPU?
Not for the small project above or typical introductory exercises with small tables of data. Larger neural networks are where specialised hardware becomes more relevant.
Should I start with large language models?
If your aim is to understand machine learning, learn data splitting, evaluation and simple models first. Those ideas help you judge more complex systems. If you only want to build an app on an existing model, you can learn both side by side.
How long does it take?
There is no fixed answer. It depends on your programming background, study time and goal. Measure progress by projects you can build and explain.
What should my second project be?
Pick a small public dataset on a subject you understand. Include missing or categorical values, define a baseline, and document where the model fails.
Your next action is simple: create the environment, run the script with the final test switched off, and explain how the model compares with the baseline.