mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 17:34:49 +08:00
Misc fixes across multiple algorithms (#6912)
Source: Snyk code quality Add scikit-fuzzy to requirements Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
This commit is contained in:
@ -75,11 +75,12 @@ def main():
|
||||
"""Call Extended Euclidean Algorithm."""
|
||||
if len(sys.argv) < 3:
|
||||
print("2 integer arguments required")
|
||||
exit(1)
|
||||
return 1
|
||||
a = int(sys.argv[1])
|
||||
b = int(sys.argv[2])
|
||||
print(extended_euclidean_algorithm(a, b))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
raise SystemExit(main())
|
||||
|
@ -14,7 +14,7 @@ Jaccard similarity is widely used with MinHashing.
|
||||
"""
|
||||
|
||||
|
||||
def jaccard_similariy(set_a, set_b, alternative_union=False):
|
||||
def jaccard_similarity(set_a, set_b, alternative_union=False):
|
||||
"""
|
||||
Finds the jaccard similarity between two sets.
|
||||
Essentially, its intersection over union.
|
||||
@ -35,18 +35,18 @@ def jaccard_similariy(set_a, set_b, alternative_union=False):
|
||||
Examples:
|
||||
>>> set_a = {'a', 'b', 'c', 'd', 'e'}
|
||||
>>> set_b = {'c', 'd', 'e', 'f', 'h', 'i'}
|
||||
>>> jaccard_similariy(set_a, set_b)
|
||||
>>> jaccard_similarity(set_a, set_b)
|
||||
0.375
|
||||
|
||||
>>> jaccard_similariy(set_a, set_a)
|
||||
>>> jaccard_similarity(set_a, set_a)
|
||||
1.0
|
||||
|
||||
>>> jaccard_similariy(set_a, set_a, True)
|
||||
>>> jaccard_similarity(set_a, set_a, True)
|
||||
0.5
|
||||
|
||||
>>> set_a = ['a', 'b', 'c', 'd', 'e']
|
||||
>>> set_b = ('c', 'd', 'e', 'f', 'h', 'i')
|
||||
>>> jaccard_similariy(set_a, set_b)
|
||||
>>> jaccard_similarity(set_a, set_b)
|
||||
0.375
|
||||
"""
|
||||
|
||||
@ -67,14 +67,15 @@ def jaccard_similariy(set_a, set_b, alternative_union=False):
|
||||
|
||||
if alternative_union:
|
||||
union = len(set_a) + len(set_b)
|
||||
return len(intersection) / union
|
||||
else:
|
||||
union = set_a + [element for element in set_b if element not in set_a]
|
||||
return len(intersection) / len(union)
|
||||
|
||||
return len(intersection) / len(union)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
set_a = {"a", "b", "c", "d", "e"}
|
||||
set_b = {"c", "d", "e", "f", "h", "i"}
|
||||
print(jaccard_similariy(set_a, set_b))
|
||||
print(jaccard_similarity(set_a, set_b))
|
||||
|
Reference in New Issue
Block a user