Exact and Certified Data Shapley for Weighted k-NN Regression

New exact Data Shapley for weighted k-NN regression overcomes prior brute-force limitations. Includes certified FPTAS and open-source library. Ideal for

martes, 28 de julio de 2026 • 4 min read • Q2BSTUDIO Team

Nuevo algoritmo exacto de Data Shapley para regresión k-NN ponderada

The concept of Data Shapley has emerged as the most rigorous standard for assigning a fair value to each training point in machine learning models. Its specialization for k-NN (k-nearest neighbors) is the most widely used version in practice, implemented in libraries such as pyDVL and OpenDataVal. However, until now there was a significant gap: exact algorithms only worked for unweighted or weighted k-NN classification, while weighted regression and soft labels remained out of reach, limited to a costly brute-force O(N^K) method. This article analyzes the recent breakthrough that closes that gap, presenting the first exact pseudo-polynomial algorithm and a certified FPTAS for weighted k-NN regression, and connects it with the opportunities this opens for companies seeking to integrate reliable and transparent artificial intelligence into their processes.

The central difficulty of weighted regression lies in the prediction being computed as a ratio of two coalition-dependent sums: the sum of weights and the sum of weights times target values. That denominator breaks the additive, threshold, and duplication structures that previous polynomial methods relied on. The new approach, based on a counting dynamic program over joint integer states (sum of weights, sum of weights times y), achieves pseudo-polynomial complexity O(N * K * precision) and has been verified against exhaustive enumeration on more than 12,700 adversarial instances with zero mismatch. It also offers a Fully Polynomial-Time Approximation Scheme (FPTAS) with verifiable error certificates, validated across over 86,400 checks. This not only provides an exact reference for auditing estimators but also demonstrates that Monte Carlo methods, while statistically equivalent at an aggregate level, fail to reproduce the exact top-10% ranking even with 3,000 permutations (1.28 million utility evaluations).

From a business perspective, the ability to assign exact value to training data has profound implications. In AI applications where data is a critical asset — such as medical diagnostics, fraud detection, or recommendation personalization — knowing which samples truly contribute to model performance enables optimized data collection, label error detection, and justification of data infrastructure investments. The weighted k-NN variant is especially relevant when neighbors do not have equal influence, common in time series, spatial data, or heterogeneous noise contexts. For example, in a cybersecurity system analyzing traffic patterns, an attack may be represented by points with variable weights depending on age or reliability; an exact Shapley identifies the most decisive records for early detection.

The release of this algorithm as open source (CPU-only library) facilitates its adoption in corporate environments. Companies like Q2BSTUDIO, specialized in custom software development, can integrate these methods into AI solutions for clients requiring traceability and certification of their models. Combining exact algorithms with cloud AWS/Azure allows scaling the computation to large datasets without losing precision, while BI/Power BI capabilities facilitate visualization of Shapley values for non-technical stakeholders. Furthermore, AI agents that make autonomous decisions can benefit from more reliable data valuation to adjust their behavior in real time.

Another key aspect is data quality management. Mislabel detection is a direct application: with exact Shapley values, anomalous points that negatively affect the model can be identified. In a downstream mislabel detection study, the authors showed that Monte Carlo values fail to reproduce the exact top-10% ranking, underscoring the need for exact methods when precision is critical. For a company managing sensitive data, such as in cybersecurity or regulatory compliance environments, having verifiable error certificates (as in the FPTAS) provides a level of transparency that may be required by audits or regulations.

The theoretical complexity of the problem also deserves attention. An unconditional lower bound of Omega(D_w) on the output size has been proven, along with hardness results in certain access models. This means that although the new algorithm is efficient in practical terms, the dependence on precision or the number of neighbors cannot be completely eliminated. However, for most business applications (K in the tens and N from thousands to millions), the pseudo-polynomial approach is feasible. Furthermore, the extension to multi-class classification with soft labels broadens its utility to problems like sentiment analysis or differential diagnosis.

In summary, the breakthrough in exact Data Shapley calculation for weighted k-NN regression represents both a theoretical and practical milestone. It allows companies and researchers to rely on data valuation free from uncontrolled approximations, facilitating decision-making based on the actual contribution of each sample. At Q2BSTUDIO, we understand that AI must not only be powerful but also verifiable. Therefore, we offer custom software development services that integrate these cutting-edge algorithms into cloud platforms, ensuring scalability, security, and certification. If your organization seeks to implement machine learning models with full transparency, exact Shapley is the path, and we are ready to help you walk it.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.