{
  "id": "opencv/kmeans-invalid-clusters",
  "signature": "cv2.error: OpenCV(4.9.0) /modules/core/src/kmeans.cpp:245: error: (-215:Assertion failed) N >= K in function 'cv::kmeans'",
  "signature_zh": "cv2.error: OpenCV(4.9.0) /modules/core/src/kmeans.cpp:245: 错误: (-215:断言失败) N >= K 在函数 'cv::kmeans' 中",
  "regex": "N >= K.*kmeans",
  "domain": "opencv",
  "category": "assertion_error",
  "subcategory": null,
  "root_cause": "The number of data points (N) is less than the number of requested clusters (K), making clustering impossible.",
  "root_cause_type": "generic",
  "root_cause_zh": "数据点数量（N）少于请求的聚类数量（K），导致聚类无法进行。",
  "versions": [
    {
      "version": "4.5.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "4.6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "4.7.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "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"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Increase the number of data points by duplicating existing points",
      "why_fails": "Duplicating points does not add new information and can bias the clustering; the real fix is to reduce K or use more distinct data.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a different clustering algorithm like DBSCAN",
      "why_fails": "While this avoids the error, it changes the algorithm behavior and may not be appropriate for the use case.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    },
    {
      "action": "Set K to a very large number",
      "why_fails": "Making K larger only exacerbates the N >= K violation.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Reduce the number of clusters K to be at most the number of data points N. Check N before calling kmeans and clamp K accordingly.",
      "success_rate": 0.95,
      "how": "Reduce the number of clusters K to be at most the number of data points N. Check N before calling kmeans and clamp K accordingly.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Add more data points by collecting additional samples or using data augmentation to increase N above K.",
      "success_rate": 0.7,
      "how": "Add more data points by collecting additional samples or using data augmentation to increase N above K.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Reduce the number of clusters K to be at most the number of data points N. Check N before calling kmeans and clamp K accordingly.",
    "Add more data points by collecting additional samples or using data augmentation to increase N above 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",
  "official_doc_section": null,
  "error_code": "-215",
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-12-01",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}