Quiz 2

Cross-Validation

116 words
1 min read
Python Week 1: the first filter for runtime behavior
Visual companion
Python
Type and operator map

Python Week 1: the first filter for runtime behavior

View
Revision summary

What this note is really saying

Short form

# Cross-Validation ## 3.1 K-Fold Cross-Validation Split data into $k$ folds. Train on $k-1$ folds, test on the remaining fold.

Cross-Validation

3.1 K-Fold Cross-Validation

Split data into kk folds. Train on k1k-1 folds, test on the remaining fold. Repeat kk times.
python
from sklearn.model_selection import cross_val_score
from sklearn.linear_model import Ridge
import numpy as np
X = np.random.randn(100, 5)
y = X[:, 0] + 0.5 * X[:, 1] + np.random.randn(100) * 0.1
model = Ridge(alpha=1.0)
scores = cross_val_score(model, X, y, cv=5, scoring='r2')
print(f"R2 scores: {scores}, mean: {scores.mean():.3f}")

3.2 LOOCV (Leave-One-Out)

k=nk = n: train on n1n-1 observations, test on the one left out. High variance, computationally expensive.

Bias-Variance Tradeoff

Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.