]> code.communitydata.science - cdsc_reddit.git/blob - similarities/cosine_similarities.py
add note to try other tf normalization strategies.
[cdsc_reddit.git] / similarities / cosine_similarities.py
1 import pandas as pd
2 import fire
3 from pathlib import Path
4 from similarities_helper import similarities, column_similarities
5
6 def cosine_similarities(infile, term_colname, outfile, min_df=None, max_df=None, included_subreddits=None, topN=500, exclude_phrases=False, from_date=None, to_date=None, tfidf_colname='tf_idf'):
7
8     return similarities(infile=infile, simfunc=column_similarities, term_colname=term_colname, outfile=outfile, min_df=min_df, max_df=max_df, included_subreddits=included_subreddits, topN=topN, exclude_phrases=exclude_phrases,from_date=from_date, to_date=to_date, tfidf_colname=tfidf_colname)
9
10
11 def term_cosine_similarities(outfile, infile='/gscratch/comdata/output/reddit_similarity/tfidf/comment_terms_100k.parquet', min_df=None, max_df=None, included_subreddits=None, topN=500, exclude_phrases=False, from_date=None, to_date=None):
12
13     return cosine_similarities(infile,
14                                'term',
15                                outfile,
16                                min_df,
17                                max_df,
18                                included_subreddits,
19                                topN,
20                                exclude_phrases,
21                                from_date,
22                                to_date
23                                )
24
25 def author_cosine_similarities(outfile, infile='/gscratch/comdata/output/reddit_similarity/tfidf/comment_authors_100k.parquet', min_df=2, max_df=None, included_subreddits=None, topN=10000, from_date=None, to_date=None):
26     return cosine_similarities(infile,
27                                'author',
28                                outfile,
29                                min_df,
30                                max_df,
31                                included_subreddits,
32                                topN,
33                                exclude_phrases=False,
34                                from_date=from_date,
35                                to_date=to_date
36                                )
37
38 def author_tf_similarities(outfile, infile='/gscratch/comdata/output/reddit_similarity/tfidf/comment_authors_100k.parquet', min_df=2, max_df=None, included_subreddits=None, topN=10000, from_date=None, to_date=None):
39     return cosine_similarities(infile,
40                                'author',
41                                outfile,
42                                min_df,
43                                max_df,
44                                included_subreddits,
45                                topN,
46                                exclude_phrases=False,
47                                from_date=from_date,
48                                to_date=to_date,
49                                tfidf_colname='relative_tf'
50                                )
51
52
53 if __name__ == "__main__":
54     fire.Fire({'term':term_cosine_similarities,
55                'author':author_cosine_similarities,
56                'author-tf':author_tf_similarities})
57

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