-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_lda.py
49 lines (37 loc) · 1.25 KB
/
build_lda.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#%%
import pandas as pd
from pymongo import MongoClient
from bson.objectid import ObjectId
import pymongo
from eBayPriceEstimator import ebaypriceestimator as epe
import importlib
# Enable logging for gensim - optional
import logging
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.ERROR)
import warnings
warnings.filterwarnings("ignore",category=DeprecationWarning)
warnings.filterwarnings("ignore",category=UserWarning)
import time
start_time = time.time()
# import myfuncs as myfn
# Mongo DB info
client = MongoClient()
db = client['ebay-db']
ebay_items_collection = db['ebay_items']
ebay_searches_collection = db['ebay_searches']
ebi = ebay_items_collection
ebs = ebay_searches_collection
from gensim import models
category_id = 177831
c = ebi.find({ "$or": [{ 'PrimaryCategoryID': str(category_id) ,
'ListingStatus' : 'Completed'
}]}, )#.limit(1000)
df = pd.DataFrame.from_records(c) #.iloc[0:2000]
#importlib.reload(epe)
texts = df.Description.to_list()
num_of_topics = 6
lda_model = epe.build_lda_model_from_text(texts,num_of_topics)
model_fname = 'lda_' + str(num_of_topics) + '.model'
lda_model.save(model_fname)
print("--- %s seconds ---" % (time.time() - start_time))
#%%