Skip to content

chapter05 fix for issue#34 #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,8 @@ dmypy.json

# Pyre type checker
.pyre/

# files created by notebook instructions
ch04/lid.176.ftz
ch04/reddit_dataframe.pkl
ch04/reddit-selfposts.db
30 changes: 14 additions & 16 deletions ch05/Feature_Engineering_Similarity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@
"source": [
"from spacy.lang.en.stop_words import STOP_WORDS as stopwords\n",
"print(len(stopwords))\n",
"tfidf = TfidfVectorizer(stop_words=stopwords)\n",
"tfidf = TfidfVectorizer(stop_words=list(stopwords))\n",
"dt = tfidf.fit_transform(headlines[\"headline_text\"])\n",
"dt"
]
Expand All @@ -469,7 +469,7 @@
"metadata": {},
"outputs": [],
"source": [
"tfidf = TfidfVectorizer(stop_words=stopwords, min_df=2)\n",
"tfidf = TfidfVectorizer(stop_words=list(stopwords), min_df=2)\n",
"dt = tfidf.fit_transform(headlines[\"headline_text\"])\n",
"dt"
]
Expand All @@ -480,7 +480,7 @@
"metadata": {},
"outputs": [],
"source": [
"tfidf = TfidfVectorizer(stop_words=stopwords, min_df=.0001)\n",
"tfidf = TfidfVectorizer(stop_words=list(stopwords), min_df=.0001)\n",
"dt = tfidf.fit_transform(headlines[\"headline_text\"])\n",
"dt"
]
Expand All @@ -498,7 +498,7 @@
"metadata": {},
"outputs": [],
"source": [
"tfidf = TfidfVectorizer(stop_words=stopwords, max_df=0.1)\n",
"tfidf = TfidfVectorizer(stop_words=list(stopwords), max_df=0.1)\n",
"dt = tfidf.fit_transform(headlines[\"headline_text\"])\n",
"dt"
]
Expand Down Expand Up @@ -527,11 +527,11 @@
"metadata": {},
"outputs": [],
"source": [
"tfidf = TfidfVectorizer(stop_words=stopwords, ngram_range=(1,2), min_df=2)\n",
"tfidf = TfidfVectorizer(stop_words=list(stopwords), ngram_range=(1,2), min_df=2)\n",
"dt = tfidf.fit_transform(headlines[\"headline_text\"])\n",
"print(dt.shape)\n",
"print(dt.data.nbytes)\n",
"tfidf = TfidfVectorizer(stop_words=stopwords, ngram_range=(1,3), min_df=2)\n",
"tfidf = TfidfVectorizer(stop_words=list(stopwords), ngram_range=(1,3), min_df=2)\n",
"dt = tfidf.fit_transform(headlines[\"headline_text\"])\n",
"print(dt.shape)\n",
"print(dt.data.nbytes)"
Expand Down Expand Up @@ -575,7 +575,7 @@
"metadata": {},
"outputs": [],
"source": [
"tfidf = TfidfVectorizer(stop_words=stopwords)\n",
"tfidf = TfidfVectorizer(stop_words=list(stopwords))\n",
"dt = tfidf.fit_transform(headlines[\"lemmas\"].map(str))\n",
"dt"
]
Expand All @@ -586,7 +586,7 @@
"metadata": {},
"outputs": [],
"source": [
"tfidf = TfidfVectorizer(stop_words=stopwords)\n",
"tfidf = TfidfVectorizer(stop_words=list(stopwords))\n",
"dt = tfidf.fit_transform(headlines[\"nav\"].map(str))\n",
"dt"
]
Expand Down Expand Up @@ -634,7 +634,7 @@
"metadata": {},
"outputs": [],
"source": [
"tfidf = TfidfVectorizer(stop_words=stopwords, min_df=2)\n",
"tfidf = TfidfVectorizer(stop_words=list(stopwords), min_df=2)\n",
"dt = tfidf.fit_transform(headlines[\"lemmas\"].map(str))\n",
"dt"
]
Expand Down Expand Up @@ -690,7 +690,7 @@
"source": [
"# there are \"test\" headlines in the corpus\n",
"stopwords.add(\"test\")\n",
"tfidf = TfidfVectorizer(stop_words=stopwords, ngram_range=(1,2), min_df=2, norm='l2')\n",
"tfidf = TfidfVectorizer(stop_words=list(stopwords), ngram_range=(1,2), min_df=2, norm='l2')\n",
"dt = tfidf.fit_transform(headlines[\"headline_text\"])"
]
},
Expand Down Expand Up @@ -764,9 +764,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"metadata": {},
"outputs": [],
"source": [
"%%time\n",
Expand Down Expand Up @@ -841,7 +839,7 @@
"metadata": {},
"outputs": [],
"source": [
"tfidf_word = TfidfVectorizer(stop_words=stopwords, min_df=1000)\n",
"tfidf_word = TfidfVectorizer(stop_words=list(stopwords), min_df=1000)\n",
"dt_word = tfidf_word.fit_transform(headlines[\"headline_text\"])"
]
},
Expand Down Expand Up @@ -880,7 +878,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "blueprints",
"language": "python",
"name": "python3"
},
Expand All @@ -894,7 +892,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.12.8"
},
"toc": {
"base_numbering": 1,
Expand Down