Skip to content

Commit a0bef59

Browse files
committed
Tests passing locally
1 parent a2628d4 commit a0bef59

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

machine_learning/word_frequency_functions.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ def term_frequency(term : str, document : str) -> int:
5050
found within the document
5151
5252
@examples:
53-
>>> document = "To be, or not to be"
5453
>>> term_frequency("to", "To be, or not to be")
5554
2
5655
"""
@@ -74,16 +73,10 @@ def document_frequency(term: str, corpus: str) -> int:
7473
@returns : the number of documents in the corpus that contain the term you are
7574
searching for and the number of documents in the corpus
7675
@examples :
77-
>>> corpus = \
78-
"This is the first document in the corpus.\n ThIs is \
79-
the second document in the corpus. \n THIS is \
80-
the third document in the corpus."
81-
>>> term = "first"
82-
1
83-
>>> term = "document"
84-
3
85-
>>> term = "this"
86-
3
76+
>>> document_frequency("first", "This is the first document in the corpus.\\nThIs is\
77+
the second document in the corpus.\\nTHIS is \
78+
the third document in the corpus.")
79+
(1, 3)
8780
"""
8881
corpus_without_punctuation = corpus.translate(
8982
str.maketrans("", "", string.punctuation)
@@ -107,9 +100,8 @@ def inverse_document_frequency(df : int, N: int) -> float:
107100
the number of documents in the corpus.
108101
@returns : log10(N/df)
109102
@examples :
110-
>>> df = 1
111-
>>> N = 3
112-
.477
103+
>>> inverse_document_frequency(1, 3)
104+
0.477
113105
"""
114106
try:
115107
idf = round(log10(N / df), 3)
@@ -128,5 +120,8 @@ def tf_idf(tf : int, idf: int) -> float:
128120
frequency : tf-idf = TF * IDF
129121
@params : tf, the term frequency, and idf, the inverse document
130122
frequency
123+
@examples :
124+
>>> tf_idf(2, 0.477)
125+
0.954
131126
"""
132127
return round(tf * idf, 3)

0 commit comments

Comments
 (0)