How bahafn/from-scratch-linear-regression works
This is a small C linear-regression example, not a general data platform. Its main workflow reads a numeric CSV dataset, splits it into training and test sets, fits feature scaling on the training set and applies it to both sets, trains a least-squares model, predicts test targets, and reports regression metrics. The implementation also provides matrix storage and a linear-system solver beneath model training. Some implementation details, including prediction and metric internals, were not sampled; the map shows only their documented or explicit use.
Main entry points: main.c Example runner · linear_regression.c CSV reader · matrix.c Linear solver · linear_regression.h Dataset storage
Components 15
Example workflow
- Example runner
src/main.c - Printed results
src/main.c
Dataset preparation
- CSV reader
src/linear_regression.c - Numeric parsing
src/string_utils.h - Dataset storage
src/linear_regression.h - Train/test split
src/linear_regression.c - Fit min-max scaling
src/linear_regression.c - Transform features
src/linear_regression.c
Regression and math
- Train model
src/linear_regression.c - Build normal equation
src/linear_regression.c - Matrix operations
src/matrix.c - Linear solver
src/matrix.c - Batch prediction
src/linear_regression.c - Regression metrics
src/linear_regression.c
Other components
- CSV dataset
Connections 16
- CSV dataset → Example runner: starts example
- Example runner → CSV reader: reads CSV
- CSV reader → Numeric parsing: parses values
- CSV reader → Dataset storage: creates dataset
- Example runner → Train/test split: splits dataset
- Train/test split → Dataset storage: creates subsets
- Example runner → Fit min-max scaling: fits on train
- Example runner → Transform features: transforms subsets
- Example runner → Train model: trains on train
- Train model → Build normal equation: builds equation
- Build normal equation → Matrix operations: uses matrix data
- Train model → Linear solver: solves system
- Linear solver → Matrix operations: uses matrix operations
- Example runner → Batch prediction: predicts test rows
- Example runner → Regression metrics: calculates metrics
- Example runner → Printed results: prints model and metrics