How to Build a Data Science Portfolio That Holds Up
A data science portfolio is judged in minutes, usually by someone who clones one repository and tries to run it. This article builds a small portfolio project that survives that test: it downloads its own data, trains a model, checks itself with automated tests, and gives the same numbers on every run. The code was run for this article and every output below is real. The advice on what reviewers value is my judgement, not survey data.

What makes a portfolio project credible
Many portfolios are notebooks that only run on the author’s laptop, with an accuracy figure and no baseline. Three properties set a project apart: it reruns from a clean checkout, it compares the model with a trivial baseline, and it has at least a few tests that fail when something breaks. None needs a complicated model. The example uses the Palmer penguins data from the seaborn-data repository, which is small and well known, so the focus stays on engineering. For your own portfolio, choose data that interests you; a familiar toy dataset on its own rarely stands out. See our list of data science projects for beginners for ideas.
The folder layout
data/penguins.csv
requirements.txt
src/__init__.py
src/data.py
src/model.py
tests/__init__.py
tests/test_model.pySeven files are enough. Code lives in src, tests in tests, and requirements.txt pins exact versions (pandas 3.0.5, scikit-learn 1.9.1, pytest 9.1.1 here) so a reviewer gets the same behaviour. Put the project under version control from the start; our Git and GitHub guide covers how.
Load the data once, then work offline
import hashlib
from pathlib import Path
import pandas as pd
URL = "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/penguins.csv"
PATH = Path("data/penguins.csv")
def load(path=PATH):
"""Download once, then read the local copy so reruns are offline and identical."""
if not path.exists():
path.parent.mkdir(exist_ok=True)
pd.read_csv(URL).to_csv(path, index=False)
df = pd.read_csv(path)
return df.dropna(subset=["bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"])
def fingerprint(path=PATH):
return hashlib.sha256(Path(path).read_bytes()).hexdigest()[:12]The raw file has 344 rows, 11 of them with at least one missing value; the four measurement columns used here are missing in 2, leaving 342 rows. The fingerprint is a short hash of the saved file. Printing it with the results lets anyone confirm they ran on the same data, which matters because a CSV downloaded from a URL can change without notice.
A model with a baseline and a fixed seed
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import cross_val_score, train_test_split
from src.data import load, fingerprint
FEATURES = ["bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"]
def build():
return make_pipeline(StandardScaler(), LogisticRegression(max_iter=1000))
def run(seed=0):
df = load()
X, y = df[FEATURES], df["species"]
Xtr, Xte, ytr, yte = train_test_split(X, y, test_size=0.25, random_state=seed, stratify=y)
model = build().fit(Xtr, ytr)
cv = cross_val_score(build(), Xtr, ytr, cv=5)
return {"rows": len(df), "data": fingerprint(), "cv_mean": round(float(cv.mean()), 3),
"test_acc": round(model.score(Xte, yte), 3),
"majority": round(float(y.value_counts(normalize=True).max()), 3)}
if __name__ == "__main__":
print(run())Scaling sits inside the pipeline so it is learned from training rows only, a simple guard against leakage (see our scikit-learn model guide). Running python -m src.model twice gave identical output both times:
{'rows': 342, 'data': '92da526b754b', 'cv_mean': 0.98, 'test_acc': 0.988, 'majority': 0.442}
{'rows': 342, 'data': '92da526b754b', 'cv_mean': 0.98, 'test_acc': 0.988, 'majority': 0.442}Always guessing the most common species (Adelie) is right 44.2% of the time. The pipeline reaches 98.0% in five-fold cross-validation and 98.8% on 86 held-out penguins. With only 86 test rows, one extra mistake moves the figure by about 1.2 points, so a README should say “about 98%” and not claim more precision. Penguin species are also an easy problem; the result shows the project works, not that the model is clever.
Three tests that guard the result
from src.data import load
from src.model import run, FEATURES
def test_no_missing_features():
assert load()[FEATURES].isna().sum().sum() == 0
def test_beats_majority_baseline():
r = run()
assert r["test_acc"] > r["majority"] + 0.3
def test_is_reproducible():
assert run(seed=0) == run(seed=0)
$ python -m pytest -q
... [100%]
3 passed in 0.90sTo check the tests do their job, I removed the line that drops missing rows from load(). All three tests failed (the first with assert np.int64(8) == 0, the others with scikit-learn’s “Input X contains NaN” error), and restoring the line brought back 3 passed. A test that has never been seen to fail proves little, so do this once for your own project. The pytest documentation covers fixtures and parametrised tests when you outgrow these.
What goes in the README
Keep it short and in this order: one sentence on the question, the exact command to run (pip install -r requirements.txt, then python -m src.model), the output you got with the data fingerprint, the baseline next to the result, and a short list of limits. Here the limits are a small, easy dataset, a single split, and no claim beyond penguins. Add a chart, but only one that answers a question. Reviewers value honesty about limits more than a high number. For a list of where to find data and courses, see free data science resources. What this article did not test: how reviewers actually react, or notebooks, dashboards and deployment, which you may want in a fuller project.
Frequently asked questions
How many projects should a data science portfolio have?
There is no tested number. Two or three finished, reproducible projects on different problems usually say more than ten half-finished notebooks.
Should I use Kaggle datasets in my portfolio?
You can, but a popular dataset with a popular approach will look like everyone else’s. Pick a question you care about, collect or clean some of your own data, and explain your choices.
Do portfolio projects need tests?
They do not need many. A few checks on the data and a baseline comparison, as above, show that you know results can silently break.
