All articles →

100 Exercises / linear algebra / Linear algebra 100 Exercises

Introduction to Matrix Decomposition in Manufacturing | Python Examples of SVD, PCA, NMF, and Matrix Completion

Apply LU, Cholesky, QR, SVD, PCA, NMF, tensor and CUR decompositions in Python. Compare compression errors and estimates of missing quality data.

Quality records combine products, machines and inspection features. Using a fictional precision-parts factory, we examine matrix decompositions that solve linear systems, compress quality variation and estimate missing measurements.

We compare computational requirements, reconstruction errors and the assumptions needed for imputation, then choose a decomposition for each task. All example data is generated in Python.

About this article This article adapts Jupyter Notebooks used in corporate training by Surikobo or its representative, Hiroshi Wayama, with permission from the participating companies.
All data listed is fictional and has no relation whatsoever to real companies, factories, or figures.

Introduction: Practical Challenges in Manufacturing Covered in This Article

Consider a factory that processes 12 types with 8 machines, inspecting six characteristics: dimensions, roundness, roughness, hardness, vibration, and temperature. It is not possible to measure all combinations every time, and the measurement matrix may be incomplete. Additionally, the characteristics correlate with each other through common factors such as processing load and thermal effects.

What is needed in this situation is not simply to calculate the average value, but to solve calibration calculations stably, extract the main causes of variation, and estimate unmeasured values while managing compression errors. For example, LU factors can be reused for new right-hand sides, while SVD lets us compare retained rank with reconstruction error.

Common situations on site

  • Using the same coefficient matrix, different measurements are solved multiple times for each day
  • Inspection characteristics increase, and it’s unclear which metrics should be prioritized in meetings.
  • I want to visualize multi-variety data, but I can’t compare it in 6D.
  • Skipped inspections and communication failures leave missing values; column-mean imputation can obscure differences between products.
  • Although the compression model is highly accurate, the site cannot explain the latent factors.

Why is this issue so difficult to judge?

There are multiple options for matrix decomposition, each with different premises and purposes. Cholesky decomposition is strong for symmetric positive definite matrices, QR decomposition is useful for stable least-squares calculations, and SVD reveals rank and the distribution of variation but requires a large computational load. PCA describes centered fluctuations, while NMF describes non-negative additive patterns. For matrix completion, a low-rank structure is not enough: missing values concentrated in certain products can make estimates unreliable.

Exercises in this article

No.ThemeJudgment in the manufacturing industry
061LU DecompositionCan multiple calibration calculations be streamlined with the same equipment model?
062Cholesky DecompositionCan covariance and normal equations be solved with a small computational complexity?
063QR DecompositionCan calibration regression with correlated predictors be solved reliably?
064SVDWhat are the independent variation directions and effective ranks of the quality matrix?
065Low-rank approximationHow much information can be stored with a few factors?
066PCACan varieties be compared based on key quality fluctuation axes?
067NMFCan nonnegative quality data be represented by additive patterns?
068Tensor DecompositionCan product × machine × feature structure be retained during compression?
069CUR decompositionCan approximation be explained using actual representative varieties and characteristics?
070matrix completionHow far can unmeasured values be compensated from low-rank structures?

Preparing the Python environment

Perform matrix calculations with NumPy, tables with pandas, and visualization with Matplotlib. Avoid relying on SciPy or machine learning libraries, and make the breakdown a short implementation that allows you to track the contents. Fix the seed of the random number generator and separate the rounding of the display from the accuracy of internal calculations.

Setup code: Preparing the Python environment (click to expand)
[IN: 1]
import sys
import numpy as np
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
from IPython.display import display

np.set_printoptions(precision=4, suppress=True)
rng = np.random.default_rng(20260712)
print(
    f"Python {sys.version.split()[0]} / NumPy {np.__version__} / pandas {pd.__version__} / Matplotlib {matplotlib.__version__}"
)
[OUT: 1]
Python 3.14.4 / NumPy 2.5.1 / pandas 3.0.3 / Matplotlib 3.11.0

Creation of Fictional Data

We produce tensors with 12 varieties, 8 equipment, and 6 inspection characteristics. Behind them are three latent factors: ‘processing load,’ ‘thermal effect,’ and ‘surface condition,’ and the observed values are set to include small measurement noise. The quality matrix XX for analysis is a table of variety× characteristics averaging equipment directions, and each column is standardized.

Setup code: Creation of Fictional Data (click to expand)
[IN: 2]
products = [f"P{i:02d}" for i in range(1, 13)]
machines = [f"M{i:02d}" for i in range(1, 9)]
features = [
    "Dimension",
    "Roundness",
    "Roughness",
    "Hardness",
    "Vibration",
    "Temperature",
]

product_factor = rng.normal(size=(12, 3))
machine_factor = rng.normal(scale=0.45, size=(8, 3))
feature_loading = np.array(
    [
        [0.90, 0.15, 0.10],
        [0.75, 0.10, 0.30],
        [0.15, 0.05, 0.95],
        [0.05, 0.90, 0.10],
        [0.55, 0.25, 0.45],
        [0.10, 0.95, 0.05],
    ]
)
quality_tensor = (
    np.einsum("pr,fr->pf", product_factor, feature_loading)[:, None, :]
    + np.einsum("mr,fr->mf", machine_factor, feature_loading)[None, :, :]
)
quality_tensor += rng.normal(scale=0.10, size=quality_tensor.shape)
raw_matrix = quality_tensor.mean(axis=1)
X = (raw_matrix - raw_matrix.mean(axis=0)) / raw_matrix.std(axis=0, ddof=1)
quality_df = pd.DataFrame(X, index=products, columns=features)
display(quality_df.round(2))

fig, ax = plt.subplots(figsize=(9, 4))
im = ax.imshow(X, cmap="coolwarm", aspect="auto", vmin=-2.5, vmax=2.5)
ax.set_title("Standardized product-by-quality matrix")
ax.set_xlabel("Quality feature")
ax.set_ylabel("Product")
ax.set_xticks(range(len(features)), features, rotation=30, ha="right")
ax.set_yticks(range(len(products)), products)
ax.grid(False)
fig.colorbar(im, ax=ax, label="Standardized value")
fig.tight_layout()
plt.show()
[OUT: 2]
Dimension Roundness Roughness Hardness Vibration Temperature
P01 0.64 0.70 0.64 0.78 1.07 0.72
P02 0.17 0.29 0.57 0.42 0.47 0.39
P03 -0.54 0.09 2.07 0.67 0.87 0.53
P04 0.44 0.54 0.31 0.19 0.49 0.19
P05 -1.49 -1.41 0.02 0.11 -1.05 -0.03
P06 -0.03 -0.56 -2.27 -0.81 -1.34 -0.73
P07 1.08 1.21 0.13 -1.40 0.43 -1.33
P08 -0.18 -0.51 -0.72 1.52 -0.05 1.61
P09 1.70 1.62 -0.02 -0.55 0.93 -0.50
P10 -1.79 -1.75 -0.24 -1.45 -1.94 -1.53
P11 -0.53 -0.58 -0.20 -0.81 -0.63 -0.74
P12 0.54 0.36 -0.30 1.32 0.75 1.41

Creation of Fictional Data: computed results

No.061: LU Decomposition

Meaning in Practice

Calibration problems often reuse the same matrix in Ax=bA\mathbf{x}=\mathbf{b} while daily observations change the right-hand side. A reusable LU factorization supports repeated solves by forward and back substitution.

Approach to Analysis and Modeling

Factor A=LUA=LU, then solve Ly=bL\mathbf{y}=\mathbf{b} followed by Ux=yU\mathbf{x}=\mathbf{y}. General implementations use row pivoting, written here as PA=LUPA=LU, to handle zero or small pivots. The strictly diagonally dominant example illustrates the factorization without row exchanges. NumPy solve is used for the two triangular equations; a production implementation would use triangular solvers to exploit the factors efficiently.

Check with Python

[IN: 3]
def lu_decompose(A):
    A = A.astype(float)
    n = len(A)
    L = np.eye(n)
    U = np.zeros_like(A)
    for i in range(n):
        U[i, i:] = A[i, i:] - L[i, :i] @ U[:i, i:]
        if abs(U[i, i]) < 1e-12:
            raise ValueError("Pivoting is required")
        L[i + 1 :, i] = (A[i + 1 :, i] - L[i + 1 :, :i] @ U[:i, i]) / U[i, i]
    return L, U


A_cal = np.array([[4.0, 1.0, 0.5], [1.0, 3.0, 0.4], [0.5, 0.4, 2.5]])
B_cal = np.array([[12.0, 10.0], [8.0, 9.0], [6.0, 7.0]])  # two operating days
L, U = lu_decompose(A_cal)
Y = np.linalg.solve(L, B_cal)
coef_lu = np.linalg.solve(U, Y)
display(pd.DataFrame(L).round(3))
display(pd.DataFrame(U).round(3))
display(
    pd.DataFrame(
        coef_lu, index=["Feed", "Speed", "Cooling"], columns=["Day A", "Day B"]
    ).round(3)
)
print(f"reconstruction error = {np.linalg.norm(A_cal - L @ U):.2e}")
print(f"maximum residual = {np.max(np.abs(A_cal @ coef_lu - B_cal)):.2e}")
[OUT: 3]
0 1 2
0 1.000 0.0 0.0
1 0.250 1.0 0.0
2 0.125 0.1 1.0
0 1 2
0 4.0 1.00 0.500
1 0.0 2.75 0.275
2 0.0 0.00 2.410
Day A Day B
Feed 2.379 1.697
Speed 1.652 2.152
Cooling 1.660 2.116
reconstruction error = 0.00e+00
maximum residual = 1.78e-15

Reading the results

The reconstruction error and residual are at the rounding error level, and the right side for two days was solved simultaneously from the same decomposition. It is suitable for daily calibration that reuses coefficient matrices. However, in actual operation, instead of custom functions, a verified library with pivot selection is used, and the condition number is also monitored.

No.062: Cholesky Decomposition

Meaning in Practice

Covariance matrices of quality characteristics and regularized coefficient matrices of least squares tend to be symmetric positive definites, and using Cholesky decomposition allows solving with less computational complexity and memory than general decomposition.

Approach to Analysis and Modeling

A real symmetric positive definite matrix has a unique factorization A=LLTA=LL^{\mathsf T} when LL is lower triangular with positive diagonal entries. Positive definiteness means zTAz>0z^{\mathsf T}Az>0 for every nonzero zz. Symmetry alone is insufficient: the smallest eigenvalue must be positive.

Check with Python

[IN: 4]
cov = np.cov(X, rowvar=False) + 0.05 * np.eye(X.shape[1])
chol = np.linalg.cholesky(cov)
target = np.ones(len(features))
weights = np.linalg.solve(chol.T, np.linalg.solve(chol, target))
weights /= target @ weights
chol_table = pd.DataFrame({"Feature": features, "Portfolio weight": weights})
display(chol_table.round(3))
print(f"minimum eigenvalue = {np.linalg.eigvalsh(cov).min():.4f}")
print(f"factorization error = {np.linalg.norm(cov - chol @ chol.T):.2e}")
[OUT: 4]
Feature Portfolio weight
0 Dimension 0.791
1 Roundness 0.171
2 Roughness 0.653
3 Hardness 0.244
4 Vibration -1.139
5 Temperature 0.280
minimum eigenvalue = 0.0507
factorization error = 3.85e-16

Reading the results

Since the minimum eigenvalue is positive and the decomposition error is sufficiently small, it satisfies the assumption that it is a positive definite value. The weights here are examples of synthetic quality indicators that consider correlations, but whether negative weights are permissible in business operations is a separate constraint. We distinguish between what can be solved numerically and what is reasonable as a KPI.

No.063: QR Decomposition

Meaning in Practice

When estimating dimensional deviations from strongly correlated explanatory variables such as temperature, speed, and load, the normal equation tends to amplify errors. QR decomposition directly decomposes the design matrix and solves calibration regression relatively stably.

Approach to Analysis and Modeling

For a full-column-rank design matrix, reduced QR gives D=QRD=QR, QTQ=IQ^{\mathsf T}Q=I and an invertible upper-triangular RR. Solve Rβ=QTyR\beta=Q^{\mathsf T}y for the least-squares coefficients. In the 2-norm, κ2(DTD)=κ2(D)2\kappa_2(D^{\mathsf T}D)=\kappa_2(D)^2, which explains why forming normal equations can worsen rounding errors.

Check with Python

[IN: 5]
n = 80
temperature = rng.normal(180, 4, n)
load = 0.85 * temperature + rng.normal(0, 2, n)
speed = rng.normal(1200, 60, n)
D = np.column_stack(
    [np.ones(n), temperature - 180, load - load.mean(), (speed - 1200) / 100]
)
y = 0.20 + 0.035 * D[:, 1] - 0.020 * D[:, 2] + 0.08 * D[:, 3] + rng.normal(0, 0.08, n)
Q, R = np.linalg.qr(D, mode="reduced")
beta_qr = np.linalg.solve(R, Q.T @ y)
beta_lstsq = np.linalg.lstsq(D, y, rcond=None)[0]
display(
    pd.DataFrame(
        {
            "Term": ["Intercept", "Temperature", "Load", "Speed/100"],
            "QR": beta_qr,
            "lstsq": beta_lstsq,
        }
    ).round(4)
)
print(f"orthogonality error = {np.linalg.norm(Q.T @ Q - np.eye(Q.shape[1])):.2e}")
print(
    f"condition(D)={np.linalg.cond(D):.1f}, condition(D.T@D)={np.linalg.cond(D.T @ D):.1f}"
)
[OUT: 5]
Term QR lstsq
0 Intercept 0.1934 0.1934
1 Temperature 0.0334 0.0334
2 Load -0.0203 -0.0203
3 Speed/100 0.0829 0.0829
orthogonality error = 6.77e-16
condition(D)=8.9, condition(D.T@D)=78.4

Reading the results

The least squares solutions of QR and NumPy coincide. Since the condition number for a normal equation is greater than the design matrix, we understand why we do not explicitly create a normal equation under strongly correlated conditions. However, interpreting coefficients requires separate experimental planning and confounding management.

No.064: SVD (Singular Value Decomposition)

Meaning in Practice

SVD divides the quality matrix into “variety-side patterns,” “importance,” and “characteristic patterns.” By observing the attenuation of singular values, you can diagnose how many independent factors actually move the six characteristics.

Approach to Analysis and Modeling

Any m×nm\times n matrix can be decomposed with X=UΣVTX=U\Sigma V^{\mathsf T}. The singular value σi\sigma_i is non-negative and arranged in descending order, and its square represents the energy of each component. Small singular values indicate noise direction and redundancy, but important minor fluctuations in the process should not be automatically considered unnecessary.

Check with Python

[IN: 6]
U, s, Vt = np.linalg.svd(X, full_matrices=False)
sv_df = pd.DataFrame(
    {
        "Component": np.arange(1, len(s) + 1),
        "Singular value": s,
        "Energy ratio": s**2 / np.sum(s**2),
    }
)
display(sv_df.round(4))
fig, ax = plt.subplots(figsize=(7, 3.5))
ax.plot(sv_df["Component"], sv_df["Singular value"], marker="o")
ax.set_title("Singular values of the quality matrix")
ax.set_xlabel("Component")
ax.set_ylabel("Singular value")
ax.grid(True, alpha=0.3)
fig.tight_layout()
plt.show()
print(f"reconstruction error = {np.linalg.norm(X - U @ np.diag(s) @ Vt):.2e}")
[OUT: 6]
Component Singular value Energy ratio
0 1 6.0129 0.5478
1 2 4.3933 0.2924
2 3 3.2389 0.1589
3 4 0.1811 0.0005
4 5 0.1097 0.0002
5 6 0.0889 0.0001

No.064: SVD (Singular Value Decomposition): computed results

reconstruction error = 1.07e-14

Reading the results

The singular values decrease rapidly, reflecting the few factors used to generate the data. Choose retained components using reconstruction error, sensitivity to anomalies and interpretability, rather than the apparent elbow alone.

No.065: Low-Rank Approximation

Meaning in Practice

With quality dashboards and edge terminals, you may not retain all data as is, but rather approximate only the main factors. Low-rank approximation quantifies the trade-off between information volume and storage/computation costs.

Approach to Analysis and Modeling

The truncated SVD Xk=UkΣkVkTX_k=U_k\Sigma_kV_k^{\mathsf T} minimizes Frobenius error among matrices of rank at most kk. Compare its relative error and cumulative squared-singular-value ratio when selecting kk.

Check with Python

[IN: 7]
records = []
# Compare each retained rank with the original standardized matrix.
for k in range(1, len(s) + 1):
    Xk = U[:, :k] @ np.diag(s[:k]) @ Vt[:k]
    records.append(
        [
            k,
            np.linalg.norm(X - Xk) / np.linalg.norm(X),
            np.sum(s[:k] ** 2) / np.sum(s**2),
        ]
    )
rank_df = pd.DataFrame(records, columns=["Rank", "Relative error", "Cumulative energy"])
display(rank_df.round(4))
fig, ax = plt.subplots(figsize=(7, 3.5))
ax.plot(rank_df["Rank"], rank_df["Relative error"], marker="o", label="relative error")
ax.plot(
    rank_df["Rank"],
    1 - rank_df["Cumulative energy"],
    marker="s",
    label="unexplained energy",
)
ax.set_title("Accuracy versus retained rank")
ax.set_xlabel("Retained rank")
ax.set_ylabel("Ratio")
ax.grid(True, alpha=0.3)
ax.legend()
fig.tight_layout()
plt.show()
[OUT: 7]
Rank Relative error Cumulative energy
0 1 0.6725 0.5478
1 2 0.3997 0.8403
2 3 0.0283 0.9992
3 4 0.0174 0.9997
4 5 0.0109 0.9999
5 6 0.0000 1.0000

No.065: Low-Rank Approximation: computed results

Reading the results

Reconstruction error decreases as rank increases, with smaller gains after the main components are retained. Local specification violations may still appear in the residual, so inspect residuals alongside the compressed representation.

No.066: PCA (Principal Component Analysis)

Meaning in Practice

PCA consolidates correlated quality characteristics into a few synthetic axes and compares similar variations or off-topic varieties in two dimensions. This serves as the gateway to visualizing “which varieties are comprehensively different” during quality meetings.

Approach to Analysis and Modeling

For centered XX, the SVD gives scores Z=UΣ=XVZ=U\Sigma=XV and direction coefficients VV. This article calls those coefficients loadings; some conventions reserve that term for correlations with the components. Standardization aligns units, but does not encode business importance. Component signs are arbitrary.

Check with Python

[IN: 8]
scores = U[:, :2] * s[:2]
loadings = Vt[:2].T
display(pd.DataFrame(loadings, index=features, columns=["PC1", "PC2"]).round(3))
fig, ax = plt.subplots(figsize=(7, 5))
ax.scatter(scores[:, 0], scores[:, 1], color="#2878B5")
for i, name in enumerate(products):
    ax.annotate(name, scores[i], xytext=(4, 3), textcoords="offset points")
ax.axhline(0, color="gray", linewidth=0.8)
ax.axvline(0, color="gray", linewidth=0.8)
ax.set_title("Product map on the first two principal components")
ax.set_xlabel("PC1 score")
ax.set_ylabel("PC2 score")
ax.grid(True, alpha=0.3)
fig.tight_layout()
plt.show()
[OUT: 8]
PC1 PC2
Dimension -0.413 -0.440
Roundness -0.452 -0.430
Roughness -0.270 0.105
Hardness -0.355 0.561
Vibration -0.543 -0.083
Temperature -0.362 0.537

No.066: PCA (Principal Component Analysis): computed results

Reading the results

Nearby products are close in the first two components, but may differ in discarded directions. Inspect the direction coefficients, original features and residuals. A distant product is a candidate for investigation, not automatically a defective product.

No.067: NMF (Non-Negative Matrix Factorization)

Meaning in Practice

For non-negative data such as defect count or contribution, NMF, which combines non-negative cause patterns, may be easier to explain than PCA, where positive and negative factors cancel each other out. You can read “How many defective modes are included in each variety.”

Approach to Analysis and Modeling

Impose D≈WHD\approx WH with D,W,H≥0D,W,H\ge0 and use multiplicative updates to reduce Frobenius error. Here the quality columns are shifted by their minima to create illustrative nonnegative data; they are not actual defect counts. Factors are not unique, so compare multiple seeds and check interpretations against process records.

Check with Python

[IN: 9]
D_defect = np.maximum(raw_matrix - raw_matrix.min(axis=0) + 0.15, 0)
k_nmf = 3
W = rng.random((D_defect.shape[0], k_nmf)) + 0.1
H = rng.random((k_nmf, D_defect.shape[1])) + 0.1
eps = 1e-10
for _ in range(800):
    H *= (W.T @ D_defect) / (W.T @ W @ H + eps)
    W *= (D_defect @ H.T) / (W @ H @ H.T + eps)
H_scaled = H / H.sum(axis=1, keepdims=True)
display(
    pd.DataFrame(
        H_scaled, index=["Pattern 1", "Pattern 2", "Pattern 3"], columns=features
    ).round(3)
)
print(
    f"relative NMF error = {np.linalg.norm(D_defect-W@H)/np.linalg.norm(D_defect):.3f}"
)
fig, ax = plt.subplots(figsize=(8, 3.5))
ax.imshow(H_scaled, cmap="YlOrRd", aspect="auto")
ax.set_title("Quality-feature composition of NMF patterns")
ax.set_xlabel("Quality feature")
ax.set_ylabel("Latent pattern")
ax.set_xticks(range(len(features)), features, rotation=30, ha="right")
ax.set_yticks(range(3), ["Pattern 1", "Pattern 2", "Pattern 3"])
ax.grid(False)
fig.tight_layout()
plt.show()
[OUT: 9]
Dimension Roundness Roughness Hardness Vibration Temperature
Pattern 1 0.426 0.302 0.002 0.025 0.182 0.063
Pattern 2 0.028 0.003 0.063 0.404 0.081 0.421
Pattern 3 0.009 0.108 0.684 0.033 0.165 0.001
relative NMF error = 0.036

No.067: NMF (Non-Negative Matrix Factorization): computed results

Reading the results

Each factor describes a nonnegative feature pattern. Such patterns suggest hypotheses, but statistical co-occurrence is not proof of a physical cause. Check stability across initializations and compare with maintenance histories or experiments.

No.068: Tensor Decomposition

Meaning in Practice

Averaging over machines removes machine-specific variation. Simply reshaping all entries into a matrix does not lose information, but a tensor decomposition retains the product, machine and feature modes explicitly.

Approach to Analysis and Modeling

HOSVD applies SVD to the matrix unfolding along each mode and retains selected bases. A core tensor GG and factors Up,Um,UfU_p,U_m,U_f give T≈G×1Up×2Um×3UfT\approx G\times_1U_p\times_2U_m\times_3U_f. Choose ranks (rp,rm,rf)(r_p,r_m,r_f) separately for each mode.

Check with Python

[IN: 10]
T = quality_tensor
Up = np.linalg.svd(T.reshape(T.shape[0], -1), full_matrices=False)[0][:, :3]
Um = np.linalg.svd(T.transpose(1, 0, 2).reshape(T.shape[1], -1), full_matrices=False)[
    0
][:, :2]
Uf = np.linalg.svd(T.transpose(2, 0, 1).reshape(T.shape[2], -1), full_matrices=False)[
    0
][:, :3]
core = np.einsum("pa,mb,fc,pmf->abc", Up, Um, Uf, T)
T_hat = np.einsum("pa,mb,fc,abc->pmf", Up, Um, Uf, core)
machine_loading = pd.DataFrame(
    Um, index=machines, columns=["Machine mode 1", "Machine mode 2"]
)
display(machine_loading.round(3))
print(f"original shape={T.shape}, core shape={core.shape}")
print(f"relative HOSVD error = {np.linalg.norm(T-T_hat)/np.linalg.norm(T):.3f}")
fig, ax = plt.subplots(figsize=(7, 3.5))
ax.bar(machines, np.abs(Um[:, 0]), color="#59A14F")
ax.set_title("Absolute loadings of the leading machine mode")
ax.set_xlabel("Machine")
ax.set_ylabel("Absolute loading")
ax.grid(True, axis="y", alpha=0.3)
fig.tight_layout()
plt.show()
[OUT: 10]
Machine mode 1 Machine mode 2
M01 -0.381 0.148
M02 -0.309 -0.463
M03 -0.352 -0.144
M04 -0.405 0.709
M05 -0.349 -0.034
M06 -0.318 -0.425
M07 -0.368 0.158
M08 -0.337 -0.182
original shape=(12, 8, 6), core shape=(3, 2, 3)
relative HOSVD error = 0.308

No.068: Tensor Decomposition: computed results

Reading the results

The 12 × 8 × 6 tensor is approximated by a 3 × 2 × 3 core and three factor matrices. Large machine-mode coefficients describe contributions to variation, not machine quality. Examine machine-level residuals as well.

No.069: CUR Decomposition

Meaning in Practice

The latent vectors of SVD are a mixture of multiple characteristics and can be difficult to explain. CUR decomposition can be described as an approximation using “representative characteristics” and “representative varieties,” selecting the actual columns CC and row RR in the source data.

Approach to Analysis and Modeling

X≈CURX\approx CUR is used, and the importance of columns and rows is determined by the leverage score of the higher-level singular vector. Here, prioritize reproducibility and decisively select the top scores, with the central matrix set as U=C+XR+U=C^+XR^+. While representativeness can be achieved, it is necessary to check that the columns are not biased toward homogeneous ones.

Check with Python

[IN: 11]
k_cur, n_cols, n_rows = 2, 3, 5
col_score = np.sum(Vt[:k_cur] ** 2, axis=0)
row_score = np.sum(U[:, :k_cur] ** 2, axis=1)
col_idx = np.argsort(col_score)[-n_cols:]
row_idx = np.argsort(row_score)[-n_rows:]
C_cur, R_cur = X[:, col_idx], X[row_idx, :]
U_cur = np.linalg.pinv(C_cur) @ X @ np.linalg.pinv(R_cur)
X_cur = C_cur @ U_cur @ R_cur
display(
    pd.DataFrame(
        {
            "Selected feature": np.array(features)[col_idx],
            "Leverage score": col_score[col_idx],
        }
    ).round(3)
)
display(
    pd.DataFrame(
        {
            "Selected product": np.array(products)[row_idx],
            "Leverage score": row_score[row_idx],
        }
    ).round(3)
)
print(f"relative CUR error = {np.linalg.norm(X-X_cur)/np.linalg.norm(X):.3f}")
[OUT: 11]
Selected feature Leverage score
0 Roundness 0.39
1 Temperature 0.42
2 Hardness 0.44
Selected product Leverage score
0 P05 0.189
1 P08 0.206
2 P09 0.295
3 P07 0.330
4 P10 0.382
relative CUR error = 0.241

Reading the results

The selected columns and rows represent real characteristics and varieties that best represent the latent axis. While it is easy to use for site presentations and representative sample design, if there are fewer options, the error is greater than the optimal low-rank approximation of SVD. It clearly states the exchange conditions for representativeness and accuracy.

No.070: Matrix Completion

Meaning in Practice

If you can compensate for the missing values caused by skipping inspections or temporary sensor stoppages, monitoring can continue. However, the complementary values are model estimates, not observations, and do not automatically replace shipment determination.

Approach to Analysis and Modeling

Keep observed values fixed and repeatedly update missing entries with a rank-3 SVD approximation. This uses singular-value truncation, unlike Soft-Impute, which shrinks singular values. The example masks entries of an already standardized, fixed matrix. Because standardization used all cells before masking, this is an illustration of reconstruction error, not an independent estimate of unseen-data performance. In deployment validation, estimate preprocessing parameters from observed training values only.

Check with Python

[IN: 12]
mask_observed = rng.random(X.shape) > 0.22
# Ensures that observations remain in each row and column
mask_observed[:, 0] = True
mask_observed[0, :] = True
X_missing = X.copy()
X_missing[~mask_observed] = np.nan
col_mean = np.nanmean(X_missing, axis=0)
X_fill = np.where(mask_observed, X_missing, col_mean)
for _ in range(150):
    u_i, s_i, vt_i = np.linalg.svd(X_fill, full_matrices=False)
    low_rank = u_i[:, :3] @ np.diag(s_i[:3]) @ vt_i[:3]
    updated = np.where(mask_observed, X, low_rank)
    change = np.linalg.norm(updated - X_fill)
    X_fill = updated
    if change < 1e-7:
        break
missing_rmse = np.sqrt(np.mean((X_fill[~mask_observed] - X[~mask_observed]) ** 2))
mean_fill = np.where(mask_observed, X, col_mean)
baseline_rmse = np.sqrt(np.mean((mean_fill[~mask_observed] - X[~mask_observed]) ** 2))
print(f"missing cells = {(~mask_observed).sum()} / {X.size}")
print(f"low-rank completion RMSE = {missing_rmse:.3f}")
print(f"column-mean baseline RMSE = {baseline_rmse:.3f}")
fig, ax = plt.subplots(figsize=(6, 4))
ax.scatter(X[~mask_observed], X_fill[~mask_observed], color="#E15759")
lims = [X[~mask_observed].min() - 0.2, X[~mask_observed].max() + 0.2]
ax.plot(lims, lims, "--", color="gray", label="ideal")
ax.set_title("Held-out values versus low-rank estimates")
ax.set_xlabel("True standardized value")
ax.set_ylabel("Estimated standardized value")
ax.grid(True, alpha=0.3)
ax.legend()
fig.tight_layout()
plt.show()
[OUT: 12]

missing cells = 18 / 72

low-rank completion RMSE = 0.126
column-mean baseline RMSE = 0.767

No.070: Matrix Completion: computed results

Reading the results

Compare the reconstruction RMSE of the masked entries with column-mean imputation. Real missingness may depend on failures or product type, so random masking can give optimistic results. Mark imputed values explicitly and remeasure critical inspection characteristics.

Using the results in practice

Matrix decomposition is not a one-size-fits-all method; it is a toolbox tailored to specific purposes.

  • solve an equation: If you want to reuse coefficient matrices, choose LU; for symmetric positive definites, choose Cholesky; for least squares, choose QR as a candidate.
  • Understanding the structure: Diagnose effective rank with SVD and manage accuracy and cost with low-rank approximation.
  • explain: Use PCA for centered variations, NMF for non-negative additive contributions, and CUR if you need a real representative matrix
  • Maintain multidirectionality: Do not easily flatten the characteristics × the type × equipment; consider tensor decomposition
  • Handling missing values: Make assumptions of matrix completion, validation missing, baseline comparison, and estimation flags mandatory

Preparing for practical use

  1. Defining Objectives and Losses: Clarify the primary objectives of compression, visualization, prediction, and gap compensation.
  2. Unify data granularity: Align variety, equipment, time, measurement units, and standard change history
  3. Monitor the assumptions: Check the mechanisms of symmetry, positive definiteness, condition number, rank, non-negativity, and defect
  4. Verify in chronological order: Evaluate not only random division but also future periods, new product types, and equipment changes
  5. Managing Residuals: Leave local anomalies that low-rank models cannot explain in control charts or alerts
  6. Separating decision-making rules: Do not decide shipment eligibility solely from estimates; define remeasurement and approval conditions
  7. Ensuring reproducibility: Record code, seed, preprocessing, model order, evaluation results, and data versions

Conclusion

LU, Cholesky and QR solve linear systems; SVD and PCA relate retained components to reconstruction error. NMF, tensor decomposition and CUR use nonnegativity, data axes, or selected original rows and columns. When evaluating imputation on real data, exclude hidden values from preprocessing and fitting, and check whether missingness is concentrated in particular products or features.

Consultations for Corporations

At Surikobo, we support everything from structural diagnosis of manufacturing data, design of quality KPIs, PoC for dimension reduction, anomaly detection, and missing-value imputation, to numerical stability reviews of existing analyses, and on-site training. We ask about challenges and available data, and organize them from the minimum configuration necessary for decision-making.

📩 Contact Us: www.surikobo.co.jp/contact
Please contact us to discuss your project.