Skip to content

Commit 343b512

Browse files
committed
Code files added
1 parent a5210a1 commit 343b512

48 files changed

Lines changed: 1634128 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Lesson5/Activity10.ipynb

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Jeopardy Topics"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": null,
13+
"metadata": {},
14+
"outputs": [
15+
{
16+
"name": "stderr",
17+
"output_type": "stream",
18+
"text": [
19+
"C:\\Users\\dwight\\Anaconda3\\envs\\packt\\lib\\site-packages\\gensim\\utils.py:1212: UserWarning: detected Windows; aliasing chunkize to chunkize_serial\n",
20+
" warnings.warn(\"detected Windows; aliasing chunkize to chunkize_serial\")\n"
21+
]
22+
}
23+
],
24+
"source": [
25+
"import pandas as pd\n",
26+
"pd.set_option('display.max_colwidth', 800)\n",
27+
"\n",
28+
"\n",
29+
"JEOPARDY_CSV = 'data/jeopardy/Jeopardy.csv'\n",
30+
"\n",
31+
"questions = pd.read_csv(JEOPARDY_CSV)\n",
32+
"\n",
33+
"questions = questions.dropna(subset=['Question'])\n",
34+
"\n",
35+
"\n",
36+
"\n",
37+
"from gensim.parsing.preprocessing import preprocess_string\n",
38+
"ques_documents = questions.Question.apply(preprocess_string).tolist()\n",
39+
"\n",
40+
"from gensim import corpora\n",
41+
"from gensim.models.ldamodel import LdaModel\n",
42+
"\n",
43+
"dictionary = corpora.Dictionary(ques_documents)\n",
44+
"corpus = [dictionary.doc2bow(text) for text in ques_documents]\n",
45+
"\n",
46+
"\n",
47+
"\n",
48+
"NUM_TOPICS = 8\n",
49+
"ldamodel = LdaModel(corpus, num_topics = NUM_TOPICS, id2word=dictionary, passes=15)\n",
50+
"\n",
51+
"\n",
52+
"ldamodel.print_topics(num_words=6)\n"
53+
]
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": null,
58+
"metadata": {},
59+
"outputs": [],
60+
"source": []
61+
}
62+
],
63+
"metadata": {
64+
"kernelspec": {
65+
"display_name": "Python [conda env:packt]",
66+
"language": "python",
67+
"name": "conda-env-packt-py"
68+
},
69+
"language_info": {
70+
"codemirror_mode": {
71+
"name": "ipython",
72+
"version": 3
73+
},
74+
"file_extension": ".py",
75+
"mimetype": "text/x-python",
76+
"name": "python",
77+
"nbconvert_exporter": "python",
78+
"pygments_lexer": "ipython3",
79+
"version": "3.7.2"
80+
}
81+
},
82+
"nbformat": 4,
83+
"nbformat_minor": 2
84+
}

0 commit comments

Comments
 (0)