Module 02 · Applied project
Bike Demand Regression Lab
Use the hourly Bike Sharing dataset from Module 01 to build a one-feature linear regression model from scratch. Predict cnt from temp with NumPy, derive the gradient updates, compare the result with a simple mean baseline and explain what the model cannot capture. This is a mathematical implementation exercise, not a claim that temperature alone explains bike demand.
Implementation plan
Build it in 6 steps
- 01 Load the exact
hour.csvfile used in Module 01, sort bydtedayandhr, and record the local file name, column names, missing-value counts and row count. - 02 Choose
tempas the sole feature andcntas the target. Create a chronological 80/20 train/holdout split before fitting or scaling anything. - 03 Calculate the feature mean and standard deviation on the training rows only. Apply those same values to both partitions and handle a zero standard deviation explicitly.
- 04 Implement
ŷ = wx + b, mean squared error and the batch gradients forwandb. Train with gradient descent and save the loss at regular intervals. - 05 Plot the training loss and the holdout observations with the fitted line. Calculate holdout MAE and RMSE, then compare them with a baseline that predicts the training target mean.
- 06 Fit the same intercept-and-slope model with
np.linalg.lstsqas a numerical check. Write a short report covering the result, the baseline comparison and at least two limitations.
What to submit
Deliverables
- A reproducible Python script or notebook using NumPy for every model and gradient calculation; scikit-learn is not used.
- A data audit that records the downloaded file identity, actual row count, missing values and selected columns.
- A loss-curve plot and a holdout scatter plot with the fitted regression line.
- A compact result table with holdout MAE and RMSE for the model and the training-mean baseline.
- A short report comparing gradient descent with
np.linalg.lstsqand explaining model limitations without making causal claims.
Quality gate
Before you finish
- dataThe chronological split happens before scaling; the holdout rows are not used to calculate preprocessing statistics.
- mathThe implemented gradients match the stated MSE derivatives and the loss decreases during training.
- evaluationModel and baseline metrics are calculated on exactly the same holdout rows.
- reproducibilityThe script records its inputs and random seed where applicable, and regenerates its plots and metrics.
Follow the module
Lessons for this project
- 02.01 Functions, Graphs & ML NotationRead the notation that appears in model equations: inputs, outputs, parameters, sums and the basic role of logarithms.
- 02.02 Vectors & Vector GeometryRepresent multiple measurements as a vector and reason about its direction, magnitude and distance from another vector.
- 02.03 Dot Products & SimilarityUnderstand the dot product as both a weighted sum and a measure of alignment between two vectors.
- 02.04 Matrices & Linear TransformationsTreat a matrix as a structured collection of numbers and as a transformation that maps input vectors to output vectors.
- 02.05 Linear Systems, Span & Least SquaresUnderstand how linear equations describe constraints, when a system can be solved exactly and how least squares handles noisy data.
- 02.06 Derivatives & Rates of ChangeUnderstand a derivative as the local rate of change and use basic differentiation rules to reason about how a function responds to its input.
- 02.07 Partial Derivatives, Gradients & Chain RuleExtend derivatives to functions with multiple inputs and understand the gradient as the direction in which a function increases most quickly.
- 02.08 Probability & Conditional ProbabilityRepresent uncertainty with events and probabilities, then update a probability when information about an event is known.
- 02.09 Random Variables & DistributionsUnderstand random variables as numeric outcomes and distributions as descriptions of how probability is assigned across possible values.
- 02.10 Expectation, Variance & CovarianceSummarize a distribution with its expected value and spread, then describe how two variables move together.
- 02.11 Loss Functions & Gradient DescentDefine an objective that measures prediction error and follow its gradient to update model parameters iteratively.
- 02.12 Linear Regression: Put the Math TogetherConnect a feature matrix, a parameter vector, squared error and gradient descent in one small linear-regression implementation.
How to assess your work
Project rubric
Mathematical correctness
Prediction, MSE and both parameter gradients are implemented correctly.
A finite-difference check verifies the gradients and the least-squares result is used as an independent check.
Evaluation discipline
A chronological holdout is kept separate from training and scaling.
The baseline is calculated only from training targets and compared on the exact same holdout rows.
Interpretation
The report explains the fitted relationship and gives at least two limitations.
It distinguishes association from causation and discusses omitted features, time patterns and the limitations of a straight line.
Reproducibility
The analysis can be run again with clear setup and input-file instructions.
Input identity, parameters and output locations are recorded, and all reported values regenerate from the script.