Abstract
Distance metrics are fundamental to many machine learning algorithms, yet standard metrics like Euclidean distance are often limited to flat, tabular data. This paper presents a methodology for applying "term distances"—specialized similarity metrics originally developed for logic programming—to both flat and complex hierarchical datasets. By mapping data into a unified XML schema, the authors show that machine learning models can exploit structural context and feature hierarchies. Empirical evaluations on standard datasets demonstrate that term distances significantly improve classification accuracy compared to traditional Euclidean and tree-edit distances.
Introduction
In machine learning, the choice of distance metric is critical for the performance of algorithms such as $k$-Nearest Neighbors ($k$-NN) and clustering. While Euclidean distance is the standard for flat data, it fails to capture the nuances of hierarchical structures like XML documents or ontologies. Conversely, traditional "tree edit distances" often ignore the semantic context of nodes, treating structural edits identically regardless of their position in the hierarchy.
This research addresses the challenge of applying context-aware "term distances" from Inductive Logic Programming to everyday data. The authors propose a transformation pipeline that converts flat or semi-structured data into functional terms (represented via XML), allowing algorithms to weight differences based on their depth and structural context.
Methodology
The core of the proposed approach is the transformation of diverse data types into a unified XML schema. This schema serves as a proxy for functional terms, enabling the use of term-based distance metrics. Three primary transformation strategies were evaluated:
- Name-Induced Hierarchies: Flat attributes are grouped based on common prefixes (e.g.,
cap-shapeandcap-colorunder a<cap>tag). - Attribute-Similarity Hierarchies: Statistical measures like Chi-square are used to find correlations between features, which are then organized into a synthetic dendrogram.
- Source-Level Hierarchical Mapping: Inherently nested data is directly translated into XML while preserving its original structure.
Once transformed, the authors apply distance-weighted $k$-NN using two specific term distances:
- Nienhuys-Cheng distance ($d_N$): Weights differences more heavily if they occur closer to the root of the tree.
- Estruch et al. distance ($d_E$): Accounts for both context and the syntactic complexity/repetition of differences.
Experimental Setup
The methodology was tested on three datasets from the UCI Machine Learning Repository:
- Mushroom: A flat dataset for predicting edibility.
- Soybean: A flat dataset for disease diagnosis.
- Demospongiae (Sponge): A complex, inherently hierarchical dataset originally represented as Lisp trees.
Results and Discussion
The experimental results highlight the superiority of term distances over standard metrics:
- Mushroom Dataset: Using a Chi-square similarity-induced hierarchy, term distances ($d_N$ and $d_E$) achieved 100% accuracy, outperforming Euclidean distance (95.5%).
- Soybean Dataset: Term distances reached 99.4% accuracy, compared to 92.6% for Euclidean distance.
- Sponge Dataset: For this hierarchical data, Euclidean distance was inapplicable. The Estruch et al. distance ($d_E$) outperformed Nienhuys-Cheng ($d_N$) with 78.7% vs. 74.3% accuracy, suggesting that accounting for repeated differences is crucial for complex semi-structured data.
The findings suggest that structure can be effectively synthesized from flat data to improve classification. Term distances align better with human logic by penalizing top-level differences more heavily, which often represent more fundamental distinctions between objects.
Conclusion
This paper demonstrates that term distances provide a powerful alternative to traditional metrics for both flat and hierarchical data. While the "Name-Induced" hierarchy method showed inconsistent results, the "Attribute-Similarity" approach proved highly effective. Future work will explore the application of these distances in clustering, automated debugging, and program analysis.
Summary updated