]> code.communitydata.science - cdsc_reddit.git/blob - similarities/cosine_similarities.py
bug fix in affinity clustering
[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 from functools import partial
6
7 def cosine_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'):
8
9     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, from_date=from_date, to_date=to_date, tfidf_colname=tfidf_colname)
10
11 # change so that these take in an input as an optional argument (for speed, but also for idf).
12 def term_cosine_similarities(outfile, min_df=None, max_df=None, included_subreddits=None, topN=500, exclude_phrases=False, from_date=None, to_date=None):
13
14     return cosine_similarities('/gscratch/comdata/output/reddit_similarity/tfidf/comment_terms_100k.parquet',
15                                'term',
16                                outfile,
17                                min_df,
18                                max_df,
19                                included_subreddits,
20                                topN,
21                                from_date,
22                                to_date
23                                )
24
25 def author_cosine_similarities(outfile, min_df=2, max_df=None, included_subreddits=None, topN=10000, from_date=None, to_date=None):
26     return cosine_similarities('/gscratch/comdata/output/reddit_similarity/tfidf/comment_authors_100k.parquet',
27                                'author',
28                                outfile,
29                                min_df,
30                                max_df,
31                                included_subreddits,
32                                topN,
33                                from_date=from_date,
34                                to_date=to_date
35                                )
36
37 def author_tf_similarities(outfile, min_df=2, max_df=None, included_subreddits=None, topN=10000, from_date=None, to_date=None):
38     return cosine_similarities('/gscratch/comdata/output/reddit_similarity/tfidf/comment_authors_100k.parquet',
39                                'author',
40                                outfile,
41                                min_df,
42                                max_df,
43                                included_subreddits,
44                                topN,
45                                from_date=from_date,
46                                to_date=to_date,
47                                tfidf_colname='relative_tf'
48                                )
49
50
51 if __name__ == "__main__":
52     fire.Fire({'term':term_cosine_similarities,
53                'author':author_cosine_similarities,
54                'author-tf':author_tf_similarities})
55

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