Six joints → X, Y, Z · 22I-2327

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.

Python 3 scikit-learn LinearRegression Jupyter Notebook License: MIT
3OLS models, one per axis
3,998Training rows
1,002Test rows
0.9787Test R² for Z, the closest axis

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.linear_model.LinearRegression 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/README.md.

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/multiple_linear_regression.ipynb.

What's Inside

The notebook, the runnable script, the result files, and the website.

Notebook

multiple_linear_regression.ipynb

The cleaned walkthrough: load the two tables, print statistics and correlations, fit the three models, and plot the charts.

Script

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

data/README.md

File names, row counts, and where to get the two Excel files. The spreadsheets themselves are gitignored.

Results

results/

metrics.csv, equations.txt, predictions_head.csv, and the figures from a fresh run that matches the notebook.

Screenshots

screenshots/

24 images, all 1600×1000, covering the data, the fit, the charts and this website.

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

ColumnRoleTraining values I actually saw
Rev1Revolute jointOnly two values: −12 (3,776 rows) and −4 (222 rows)
Rev2Revolute jointSix values: −20, −12, −4, 4, 12, 20
Rev3Revolute jointThe same six values as Rev2
Rev4Revolute jointThe same six values as Rev2
Rev5Revolute jointSix values: 70, 78, 86, 94, 102, 110
PrisPrismatic jointOnly three values: 0 (1,332 rows), 7 (1,333) and 14 (1,333)
X, Y, ZEnd-effector positionContinuous targets

Training-set summary

ColumnMeanStdMinMax
Rev1−11.55581.8323−12−4
Rev2−0.550313.8666−2020
Rev3−0.318213.6105−2020
Rev4−0.010013.6682−2020
Rev589.994013.663570110
Pris7.00185.7158014
X22.828310.5527−1.937854.2720
Y−4.379812.5314−34.833829.8622
Z35.240414.9007−0.518368.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.

1

Load the two tables

Read traindata1.xlsx and testdata1.xlsx. If either file is missing, the script stops and points at data/README.md.

2

Look at the data

Print the shapes, the training statistics and the joint–pose correlations.

3

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².

4

Write the report

Print the equations and write results/metrics.csv, results/equations.txt and results/predictions_head.csv.

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

CoordMSERMSER²
X11.29293.36050.8729
Y14.18103.76580.8822
Z4.31252.07670.9787

Training correlations of the joints with X, Y and Z

Jointcorr(X)corr(Y)corr(Z)
Rev10.2610.1610.187
Rev2−0.153−0.533−0.024
Rev3−0.7600.099−0.689
Rev4−0.204−0.8070.000
Rev5−0.005−0.001−0.711
Pris−0.4720.0860.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.

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.

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/README.md.

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/multiple_linear_regression.ipynb.

License

The code in this repository is under the MIT License, Copyright (c) 2026 Mohammad Rohaan.