Multiple linear regression for end-effector position
I fitted three ordinary-least-squares models that map a manipulator’s six joint readings to Cartesian X, Y and Z. On the 1,002-row test set, Z comes out closest, with R² 0.9787. A re-run of the same fit matches the original notebook.
Live Links
The repository, this page, and a ZIP of the current main branch.
Overview
Forward kinematics from joint angles to pose is trigonometric. This project asks how far a purely linear model can go as a simple stand-in.
I fitted three ordinary-least-squares models that map a manipulator’s six joint readings — five revolute joints, Rev1 through Rev5, and one prismatic joint, Pris — to the Cartesian end-effector coordinates X, Y and Z. Each axis gets its own equation:
coord = b0 + b1*Rev1 + b2*Rev2 + b3*Rev3 + b4*Rev4 + b5*Rev5 + b6*Pris
Each axis is a separate sklearn. fit (ordinary least squares, intercept on, no feature scaling). There is no shared multi-output estimator. The Excel files already come as a train/test split — 3,998 and 1,002 rows, nine columns — so I did not call train_test_split. They are not stored in this repository; names and links are in data/
I re-ran the fit from src/fit_mlr.py. The printed test metrics (four decimal places) and the first ten predictions match the original notebook, which is in notebooks/
What's Inside
The notebook, the runnable script, the result files, and the website.
multiple_linear_regression.ipynb
The cleaned walkthrough: load the two tables, print statistics and correlations, fit the three models, and plot the charts.
src/fit_mlr.py
The same ordinary-least-squares fit, runnable from the command line. It prints the report and writes the files under results/.
data/README.md
File names, row counts, and where to get the two Excel files. The spreadsheets themselves are gitignored.
results/
metrics.csv, equations.txt, predictions_head.csv, and the figures from a fresh run that matches the notebook.
screenshots/
24 images, all 1600×1000, covering the data, the fit, the charts and this website.
index.html
This page. Raspberry and gold, with a dark theme and a light theme, built to be read on a phone as well as a desktop.
The Data
Both files have the same nine columns. The six joint columns are integers; X, Y and Z are floating-point. Training set 3,998 rows, test set 1,002 rows. No missing cells.
Columns
| Column | Role | Training values I actually saw |
|---|---|---|
Rev1 | Revolute joint | Only two values: −12 (3,776 rows) and −4 (222 rows) |
Rev2 | Revolute joint | Six values: −20, −12, −4, 4, 12, 20 |
Rev3 | Revolute joint | The same six values as Rev2 |
Rev4 | Revolute joint | The same six values as Rev2 |
Rev5 | Revolute joint | Six values: 70, 78, 86, 94, 102, 110 |
Pris | Prismatic joint | Only three values: 0 (1,332 rows), 7 (1,333) and 14 (1,333) |
X, Y, Z | End-effector position | Continuous targets |
Training-set summary
| Column | Mean | Std | Min | Max |
|---|---|---|---|---|
| Rev1 | −11.5558 | 1.8323 | −12 | −4 |
| Rev2 | −0.5503 | 13.8666 | −20 | 20 |
| Rev3 | −0.3182 | 13.6105 | −20 | 20 |
| Rev4 | −0.0100 | 13.6682 | −20 | 20 |
| Rev5 | 89.9940 | 13.6635 | 70 | 110 |
| Pris | 7.0018 | 5.7158 | 0 | 14 |
| X | 22.8283 | 10.5527 | −1.9378 | 54.2720 |
| Y | −4.3798 | 12.5314 | −34.8338 | 29.8622 |
| Z | 35.2404 | 14.9007 | −0.5183 | 68.1762 |
Rev1 barely moves, so its coefficient is weakly identified. Every one of the 1,002 test rows has Rev1 = -4; the test set never uses the −12 value that dominates the training file. Pris is almost evenly split in both files (the test set has 334 rows of each value). On the training set, Y averages −4.38; on the test set it averages 6.74. X and Z stay closer across the split.
How the Models Are Fitted
The work is in src/fit_mlr.py and in the notebook. The steps are the same in both.
Load the two tables
Read traindata1.xlsx and testdata1.xlsx. If either file is missing, the script stops and points at data/
Look at the data
Print the shapes, the training statistics and the joint–pose correlations.
Fit one model per axis
For X, Y and Z, fit LinearRegression() on the six joints, predict on the test set, and compute MSE, RMSE and R².
Write the report
Print the equations and write results/
The sklearn estimator is used with its defaults for this model: the intercept is fitted, and the joints are not standardised. I did not add regularisation, polynomial terms, or a second model family. The point of the exercise is this linear baseline.
Test Results
Test set, 1,002 rows. The four-decimal figures are exactly what the original notebook printed, and what a fresh run of src/fit_mlr.py prints. Z is the closest of the three.
Test metrics
| Coord | MSE | RMSE | R² |
|---|---|---|---|
| X | 11.2929 | 3.3605 | 0.8729 |
| Y | 14.1810 | 3.7658 | 0.8822 |
| Z | 4.3125 | 2.0767 | 0.9787 |
Training correlations of the joints with X, Y and Z
| Joint | corr(X) | corr(Y) | corr(Z) |
|---|---|---|---|
| Rev1 | 0.261 | 0.161 | 0.187 |
| Rev2 | −0.153 | −0.533 | −0.024 |
| Rev3 | −0.760 | 0.099 | −0.689 |
| Rev4 | −0.204 | −0.807 | 0.000 |
| Rev5 | −0.005 | −0.001 | −0.711 |
| Pris | −0.472 | 0.086 | 0.002 |
The strongest pairs are Rev4 with Y (−0.807), Rev3 with X (−0.760), Rev5 with Z (−0.711) and Rev3 with Z (−0.689). The residual plots still show structure, which is what I would expect from a linear model of a trigonometric relationship: the fit is a useful rough surrogate, especially for Z, but it is not a substitute for forward kinematics.
Learned equations
X = 29.7374 + 0.0565×Rev1 - 0.0951×Rev2 - 0.5845×Rev3 - 0.1582×Rev4 - 0.0043×Rev5 - 0.8729×Pris
Y = -5.6235 + 0.0268×Rev1 - 0.4833×Rev2 + 0.1079×Rev3 - 0.7391×Rev4 + 0.0000×Rev5 + 0.1874×Pris
Z = 103.9744 - 0.0730×Rev1 - 0.0043×Rev2 - 0.7571×Rev3 - 0.0004×Rev4 - 0.7762×Rev5 + 0.0053×Pris
Y’s Rev5 coefficient is about 0.0000306888, so it prints as 0.0000. The raw numbers are in results/.
Training and Test Files
The two Excel files are not in this repository. They never were, and they are listed in .gitignore. Place them in data/ under these exact names.
| File | Rows | Direct link |
|---|---|---|
traindata1.xlsx | 3,998 | https://github.com/rohaan2802/Machine_Learning/raw/main/Lecture%20%2311/traindata1.xlsx |
testdata1.xlsx | 1,002 | https://github.com/rohaan2802/Machine_Learning/raw/main/Lecture%20%2311/testdata1.xlsx |
I used the copies from Lecture #11 of my Machine_Learning repository. A re-run on those files produced the same shapes, the same printed statistics, the same first ten predictions and the same four-decimal test metrics as the original notebook. There is no GitHub Release on this repo.
Screenshots
24 images, every one 1600×1000. Click one to open it at full size.
No matching screenshots.
Folder Structure
Linear_Regression/
├── notebooks/multiple_linear_regression.ipynb
├── src/fit_mlr.py
├── data/README.md place the two Excel files here (gitignored)
├── results/ metrics, equations, first ten predictions
├── screenshots/ 24 images, 1600×1000
├── assets/ website CSS, JS and favicon
├── index.html
├── requirements.txt
├── LICENSE
└── README.md
How to run
Python 3, with the packages in requirements.txt. Put the two Excel files in data/ first; names and links are in data/
Linux / macOS
git clone https://github.com/rohaan2802/Linear_Regression.git
cd Linear_Regression
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python3 src/fit_mlr.py
Windows
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
python src\fit_mlr.py
That prints the training statistics, the correlations, the coefficients, the test metrics and the three equations, and writes files under results/. Optional flags: --data-dir and --results-dir. The same steps are in notebooks/
License
The code in this repository is under the MIT License, Copyright (c) 2026 Mohammad Rohaan.