{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The Jaccard dissimilarity satisfies the triangle inequality and is qualified as a metric. "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "2"
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Jaccard index"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", or "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Jaccard similarity coefficient"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", is equal to one minus the Jaccard dissimilarity. "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "3"
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The dissimilarity between general (finite) sets may be computed by encoding them as boolean vectors and computing the dissimilarity between the encoded vectors. For example, subsets "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "A,B"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\{ 1, 2, ..., n \\}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " may be encoded into boolean vectors "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "u, v"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " by setting "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "u_k := 1_{k \\in A}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "v_k := 1_{k \\in B}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "k = 1,2,\\cdots,n"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "versionchanged",
          "base_type": "neutral",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "versionchanged 1.2.0"
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Previously, if all (positively weighted) elements in "
                },
                {
                  "__type": "ParamRef",
                  "__tag": 4071,
                  "name": "u"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " and "
                },
                {
                  "__type": "ParamRef",
                  "__tag": 4071,
                  "name": "v"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " are zero, the function would return "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "nan"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ".  This was changed to return "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "0"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " instead."
                }
              ]
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "versionchanged",
          "base_type": "neutral",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "versionchanged 1.15.0"
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Non-0/1 numeric input used to produce an ad hoc result.  Since 1.15.0, numeric input is converted to Boolean before computation."
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Raises": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Yields": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Methods": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Returns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "jaccard",
              "annotation": "float",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The Jaccard dissimilarity between vectors "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "u"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "v"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", optionally weighted by "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "w"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " if supplied."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Compute the Jaccard dissimilarity between two boolean vectors."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Receives": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warnings": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Attributes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "u",
              "annotation": "(N,) array_like of bools",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Input vector."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "v",
              "annotation": "(N,) array_like of bools",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Input vector."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "w",
              "annotation": "(N,) array_like of floats, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Weights for each pair of "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "(u_k, v_k)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ".  Default is "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "None"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", which gives each pair a weight of "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "1.0"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Given boolean vectors "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "u \\equiv (u_1, \\cdots, u_n)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "v \\equiv (v_1, \\cdots, v_n)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " that are not both zero, their "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Jaccard dissimilarity"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is defined as ("
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", p. 26)"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "d_\\textrm{jaccard}(u, v) := \\frac{c_{10} + c_{01}}\n                                 {c_{11} + c_{10} + c_{01}}"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "where"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "c_{ij} := \\sum_{1 \\le k \\le n, u_k=i, v_k=j} 1"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "for "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "i, j \\in \\{ 0, 1\\}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ".  If "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "u"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "v"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " are both zero, their Jaccard dissimilarity is defined to be zero. "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "2"
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If a (non-negative) weight vector "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "w \\equiv (w_1, \\cdots, w_n)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is supplied, the "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "weighted Jaccard dissimilarity"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is defined similarly but with "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "c_{ij}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " replaced by"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "\\tilde{c}_{ij} := \\sum_{1 \\le k \\le n, u_k=i, v_k=j} w_k"
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Other Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    }
  },
  "_ordered_sections": [
    "Summary",
    "Extended Summary",
    "Parameters",
    "Attributes",
    "Methods",
    "Returns",
    "Yields",
    "Receives",
    "Other Parameters",
    "Raises",
    "Warns",
    "Warnings",
    "Notes"
  ],
  "item_file": "/scipy/spatial/distance.py",
  "item_line": 778,
  "item_type": "function",
  "aliases": [
    "scipy.spatial.distance.jaccard"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "from scipy.spatial import distance\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nNon-zero vectors with no matching 1s have dissimilarity of 1.0:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "distance.jaccard([1, 0, 0], [0, 1, 0])\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nVectors with some matching 1s have dissimilarity less than 1.0:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "distance.jaccard([1, 0, 0, 0], [1, 1, 1, 0])\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nIdentical vectors, including zero vectors, have dissimilarity of 0.0:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "distance.jaccard([1, 0, 0], [1, 0, 0])\ndistance.jaccard([0, 0, 0], [0, 0, 0])\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThe following example computes the dissimilarity from a confusion matrix\ndirectly by setting the weight vector to the frequency of True Positive,\nFalse Negative, False Positive, and True Negative:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "distance.jaccard([1, 1, 0, 0], [1, 0, 1, 0], [31, 41, 59, 26])\n",
        "execution_status": "failure"
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "u",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "v",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "w",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "jaccard"
  },
  "references": [
    ".. [1] Kaufman, L. and Rousseeuw, P. J.  (1990).  \"Finding Groups in Data:",
    "       An Introduction to Cluster Analysis.\"  John Wiley & Sons, Inc.",
    ".. [2] Kosub, S.  (2019).  \"A note on the triangle inequality for the",
    "       Jaccard distance.\"  *Pattern Recognition Letters*, 120:36-38.",
    ".. [3] https://en.wikipedia.org/wiki/Jaccard_index"
  ],
  "qa": "scipy.spatial.distance:jaccard",
  "arbitrary": [],
  "local_refs": [
    "jaccard",
    "u",
    "v",
    "w"
  ]
}