基礎知識指南

機器學習中的距離度量

距離度量是數學函數,用於量化兩個數據點之間的相似或差異程度,是 k-近鄰和聚類等演算法的基礎。

聆聽此指南AI 語音敘述 · ~3 min

本頁閱讀時間3分鐘
  1. 概述
  2. 深入探討
  3. 現實世界的實施
  4. 機器學習中距離度量的未來
  5. 付諸實踐
  6. 不斷探索
  7. 常見問題

概述

選擇正確的度量標準至關重要,因為不同的度量標準假設了不同的相似性概念,錯誤的選擇可能會導致原本合理的演算法表現不佳。

深入探討

A distance metric turns raw feature values into a single number representing how far apart two points are, which many algorithms rely on directly. Euclidean distance, the straight-line distance familiar from geometry, is a common choice in many introductory examples and works well when features are continuous, roughly on comparable scales, and the notion of similarity matches physical closeness. Manhattan distance, also called taxicab distance, sums the absolute differences along each dimension rather than taking the square root of squared differences; it suits grid-like movement constraints and is less sensitive to outliers in individual dimensions than Euclidean distance. Cosine distance measures orientation between nonzero vectors rather than their magnitudes, making it useful in some text and recommendation systems where a document or user profile's overall direction, such as topic balance, matters more than its raw length or intensity. Mahalanobis distance generalizes Euclidean distance by accounting for the correlations and differing variances between features, effectively normalizing the space so that features are compared fairly regardless of their original scale, which is useful in anomaly detection and multivariate outlier analysis. Hamming distance counts the number of positions at which two equal-length strings or categorical vectors differ, making it suited for categorical data, error-correcting codes, and genetic sequence comparison rather than continuous numeric data. A common misconception is that Euclidean distance is always the safe default; in high-dimensional spaces, all pairwise Euclidean distances tend to become similar, a phenomenon sometimes called the curse of dimensionality, which can make nearest-neighbor comparisons less informative; checking distance distributions and task performance can reveal when that matters.

現實世界的實施

預測房價的 k-近鄰模型使用歐幾里得距離來衡量建築面積、臥室數量及房齡,將所有數值差異視為特徵空間中的直線距離。

城市網格配送路徑規劃工具使用曼哈頓距離而非歐幾里得距離,因為車輛必須沿著街道網格行駛,而非直線移動,這使得度量標準符合實際的移動限制。

比較用戶偏好向量的推薦系統使用餘弦距離而非歐幾里得距離,因為它關注的是偏好模式的 방향(例如類型平衡),而非評分的原始幅度。

DNA 序列比較工具使用漢明距離來計算兩個等長基因序列中差異的位置數量,因為數據是類別型的而非連續型的。

機器學習中距離度量的未來

距離度量標準的選擇仍然是機器學習實踐中一個基礎且相對穩定的部分,儘管學習型距離度量(有時稱為度量學習)在面部驗證等專業應用中越來越受歡迎,其中神經網絡學習一個嵌入空間,使得簡單的距離(通常是餘弦或歐幾里得距離)在訓練後變得有意義。隨著深度學習的發展,預計距離度量標準將繼續保持相關性,因為大多數基於嵌入的系統仍然依賴於應用於學習表示的經典距離函數,而不是完全取代距離的概念。

付諸實踐

為什麼這很重要

  • 更明確的決策. 它可以幫助您將清晰的技術聲明與行銷語言分開。
  • 成本與預算. 在花費金錢或時間之前,您可以提出更好的實施問題。
  • 團隊與工作流程. 具有共同理解的團隊可以做出更好的產品、政策和學習決策。

留意

  • 不同的團隊可能會以不同的方式使用相同術語,因此請儘早定義範圍。
  • 基準測試可能看起來很強大,但實際效能卻參差不齊。
  • 忽視數據品質和評估計劃通常會產生脆弱的結果。

後續步驟

  1. 從您需要的結果的簡單語言定義開始。
  2. 在測試之前選擇一種成功指標和一種失敗條件。
  3. 使用代表性資料運行小型試點,而不是完善的演示集。
  4. 記錄機器學習中距離度量標準在哪些方面有幫助,以及在哪些情況下更簡單的方法更好。

不斷探索

免費電子報

獲取每日 AI 簡報

每個工作日上午提供三則經過驗證的 AI 新聞,以淺顯易懂的英文撰寫。永久免費,無廣告。

每個工作日一封電子郵件。一鍵取消訂閱。我們絕不出售或分享您的地址。

測試一下自己

參加機器學習中距離度量標準測驗

每個答案皆有即時回饋,通過課程後可獲得具備可驗證 ID 的可分享證書。

開始測驗

支持免費的 AI 教育。AI Understanding 是一個 501(c)(3) 非營利組織——絕無廣告,絕無付費牆。 捐款

常見問題

什麼是機器學習中的距離度量標準?

距離度量是數學函數,用於量化兩個數據點之間的相似或差異程度,是 k-近鄰和聚類等演算法的基礎。選擇正確的度量標準至關重要,因為不同的度量標準假設了不同的相似性概念,錯誤的選擇可能會導致原本合理的演算法表現不佳。

為什麼配送路徑規劃示例選擇曼哈頓距離而非歐幾里得距離?

曼哈頓距離沿著網格軸線累加差異,這符合車輛實際沿著城市街道行駛而非直線路徑的方式。

根據指南定義,餘弦距離測量什麼特性,使其適合推薦系統?

餘弦距離捕捉的是方向(例如偏好向量中的類型平衡),而非原始幅度,這符合推薦系統的應用場景。

馬哈拉諾比斯距離比歐幾里得距離多納入了什麼額外資訊?

馬哈拉諾比斯距離使用特徵協方差矩陣的逆矩陣,考慮了普通歐幾里德距離忽略的相關性和尺度差異。

根據指南,漢明距離特別適合什麼類型的資料?

該指南將漢明距離描述為計算等長字串或分類向量中的不同位置,以擬合遺傳序列比較。

該指南說在計算跨特徵的歐幾里德距離之前通常需要什麼預處理步驟?

技術部分指出,特徵通常必須進行縮放(通常透過標準化),因此較大範圍的特徵不會主導距離計算。