PCA Calculator (Principal Component Analysis)

PCA squeezes many related features into a few new ones, called principal components, while keeping as much of the information (variance) as possible. It is one of the most used tools in machine learning, deep learning and data science.

Paste or type your table, press Calculate, and get eigenvalues, explained variance, loadings, scores, a biplot and a step-by-step solution. Your data stays in this browser.

New to PCA? Read the plain-English guide — from basics to advanced, with ML, deep learning and edge-AI uses.

This tool answers one question: "I have lots of related measurements. Can a few summary numbers describe them almost as well?" Imagine photographing a 3D object: PCA finds the best camera angle, so a flat photo still shows most of the shape.

  1. 1. Put your data in the table

    One row per person, sample or reading. One column per measurement (feature). All values must be numbers. Click Example to see a filled table.

  2. 2. Or paste from Excel

    Use Paste / import to copy a table from Excel, Sheets or a CSV. The first row must be the column names.

  3. 3. Keep the defaults

    Standardize is on and the tool keeps enough components to explain 90% of the variance. Change this in More options once you understand it.

  4. 4. Press Calculate

    Nothing is calculated until you press the button.

  5. 5. Read the result

    Start with the 'In simple words' box, then the Components tab to see how much each new axis explains, and the Loadings tab to see what each axis means.

Rule of thumb to remember: keep enough components to explain about 90% of the variance. Every unfamiliar word is explained in the guide below the tool.

Data — every column must be a number

How to fill this table: each row is one person, sample or sensor reading, and each column is one measurement (feature). Unlike regression there is no "answer" column, because PCA only looks at how the features relate to each other. The pre-filled example has five student measurements.

Untick Include to leave a column out without deleting it. Nothing recalculates automatically, so press Calculate when you're ready. Your table is saved automatically in this browser.

#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

Fill in your data above and press Calculate to see results.

The plain-English guide to PCA

Read this once and you will understand most of what the tool shows you, from the very basics to the advanced checks, and where PCA fits in machine learning, deep learning and AI on small devices. Think of PCA as finding the best camera angle: a 3D object photographed from a clever angle still shows most of its shape in a flat picture. PCA does the same for data with many columns.

When, how and why to use this calculator

When: whenever you have many numeric columns that partly repeat each other (many sensors, survey questions, image or text features) and you want fewer, cleaner ones. How: fill the table with one row per sample and one column per feature, then press Calculate. Why: to visualize high-dimensional data, speed up models, remove redundancy and noise, detect unusual samples, and cut memory and compute on small devices.

Key words, explained simply

Start at Level 1. You only need the later levels once you want to check whether the analysis can be trusted.

Level 1 — The basics

Feature (variable)

One column of your data, such as height, temperature or sensor reading.

Dimension

The number of features. 20 features means a 20-dimensional dataset. More dimensions means more to store, compute and understand.

Variance

How spread out a feature is. A feature that never changes has zero variance and tells you nothing.

Correlation

How strongly two features move together, from −1 to +1. PCA works best when features are correlated, because then they repeat each other.

Principal component (PC)

A new axis built by mixing the original features. PC1 captures the most variation, PC2 the next most, and so on. Each PC is completely uncorrelated with the others.

Dimensionality reduction

Keeping only the first few PCs so that many features become a few, with a small loss of information.

Projection

Dropping each data point onto the new axes to get its new coordinates, like a shadow onto a wall.

Level 2 — Reading the results

Eigenvalue

The amount of variance along a component's direction. Bigger means that component matters more.

Eigenvector

The direction of a component, written as a list of weights, one per original feature.

Explained variance ratio

The share of the total information each component holds. All ratios add up to 100%.

Cumulative variance

The running total of the ratios. Used to decide how many components to keep.

Scree plot

A chart of eigenvalues from biggest to smallest. Look for the elbow where the curve flattens; components after it add little.

Loading

How strongly a feature is tied to a component. The tool shows the eigenvector weights and the easier-to-read feature-component correlations.

Score

A data point's new coordinate on a component. The scores table is your compressed dataset.

Biplot

One picture with the data points (scores) and the features (arrows). Arrows pointing the same way mean the features are positively correlated.

Level 3 — Checking the analysis

Standardization (z-score)

Rescaling each feature to mean 0 and standard deviation 1, so every feature gets an equal say.

Covariance vs correlation matrix

The covariance matrix keeps original units, so big-number features dominate. The correlation matrix is the same thing after standardizing. It is the safer default.

Kaiser criterion

A rule of thumb: keep components with eigenvalue above 1 (for standardized data), meaning they explain more than a single original feature would.

KMO

Kaiser-Meyer-Olkin measure of sampling adequacy from 0 to 1. Above 0.6 is acceptable and above 0.8 is good for PCA.

Bartlett's test

Tests whether your features are correlated at all. A significant result (p below 0.05) means there is structure worth summarising.

Reconstruction error

How much information is lost when you go back from k components to the original features. Rows with a large error do not fit the main pattern, so it doubles as an anomaly detector.

Level 4 — Advanced ideas

Orthogonality

The new axes are at right angles, which means the components are uncorrelated. That is why PCA helps with multicollinearity.

SVD connection

In practice PCA is computed with the singular value decomposition of the centered data matrix. The squared singular values, divided by (n − 1), are the eigenvalues.

Whitening

Rescaling every component to variance 1 after PCA, so the transformed features are uncorrelated and equally scaled. Common before some neural-network and ICA pipelines.

Fit on training data only

Compute the mean, scale and components from training data, then reuse them unchanged on test data or on a device. Refitting on test data leaks information.

Linear limits and kernel PCA

PCA only finds straight-line structure. For curved structure, use Kernel PCA, an autoencoder, t-SNE or UMAP.

Incremental and sparse PCA

Variants for data too big for memory (process in batches) or when you want each component to use only a few features.

Linear autoencoder

A neural network with a linear bottleneck, trained with squared error, learns the same subspace as PCA. That is the bridge between PCA and deep learning.

Worked example 1: PCA on two features by hand (basic)

Two standardized features, say hours studied and practice tests, have correlation 0.5, so their correlation matrix is [[1, 0.5], [0.5, 1]]. (Made-up numbers, for illustration only.)

  1. The eigenvalues of this matrix are 1 + 0.5 = 1.5 and 1 − 0.5 = 0.5. They add to 2, the total variance (one per feature).
  2. The eigenvector for 1.5 is (1, 1) / √2 ≈ (0.71, 0.71), so PC1 = 0.71 × z₁ + 0.71 × z₂: "both features high together", an overall effort axis.
  3. The eigenvector for 0.5 is (1, −1) / √2, so PC2 = 0.71 × z₁ − 0.71 × z₂: "one high, the other low".
  4. Shares: PC1 = 1.5 / 2 = 75%, PC2 = 25%. Keeping only PC1 halves the columns and keeps 75% of the information.
  5. A student with z₁ = 1 and z₂ = 1 gets PC1 = 0.71 + 0.71 ≈ 1.41 and PC2 = 0. Their whole story sits on PC1.

Worked example 2: how many components to keep? (intermediate)

Suppose 5 standardized features give eigenvalues 3.2, 1.1, 0.4, 0.2, 0.1 (total 5).

ComponentEigenvalue% of varianceCumulative %
PC13.264%64%
PC21.122%86%
PC30.48%94%
PC40.24%98%
PC50.12%100%
  • Kaiser rule (eigenvalue above 1): keeps PC1 and PC2, that is 2 components (86% of the variance).
  • 90% rule: the running total first passes 90% at PC3, so keep 3 components (94%).
  • Scree elbow: the curve drops steeply until PC2 or PC3 and then flattens, which points to 2 or 3.
  • The rules disagree a little, which is normal. Pick by your goal: 2 for a plot, 3 for a model, more if you cannot afford to lose information.

Worked example 3: reading loadings and reconstruction error (advanced)

  • Loadings: if PC1 has correlations +0.95 with Hours Studied, +0.92 with Practice Tests and +0.87 with Attendance, and about 0.1 with the others, then PC1 is an "effort" axis. A student with a high PC1 score works hard on all three at once.
  • Opposite signs: if PC2 is +0.85 for Sleep Hours and −0.83 for Screen Time, it contrasts sleep with screen time: a "lifestyle" axis. High PC2 means lots of sleep and little screen time.
  • Reconstruction error: after keeping 2 components, a row is rebuilt from just 2 numbers. If most rows rebuild within an error of about 0.5 (in standardized units) but one row has 6, that row does not follow the main pattern. It may be a data mistake, or a genuinely unusual case worth checking.
  • Suitability: KMO of 0.83 (good) and a Bartlett p-value below 0.001 mean the features are related enough for PCA to work well. KMO under 0.5 means most of the correlation is not shared, so PCA will not compress your data well.

What each tab shows

ResultThe big picture: how much information is kept, whether PCA suits your data (KMO, Bartlett), a plain-language summary and an on-device cost estimate.
ComponentsEvery component with its eigenvalue and variance share, plus the variance chart and the scree plot.
LoadingsWhat each component means: a heat-map of feature weights and correlations, and a biplot.
ScoresYour data in the new coordinates (the compressed table), the reconstruction error for each row, and CSV export.
LearnThe whole calculation with your numbers, step by step, plus Python and R code to repeat it.

A simple routine for reading your results

  1. KMO and Bartlett. Is the data suitable for PCA at all?
  2. Variance kept. Does the number of components kept explain enough (usually 80–95%)?
  3. Scree plot. Is there an elbow that agrees with your choice?
  4. Loadings and biplot. What does each kept component mean?
  5. Reconstruction errors. Any rows that do not fit?
  6. Use the scores. Export them and use them as the new, smaller feature table.

How PCA is used in machine learning

In machine learning PCA is mostly a preprocessing and exploration step. It does not predict anything by itself, but it makes the data easier for the models that do.

UseHow PCA helpsExample
Faster, simpler modelsFewer inputs means faster training and prediction, especially for k-nearest neighbours, SVM and k-means, which slow down with many dimensions.Reduce 300 features to 20 before clustering customers.
Fixing overlapping featuresComponents are uncorrelated, so they remove multicollinearity. Regression on components is called principal component regression (PCR).Many correlated economic indicators predicting one outcome.
VisualizationPlot PC1 against PC2 to see clusters and outliers in data with dozens of columns.Show whether patients or products form groups.
Noise reductionSmall components are mostly noise. Keep the big ones and reconstruct to get a cleaner signal.Denoise sensor readings or images.
Anomaly detectionA sample that rebuilds badly from a few components does not follow the normal pattern.Flag a faulty machine or a fraudulent transaction.
Feature engineeringComponents can act as new, compact features whose meaning you can read from the loadings.An 'effort' score and a 'lifestyle' score from many survey items.

The safe workflow

  1. Split your data into training and test sets first.
  2. Standardize using the training data's mean and standard deviation.
  3. Fit PCA on the training data only, and choose the number of components (by variance, or by cross-validation).
  4. Transform the test data with the same mean, scale and components. Never refit on the test set, that leaks information.
  5. Train your model on the scores and compare it with a model on the original features.
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import PCA
from sklearn.linear_model import LogisticRegression

model = make_pipeline(StandardScaler(), PCA(n_components=0.90), LogisticRegression())
model.fit(X_train, y_train)      # scaler and PCA are fitted on training data only
print(model.score(X_test, y_test))

Limits to remember

  • PCA is unsupervised: it keeps high-variance directions, which are not always the ones that predict your target.
  • It only captures straight-line structure. Curved patterns need Kernel PCA, an autoencoder, t-SNE or UMAP.
  • It needs numeric data. Do not run it on raw category codes.
  • Components are mixtures, so they are harder to explain to non-technical people than the original features.

How PCA is used in deep learning

Deep networks learn their own features, so PCA plays a supporting role. It is a strong, cheap baseline, and the ideas behind it appear all over deep learning.

Compressing embeddings

Text and image models output vectors with hundreds or thousands of numbers (for example 768). PCA can shrink them to 128 or 256 for cheaper storage and faster similarity search, at a small cost in accuracy.

Linear autoencoder = PCA

A neural network with a straight-line bottleneck trained to rebuild its input learns the same subspace as PCA. Real autoencoders add non-linear layers to go beyond it.

Preprocessing and whitening

Standardizing or whitening inputs with PCA can make training of small networks steadier and faster, especially on tabular and sensor data.

Understanding what a network learned

PCA of hidden-layer activations shows how many dimensions a layer really uses. The same low-rank thinking sits behind methods such as LoRA, which adds small low-rank updates to big models.

Visualizing embeddings

The common recipe is PCA down to about 50 dimensions first, then t-SNE or UMAP down to 2, which is faster and less noisy than going straight to 2.

Sizing your model

A tiny first layer needs fewer weights when it reads k components instead of p features. Try the NN Parameter & FLOPs Counter on this site to see the savings.

PCA in Agentic AI on edge devices

An edge device is a small computer close to the real world: a drone, robot, wearable, phone, camera or factory sensor. An AI agent on such a device repeatedly senses, understands, decides and acts, with very little memory, power and network bandwidth. PCA is a cheap, predictable way to keep that loop small.

1. Sense

Sensors give p raw numbers (IMU, vibration, audio features, camera features).

2. Compress

PCA turns p numbers into k. One small matrix multiplication, computed offline.

3. Decide

A tiny model, rule set or small on-device language model reads the k numbers and picks an action.

4. Act

Motor, alert or message. Meanwhile the reconstruction error tells the agent when input looks unusual.

Where PCA helps a device-side agent

Need on the deviceWhat PCA doesExample
Small input for TinyMLTurns many correlated channels into a few, so the first layer of the on-device model needs fewer weights and multiply-adds.20 vibration features → 4 components for a motor-health classifier on a microcontroller.
Compact agent stateGives the policy or planner a short, uncorrelated state vector instead of a long raw one.A robot's many joint and IMU readings → 6 numbers for its controller.
Self-monitoring and safetyReconstruction error shows when a reading does not fit normal patterns, so the agent can slow down, use a safe mode or ask a bigger cloud model.A drone notices its sensors behave unlike anything seen in training.
Memory and retrieval on deviceCompress embeddings of past events or documents, so more fit in RAM or flash and search is faster.768-number embeddings → 128 for an on-device knowledge store.
Bandwidth and batterySend k numbers instead of p over BLE, LoRa or cellular, saving energy.A wearable uploads 5 numbers per reading instead of 40.
Drift monitoringTrack how the variance along each component changes over time. A shift tells you the environment or the sensor has changed and the model needs updating.Sensor ageing or a new operating environment.

How to deploy it on a device

  1. Fit offline on representative training data, on a computer (this calculator or scikit-learn).
  2. Export three things: the mean vector, the scale vector (if standardizing) and the p × k component matrix.
  3. Quantize the matrix to INT8 or fixed-point if the device needs it, and re-check accuracy afterwards.
  4. On the device, per reading: subtract the mean, divide by the scale, multiply by the matrix. That is p × k multiply-adds, which the Result tab estimates for you.
  5. Feed the k scores to the on-device model, and optionally compute the reconstruction error as a health check.

Limits on the edge

  • PCA is linear. For strongly curved sensor patterns a small autoencoder may compress better.
  • The device must use exactly the same mean, scale and components as training; otherwise results are meaningless.
  • Refit when sensors, environment or behaviour drift. Otherwise the components describe yesterday's world.
  • Rounding to INT8 changes results slightly. Test with the quantized matrix, not just the float one.

If something looks wrong, what to try

What you seeWhat it meansWhat to try
Bartlett p is above 0.05, or KMO is below 0.5Your features are barely correlated, so there is little to compress.PCA is the wrong tool here. Try other features, or keep the original ones.
PC1 explains only 20–30% and the scree plot is flatThere is no dominant pattern; information is spread evenly.You would need many components. Consider whether reduction is worth it.
One feature dominates PC1 and has a huge scaleThe covariance matrix is being driven by the units, not by structure.Switch to 'Correlation matrix' (standardize).
A row has a very large reconstruction errorThat row does not follow the main pattern (possible outlier, fault or data error).Check the row. Remove it or keep it as an anomaly signal.
An error says a column has zero varianceThat column has the same value in every row.Untick Include for that column.
Loadings are hard to interpretThe components mix many features, which is normal for PCA.Read only the loadings above about 0.5 in size, and look at the biplot.

Common beginner mistakes

  • Skipping standardization when features use different units.
  • Reading "variance explained" as "importance for predicting my target". PCA never sees the target.
  • Fitting PCA on all the data before splitting into train and test.
  • Keeping too few components, or keeping all of them and calling it "reduced".
  • Over-interpreting a component's name. The maths gives directions; the meaning is your judgement.
  • Feeding in ID columns or category codes as if they were measurements.

How this calculator works

The calculator centres (and optionally standardizes) your columns, builds the covariance or correlation matrix, and finds its eigenvalues and eigenvectors with the Jacobi rotation method. Components are sorted by eigenvalue; scores are the data projected onto the eigenvectors; loadings are the eigenvectors and the feature-component correlations. Eigenvector signs are set so the largest weight is positive, which keeps results stable between runs.

Bartlett's test of sphericity uses the determinant of the correlation matrix, and KMO compares ordinary and partial correlations. Nothing is calculated until you press Calculate.

Common questions