Set-up · 25 minutes
Set up your lab for AI for security operations
- Create the lab folder and a virtual environment with the pinned libraries
- Save the data generator that makes every data set of the course
- Prove with a check script that the lab and the local model work
The lab folder as it stands after this lesson. Unzip it in ~/krlab.
More
The zip holds every file that the course has printed up to here. Type the code yourself first: you learn more.
What you need
- The courses "How AI works" (the libraries and the measures precision and recall), "How LLMs and agents work" (the local model server), "Security fundamentals" (logs and detection) and "Security operations basics" (the SOC workflow by hand: this course adds the model). This course names their lessons and does not teach them again.
- Python 3.12 or newer. The pinned libraries need it. The programs of the course need Python 3.10 or newer, and nothing else.
- The model server Ollama, running, with the model
llama3.2:3b. You installed it in lesson 3 of "How LLMs and agents work". Only lesson 3 uses it. If your computer cannot run a 3B model, setKR_NO_MODEL=1(see "Check your lab"): you can then do everything except the model run of lesson 3, and the checks of lesson 3 use a recorded file. - About 500 MB of free disk space for the libraries, and 4 GB of free memory for the model. No GPU, no account and no paid service.
Everything runs on your own computer, in one folder: ~/krlab/ai-for-secops. All data is invented. The company is "Harbourline Logistics", every person is made up, every outside address comes from a block that RFC 5737 reserves for documentation (192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24), every inside address is in the private block 10.20.0.0/16, and every domain ends in .example or .test. Never put real logs, real mail or real customer data into this lab.
- Check script → gen.py: is the data fingerprint the same?
- gen.py → Lesson programs: data from a fixed seed
- Lesson programs → Local model: lesson 3 only
Set it up
1. Make the lab folder
mkdir -p (make directory, with its parents) creates the folder. cd (change directory) moves you into it.
mkdir -p ~/krlab/ai-for-secops
cd ~/krlab/ai-for-secops
pwd/home/you/krlab/ai-for-secops2. Make the environment and install the pinned libraries
A virtual environment is a private folder of Python packages, and a pinned version is an exact one (lesson 0 of "How AI works" explains both). Pins give every reader the same numbers. Save requirements.txt first.
requirements.txt
scikit-learn==1.9.1
numpy==2.5.5
scipy==1.18.1
joblib==1.6.0python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtRun source .venv/bin/activate at the start of every lesson. Your prompt then starts with (.venv).
3. Save the data generator
gen.py makes all the data of the course: a week of security alerts, one case log, a week of login sessions, short mail messages, ten threat reports, a day of mail and twelve payment requests. Every record is made by a program, with a fixed seed. A seed is the start number of a random number generator. random.Random(1005) gives the same "random" numbers on every machine, so you get exactly the data that the lessons show.
The file is long, and you do not need to read it now. Each lesson names the function that it uses. Two things are worth knowing. First, in each record a field label holds the true answer (1 for a real incident, a real phishing message or a planted anomaly). The lessons use it only to measure a detector, as in "How AI works", lesson 6. Second, fingerprint() makes a short code from all the data. If your copy of the file differs by one character, the code differs, and the check script tells you.
gen.py
"""gen.py: the synthetic data of the course "AI for security operations".
Every record is invented. Every function uses its own fixed seed, so every reader gets the same data.
Outside addresses come from the blocks that RFC 5737 reserves for documentation, inside addresses are
in 10.20.0.0/16, domains end in .example or .test, and every person and company is made up.
python3 gen.py print the size of each data set and its fingerprint
python3 gen.py intel write the intel reports into the folder intel/
"""
import hashlib
import json
import random
import sys
from pathlib import Path
DAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
USERS = ["alma", "boris", "chen", "dana", "emil", "farah", "gus", "hana", "ivo", "jun", "kofi", "lena",
"marek", "nadia", "omar", "petra", "quinn", "rosa", "sven", "tara", "uma", "viktor", "wen", "yara"]
BAD_IPS = [f"203.0.113.{n}" for n in (10, 11, 12, 23, 24, 57, 58, 90, 91, 140, 141, 200)]
EXTERNAL = [f"{block}.{n}" for block in ("198.51.100", "192.0.2", "203.0.113") for n in range(30, 250, 7)
if f"{block}.{n}" not in BAD_IPS]
ASSET_OWNER = {1: "workstation pool", 2: "business server team", 3: "finance and payroll team"}
# ---------------------------------------------------------------- alerts
RULES = ["failed-login-burst", "impossible-travel", "malware-signature", "port-scan", "dns-odd-domain",
"large-upload", "new-admin-account", "phishing-report"]
RULE_WEIGHT = [22, 6, 12, 20, 14, 10, 4, 12]
RULE_P = [0.03, 0.12, 0.08, 0.015, 0.04, 0.10, 0.25, 0.06] # chance that an alert of this rule is real
def _alert(r, rule, real, shift, scanner=False):
"""One alert. The label is chosen first, and then the fields are drawn to match it, with overlap.
About one real alert in ten is quiet: its fields look like those of a harmless alert."""
label = int(real)
real = real and r.random() > 0.1
hour = r.choice([0, 1, 2, 3, 4, 5, 22, 23]) if r.random() < (0.5 if real else 0.12) else r.randint(8, 17)
severity = r.choice([1, 2, 2, 3, 3, 4])
asset = r.choices([1, 2, 3], [0.3, 0.4, 0.3] if real else [0.6, 0.3, 0.1])[0]
admin = int(r.random() < (0.25 if real else 0.08))
ext = int(r.random() < (0.7 if real else 0.35))
new_source = int(r.random() < (0.6 if real else 0.2))
count = r.randint(1, 3)
mb = r.randint(0, 60) if real else r.randint(0, 20)
if real and r.random() < 0.4:
severity = min(4, severity + 1)
if rule == "failed-login-burst":
count = r.randint(20, 80) if real else r.randint(5, 15)
elif rule == "port-scan":
count = r.randint(100, 1500) if real else r.randint(10, 200)
elif rule == "large-upload":
mb = r.randint(100, 900) if real else r.randint(20, 150)
if shift and real: # a new campaign: quiet, in working hours, from ordinary accounts
hour, admin, asset = r.randint(9, 17), int(r.random() < 0.05), r.choices([1, 2, 3], [0.2, 0.7, 0.1])[0]
severity, new_source, ext, mb = r.choice([1, 1, 2, 3]), int(r.random() < 0.3), int(r.random() < 0.5), r.randint(0, 40)
if rule == "failed-login-burst":
count = r.randint(12, 30)
if scanner: # the nightly vulnerability scanner of the shifted week: noisy and harmless
rule, hour, count, severity, ext, new_source, admin, asset = "port-scan", r.randint(1, 4), r.randint(800, 2000), 3, 1, 1, 0, 3
user = r.choice(USERS[:3]) if admin else r.choice(USERS[3:])
if ext:
src = r.choice(BAD_IPS) if r.random() < (0.35 if label else 0.02) else r.choice(EXTERNAL)
else:
src = f"10.20.{r.randint(0, 9)}.{r.randint(2, 250)}"
host = f"srv-{r.randint(1, 12):02d}" if asset > 1 else f"wks-{r.randint(1, 30):02d}"
return {"rule": rule, "hour": hour, "severity": severity, "user": user, "host": host, "src_ip": src,
"count": count, "mb_out": mb, "asset": asset, "admin": admin, "ext_src": ext,
"new_source": new_source, "label": label}
def alerts(week, n=1000, shift=False):
"""One week of alerts in arrival order. week 1 to 4 are history, week 5 is the fixed week of the lessons.
shift=True is a week with a new pattern (lesson 15)."""
r = random.Random((2000 if shift else 1000) + week)
rules, weights, probs = RULES[:], RULE_WEIGHT[:], RULE_P[:]
if shift:
rules.append("oauth-consent-grant")
weights.append(12)
probs = [p * 0.6 for p in probs] + [0.40]
out = []
scanners = 60 if shift else 0
for _ in range(n - scanners):
k = r.choices(range(len(rules)), weights)[0]
out.append(_alert(r, rules[k], r.random() < probs[k], shift))
for _ in range(scanners):
out.append(_alert(r, "port-scan", False, shift, scanner=True))
r.shuffle(out)
days = [160] * 5 + [100] * 2
first = 0
for d, size in enumerate(days):
for a in out[first:first + size]:
a["day"] = DAYS[d]
first += size
for i, a in enumerate(out):
a["id"] = f"W{week}-{i + 1:04d}"
a["text"] = (f"{a['rule']} on {a['host']} for {a['user']} from {a['src_ip']} at {a['hour']:02d}:00, "
f"count {a['count']}, {a['mb_out']} MB out, severity {a['severity']}")
return out
# ---------------------------------------------------------------- one case log
def case_log(seed=21):
"""The auth log of one host for one night, as text lines. One account is guessed and then used."""
r = random.Random(seed)
lines, t = [], 0
for i in range(40):
t += r.randint(30, 400)
user = r.choice(["alma", "boris", "chen", "emil", "farah"])
ok = "ok" if r.random() < 0.9 else "fail"
lines.append((t, f"LOGIN {ok} user={user} ip=10.20.{r.randint(0, 9)}.{r.randint(2, 250)}"))
start = 2 * 3600 + 11 * 60 + 5
for i in range(23):
start += r.randint(2, 9)
lines.append((start, "LOGIN fail user=dana ip=203.0.113.57"))
lines.append((start + 6, "LOGIN ok user=dana ip=203.0.113.57"))
lines.append((start + 31, "FILE read user=dana path=/finance/payroll-2026.xlsx"))
lines.append((start + 40, "FILE download user=dana path=/finance/payroll-2026.xlsx"))
lines.sort()
day = "2026-03-14"
return [f"{day} {s // 3600:02d}:{s % 3600 // 60:02d}:{s % 60:02d} {text} host=srv-04" for s, text in lines]
# ---------------------------------------------------------------- login events
def logins(seed=31):
"""A week of login sessions. A few are planted anomalies (label 1). label 2 is an odd but harmless backup run."""
r = random.Random(seed)
rows = []
for u in USERS:
base = r.randint(8, 11)
for d in range(7):
for _ in range(r.randint(0, 2) if d > 4 else r.randint(4, 7)):
rows.append({"user": u, "day": DAYS[d], "hour": min(23, max(0, round(r.gauss(base + 3, 2)))),
"failed": r.choice([0, 0, 0, 0, 0, 1, 1, 2]), "mb_down": max(1, round(r.gauss(30, 12))),
"hosts": r.choice([1, 1, 2, 2, 2, 3, 3, 4]), "label": 0})
for k in range(2): # one extreme download, in working hours
rows[r.randrange(len(rows))].update(mb_down=r.randint(500, 800), label=1)
for k in range(5): # moderate changes in several fields at once
rows[r.randrange(len(rows))].update(hour=r.randint(4, 5), failed=2, mb_down=r.randint(55, 65),
hosts=4, label=1)
rows[r.randrange(len(rows))].update(mb_down=420, hosts=3, label=2)
for i, row in enumerate(rows):
row["id"] = f"L{i + 1:04d}"
return rows
# ---------------------------------------------------------------- messages
URGENT = ["urgent", "immediately", "now", "suspended", "final notice", "within 24 hours", "expires", "verify"]
PHISH_OLD = [
"URGENT: your account is suspended. Verify your password now at the link",
"Final notice: your mailbox expires today. Verify your login immediately",
"Your payment failed. Update your card details within 24 hours at the link",
"Security alert: unusual sign in. Verify your account now or lose access",
"Your parcel is held. Pay the fee immediately at the link",
]
PHISH_NEW = [
"Hello, a document was shared with you. You can open it here",
"Your colleague sent you a file for review. Open it at the link",
"The report you asked for is ready. You can read it at the link",
"Please find the updated schedule at the link below",
"A voice message was left for you. Listen at the link",
]
PHISH_CALM = [
"Please confirm your details at the link",
"Your document is waiting for you at the link",
"Click the link to review your account",
]
GOOD_OLD = [
"Lunch at noon? I booked a table for four",
"The meeting moved to Thursday at ten. Please confirm now if that is a problem",
"Minutes of the call are in the shared folder",
"Can you review my pull request today?",
"The build passed and the release is on Friday",
"Please verify the figures in the quarterly report before Monday",
"Reminder: the office closes early today. Final notice for holiday requests is Friday",
]
GOOD_NEW = [
"A document was shared with you. You can open it here",
"Your colleague sent you a file for review. Open it at the link",
"The report you asked for is ready. You can read it at the link",
"Please find the updated schedule at the link below",
"A voice message was left for you. Listen at the link",
]
SENDERS = ["bank.example", "shop.example", "mail.example", "post.example", "cloud.example"]
LOOKALIKE = ["secure-login.test", "account-check.test", "update-portal.test", "verify-now.test"]
def messages(seed, n, style="old"):
"""Short labelled messages. style "new" is wording that the model never saw in training.
In the old style, a few phishing messages use calm words, and a few real alerts use urgent words."""
r = random.Random(seed)
out = []
for i in range(n):
phish = r.random() < 0.3
sender = r.choice(SENDERS)
if phish:
pool = PHISH_OLD if style == "old" else PHISH_NEW
if style == "old" and r.random() < 0.3:
pool = PHISH_CALM
text, link = r.choice(pool), r.choice(LOOKALIKE)
if r.random() < 0.07: # sent from a hijacked account: the domain matches
link = sender
else:
pool = GOOD_OLD if style == "old" else GOOD_NEW
if style == "old" and r.random() < 0.08:
pool = PHISH_OLD
text = r.choice(pool)
link = ""
if style == "new" or r.random() < 0.15 or pool is PHISH_OLD: # a real link: the same domain, or a mail service of the sender
link = sender if r.random() < 0.8 else r.choice(["links." + sender, "links." + sender, "mailer.test"])
out.append({"id": f"M{seed}-{i + 1:03d}", "sender": sender, "link": link, "text": text, "label": int(phish)})
return out
# ---------------------------------------------------------------- intel base
INTEL = {
"rpt-01.txt": ("2026-01-12", "Harbour CERT", "Group Alder sends invoice emails to finance staff. The emails link to a page that asks for a "
"password. Alder began this in January.", ["alder-target = finance staff", "alder-lure = invoice email"]),
"rpt-02.txt": ("2026-03-10", "Harbour CERT", "A sample from Group Alder calls home to the address 198.51.100.23 on port 8443 every "
"10 minutes. The sample is a small loader.", ["alder-c2-port = 8443", "alder-c2-address = 198.51.100.23"]),
"rpt-03.txt": ("2026-04-02", "Vendor Northwind", "Group Birch tries stolen passwords against remote desktop gateways. Attempts "
"peak near 03:00 UTC.", ["birch-target = remote desktop gateways", "birch-peak = 03:00 UTC"]),
"rpt-04.txt": ("2026-05-20", "Partner Blue Quay", "Group Birch reuses passwords from old breaches. Accounts without a second factor "
"fall first.", ["birch-method = reused passwords"]),
"rpt-05.txt": ("2026-06-18", "Harbour CERT", "A loader that is used by Group Alder installs a scheduled task named SyncHelper. "
"Look for that task name on finance laptops.", ["alder-persistence = scheduled task SyncHelper"]),
"rpt-06.txt": ("2026-07-07", "Vendor Northwind", "Group Cedar scans for old file transfer servers that have no patch. It does not "
"use email.", ["cedar-target = unpatched file transfer servers", "cedar-lure = none"]),
"rpt-07.txt": ("2026-09-14", "Harbour CERT", "New analysis of Group Alder: the loader now calls home on port 9443. The address is "
"unchanged. Earlier reports of port 8443 are out of date.", ["alder-c2-port = 9443", "alder-c2-address = 198.51.100.23"]),
"rpt-08.txt": ("2026-09-30", "Partner Blue Quay", "Group Birch has moved from remote desktop gateways to VPN portals in the last "
"month.", ["birch-target = VPN portals"]),
"rpt-09.txt": ("2026-10-12", "Unverified forum post", "A forum user claims that Group Cedar now sends emails with fake tax notices. "
"No proof was given.", ["cedar-lure = fake tax notice email"]),
"rpt-10.txt": ("2026-10-21", "Harbour CERT", "Advice for all groups: a second factor on every remote access service stops most "
"password reuse attacks.", ["advice = second factor on remote access"]),
}
AS_OF = "2026-11-01"
def intel_text(name):
date, source, body, claims = INTEL[name]
return (f"Report: {name}\nDate: {date}\nSource: {source}\n\n{body}\n\nClaims:\n" + "".join(f"- {c}\n" for c in claims))
# ---------------------------------------------------------------- mail stream and payment requests
CORP = "harbourline.example"
EXECS = {"Priya Nair": "CFO", "Tomas Weber": "CEO"}
STAFF = [f"{u}@{CORP}" for u in USERS]
NORMAL = ["Can we move the call to {t}?", "The deck for {t} is in the shared folder.", "Thanks, I will check the figures by {t}.",
"Please send me the signed form before {t}.", "Lunch at {t}? The usual place.", "The build is green. Release at {t}."]
VARIANT = [("Hello {n},", "Hi {n},", "Dear {n},"),
("our supplier has {a} its bank details.", "the supplier {a} its bank details.", "we were told the supplier {a} its bank account."),
("Please {b} the new details in the portal today.", "Could you {b} the new details through the link?", "We need you to {b} the new details at the link.")]
def mail_stream(seed=41):
"""A day of mail, one record each: minute of the day, sender name and address, recipient, text."""
r = random.Random(seed)
rows = []
for i in range(220):
s = r.choice(STAFF)
rows.append({"minute": r.randint(420, 1080), "name": s.split("@")[0].title(), "addr": s, "to": r.choice(STAFF),
"text": r.choice(NORMAL).format(t=f"{r.randint(9, 17)}:{r.choice(['00', '30'])}"), "label": 0})
for i in range(30): # one sender, the same text: a normal newsletter
rows.append({"minute": 540 + i, "name": "Hr Team", "addr": f"hr@{CORP}", "to": STAFF[i % len(STAFF)],
"text": "The new leave policy is on the intranet. Please read it this week.", "label": 0})
for i in range(12): # one sender, slightly different words: a normal reminder
rows.append({"minute": 780 + i, "name": "Hr Team", "addr": f"hr@{CORP}", "to": STAFF[i % len(STAFF)],
"text": f"Reminder {i}: please send your timesheet for {r.choice(['May', 'June', 'July'])} by {r.choice(['Friday', 'Monday'])}.",
"label": 0})
senders = [("Priya Nair", "priya.nair@mailbox.test"), ("Tomas Weber", "t.weber@mailbox.test"), ("Accounts", "accounts@billing-desk.test")]
senders += [("Finance Desk", f"desk{k}@pay-{k}.test") for k in range(1, 7)]
for i in range(26): # many senders, many unique texts: one burst
name, addr = senders[i % len(senders)]
rows.append({"minute": 600 + r.randint(0, 38), "name": name, "addr": addr, "to": STAFF[(i * 3) % len(STAFF)],
"text": " ".join(r.choice(part).format(n=STAFF[(i * 3) % len(STAFF)].split("@")[0].title(),
a=r.choice(["changed", "updated", "replaced"]),
b=r.choice(["confirm", "check", "approve"])) for part in VARIANT),
"label": 1})
rows.sort(key=lambda m: m["minute"])
for i, m in enumerate(rows):
m["id"] = f"S{i + 1:03d}"
return rows
def payment_requests():
"""Twelve requests to move money. channel is how the request arrived."""
keys = ["id", "channel", "amount", "new_payee", "approved_in_system", "callback_done"]
rows = [("R01", "email", 1200, 0, 1, 0), ("R02", "email", 48000, 1, 0, 0), ("R03", "voice", 25000, 0, 0, 0),
("R04", "video", 90000, 1, 0, 0), ("R05", "chat", 300, 0, 1, 0), ("R06", "voice", 15000, 0, 1, 1),
("R07", "email", 7000, 1, 1, 1), ("R08", "video", 60000, 0, 0, 1), ("R09", "email", 9500, 0, 1, 0),
("R10", "voice", 4000, 1, 0, 0), ("R11", "email", 52000, 0, 1, 1), ("R12", "chat", 18000, 1, 0, 1)]
return [dict(zip(keys, row)) for row in rows]
# ---------------------------------------------------------------- fingerprint
def fingerprint():
"""A short code that is the same on every machine that has the same data."""
parts = [alerts(5), alerts(6, shift=True), case_log(), logins(), messages(1, 300), messages(2, 100, "new"),
sorted(INTEL.items()), mail_stream(), payment_requests()]
return hashlib.sha256(json.dumps(parts, sort_keys=True).encode()).hexdigest()[:12]
if __name__ == "__main__":
if sys.argv[1:] == ["intel"]:
Path("intel").mkdir(exist_ok=True)
for name in INTEL:
Path("intel", name).write_text(intel_text(name))
print(f"wrote {len(INTEL)} reports into intel/")
else:
w = alerts(5)
print("alerts week 5:", len(w), "real:", sum(a["label"] for a in w))
print("alerts shifted week 6:", len(alerts(6, shift=True)), "real:", sum(a["label"] for a in alerts(6, shift=True)))
print("case log lines:", len(case_log()))
print("login sessions:", len(logins()))
print("messages:", len(messages(1, 300)), "new style:", len(messages(2, 100, "new")))
print("intel reports:", len(INTEL))
print("mail stream:", len(mail_stream()), "payment requests:", len(payment_requests()))
print("fingerprint:", fingerprint())4. Look at the sizes
python3 gen.py prints the size of each data set and the fingerprint.
python3 gen.pyalerts week 5: 1000 real: 59
alerts shifted week 6: 1000 real: 61
case log lines: 66
login sessions: 709
messages: 300 new style: 100
intel reports: 10
mail stream: 288 payment requests: 12
fingerprint: 2757ddccf878The two last numbers of the first line, 1000 alerts and 59 real, are the facts of the fixed week that most lessons use. About 6 alerts in 100 are real.
Check your lab
The script labcheck.py prints one line for each of nine requirements and a last line with the total. If you cannot run the model, type export KR_NO_MODEL=1 first: the two model lines then read skip, and the total is 7 of 7. __import__(name) loads a library whose name is in a variable, and __version__ is the version text that a library carries. os.environ.get(name) reads an environment variable. gen.fingerprint() computes the code of the data. urllib.request.urlopen sends a web request, here to the model server on your own computer. sys.exit(1) ends the program with exit code 1, which means "failed".
labcheck.py
"""labcheck.py: prove that the lab of "AI for security operations" works."""
import json
import os
import sys
import urllib.request
from pathlib import Path
PINNED = {"sklearn": "1.9", "numpy": "2.5", "scipy": "1.18", "joblib": "1.6"}
FINGERPRINT = "2757ddccf878" # the code of the data that gen.py makes
SERVER = os.environ.get("KR_OLLAMA", "http://127.0.0.1:11434")
MODEL = os.environ.get("KR_MODEL", "llama3.2:3b")
NO_MODEL = os.environ.get("KR_NO_MODEL") == "1" # a reader who cannot run a model sets this
results = []
def check(name, ok, detail):
"""Print one line for one requirement and remember the result."""
results.append(ok)
print(("ok " if ok else "FAIL ") + name.ljust(8) + detail)
v = sys.version_info
check("python", v >= (3, 12), f"{v.major}.{v.minor}.{v.micro}")
check("venv", sys.prefix != sys.base_prefix, sys.prefix)
for module, want in PINNED.items():
try:
lib = __import__(module)
have = ".".join(lib.__version__.split(".")[:2])
check(module, have == want, f"{lib.__version__} (the lessons use {want}.x)")
except ImportError:
check(module, False, "not installed")
try:
import gen
check("data", gen.fingerprint() == FINGERPRINT, "gen.py makes the same data as the lessons")
except Exception as error:
check("data", False, f"gen.py: {error}")
if NO_MODEL:
print("skip server KR_NO_MODEL=1: only lesson 3 needs the model")
print("skip model KR_NO_MODEL=1")
else:
try:
with urllib.request.urlopen(SERVER + "/api/tags", timeout=3) as reply:
installed = [m["name"] for m in json.load(reply)["models"]]
except (OSError, ValueError, KeyError):
installed = None
check("server", installed is not None, "a model server answers" if installed is not None else "no answer from " + SERVER)
check("model", MODEL in (installed or []), f"{MODEL} is installed" if MODEL in (installed or []) else f"{MODEL} is not installed")
print(f"lab ready: {sum(results)} of {len(results)}")
sys.exit(0 if all(results) else 1)python3 labcheck.pyok python 3.14.4
ok venv /home/you/krlab/ai-for-secops/.venv
ok sklearn 1.9.1 (the lessons use 1.9.x)
ok numpy 2.5.5 (the lessons use 2.5.x)
ok scipy 1.18.1 (the lessons use 1.18.x)
ok joblib 1.6.0 (the lessons use 1.6.x)
ok data gen.py makes the same data as the lessons
ok server a model server answers
ok model llama3.2:3b is installed
lab ready: 9 of 9Your Python version and your folder can differ. Every other line must be the same. Type the last line of your own output, and the code that gen.py printed.
If it fails
Read the first line that starts with FAIL. Fix that one, then run python3 labcheck.py again. The script ends with exit code 1 when a requirement fails.
| The script says | What it means | What to do |
|---|---|---|
FAIL python | Python is older than 3.12. | Install Python 3.12 or newer, then make the environment again with that python3. |
FAIL venv | The environment is not switched on. | Run source .venv/bin/activate in the lab folder. |
FAIL sklearn not installed (or numpy, scipy, joblib) | The install did not run in this environment. | Switch the environment on, then run pip install -r requirements.txt again. |
FAIL sklearn 1.8.0 (the lessons use 1.9.x) | Another version is installed. | Run pip install -r requirements.txt again. |
FAIL data | gen.py is missing, or it differs from the lesson. | Save the file again from the lesson, whole, and run the script again. A tab or a missing line is enough to change the code. |
FAIL server | No model server answers on 127.0.0.1:11434. | Start it with ollama serve in another terminal. Lesson 3 of "How LLMs and agents work" shows the install. If your computer cannot run the model, run export KR_NO_MODEL=1 and check again. |
FAIL model | The server runs, but it has no llama3.2:3b. | Run ollama pull llama3.2:3b (a download of about 2 GB). |
If pip cannot find a pinned version for your system, follow "If it fails" in the set-up lesson of "How AI works": use the newest versions, and read a number that differs only in its last digit as correct. The answers that this course checks are counts and values rounded to two decimals. The check on this page expects lab ready: 9 of 9 (or lab ready: 7 of 7 with KR_NO_MODEL=1), so it will not accept a run with a FAIL line.