{
  "id": "opencv/kmeans-clustering-empty-labels",
  "signature": "cv2.error: OpenCV(4.9.0) /tmp/opencv-4.9.0/modules/core/src/kmeans.cpp:245: error: (-215:Assertion failed) N >= K in function 'kmeans'",
  "signature_zh": "cv2.error: OpenCV(4.9.0) /tmp/opencv-4.9.0/modules/core/src/kmeans.cpp:245: error: (-215:断言失败) N >= K 在函数 'kmeans' 中",
  "regex": "N >= K.*function 'kmeans'",
  "domain": "opencv",
  "category": "assertion_error",
  "subcategory": null,
  "root_cause": "Number of data points (N) is less than the number of clusters (K) requested in k-means clustering, causing an assertion failure.",
  "root_cause_type": "generic",
  "root_cause_zh": "k-means 聚类中数据点数量 (N) 小于请求的簇数量 (K)，导致断言失败。",
  "versions": [
    {
      "version": "4.8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "4.9.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "4.10.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Using K=1 might avoid the assertion but is not meaningful for clustering; it's a workaround but not a fix.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Randomly duplicating points to increase N distorts the data distribution and produces incorrect clusters.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Transposing the data matrix doesn't change the number of samples; it only changes feature dimensions.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure K is less than or equal to the number of data points. Add a check: `if len(data) < K: K = len(data)` before calling kmeans.",
      "success_rate": 0.95,
      "how": "Ensure K is less than or equal to the number of data points. Add a check: `if len(data) < K: K = len(data)` before calling kmeans.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a smaller K value appropriate for the dataset: `K = min(K, len(data))`",
      "success_rate": 0.9,
      "how": "Use a smaller K value appropriate for the dataset: `K = min(K, len(data))`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Collect more data points or use a different clustering algorithm (e.g., DBSCAN) that doesn't require specifying K.",
      "success_rate": 0.7,
      "how": "Collect more data points or use a different clustering algorithm (e.g., DBSCAN) that doesn't require specifying K.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Ensure K is less than or equal to the number of data points. Add a check: `if len(data) < K: K = len(data)` before calling kmeans.",
    "Use a smaller K value appropriate for the dataset: `K = min(K, len(data))`",
    "Collect more data points or use a different clustering algorithm (e.g., DBSCAN) that doesn't require specifying K."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.opencv.org/4.x/d5/d38/group__core__cluster.html#ga9a34e2885e5b3e9ad7a7a2f7c0e3c3a0",
  "official_doc_section": null,
  "error_code": "-215",
  "verification_tier": "ai_generated",
  "confidence": 0.9,
  "fix_success_rate": 0.95,
  "resolvable": "true",
  "first_seen": "2024-01-12",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}