]> code.communitydata.science - cdsc_reddit.git/blob - similarities/lsi_similarities.py
refactor clustring in object oriented style
[cdsc_reddit.git] / similarities / lsi_similarities.py
1 import pandas as pd
2 import fire
3 from pathlib import Path
4 from similarities_helper import similarities, lsi_column_similarities
5 from functools import partial
6
7 def lsi_similarities(infile, term_colname, outfile, min_df=None, max_df=None, included_subreddits=None, topN=500, from_date=None, to_date=None, tfidf_colname='tf_idf',n_components=100,n_iter=5,random_state=1968,algorithm='arpack'):
8     print(n_components,flush=True)
9
10     simfunc = partial(lsi_column_similarities,n_components=n_components,n_iter=n_iter,random_state=random_state,algorithm=algorithm)
11
12     return similarities(infile=infile, simfunc=simfunc, term_colname=term_colname, outfile=outfile, min_df=min_df, max_df=max_df, included_subreddits=included_subreddits, topN=topN, from_date=from_date, to_date=to_date, tfidf_colname=tfidf_colname)
13
14 # change so that these take in an input as an optional argument (for speed, but also for idf).
15 def term_lsi_similarities(outfile, min_df=None, max_df=None, included_subreddits=None, topN=500, from_date=None, to_date=None, n_components=300,n_iter=5,random_state=1968,algorithm='arpack'):
16
17     return lsi_similarities('/gscratch/comdata/output/reddit_similarity/tfidf/comment_terms_100k.parquet',
18                             'term',
19                             outfile,
20                             min_df,
21                             max_df,
22                             included_subreddits,
23                             topN,
24                             from_date,
25                             to_date,
26                             n_components=n_components
27                             )
28
29 def author_lsi_similarities(outfile, min_df=2, max_df=None, included_subreddits=None, topN=10000, from_date=None, to_date=None,n_components=300,n_iter=5,random_state=1968,algorithm='arpack'):
30     return lsi_similarities('/gscratch/comdata/output/reddit_similarity/tfidf/comment_authors_100k.parquet',
31                             'author',
32                             outfile,
33                             min_df,
34                             max_df,
35                             included_subreddits,
36                             topN,
37                             from_date=from_date,
38                             to_date=to_date,
39                             n_components=n_components
40                                )
41
42 def author_tf_similarities(outfile, min_df=2, max_df=None, included_subreddits=None, topN=10000, from_date=None, to_date=None,n_components=300,n_iter=5,random_state=1968,algorithm='arpack'):
43     return lsi_similarities('/gscratch/comdata/output/reddit_similarity/tfidf/comment_authors_100k.parquet',
44                             'author',
45                             outfile,
46                             min_df,
47                             max_df,
48                             included_subreddits,
49                             topN,
50                             from_date=from_date,
51                             to_date=to_date,
52                             tfidf_colname='relative_tf',
53                             n_components=n_components
54                             )
55
56
57 if __name__ == "__main__":
58     fire.Fire({'term':term_lsi_similarities,
59                'author':author_lsi_similarities,
60                'author-tf':author_tf_similarities})
61

Community Data Science Collective || Want to submit a patch?