]> code.communitydata.science - cdsc_reddit.git/blobdiff - clustering/fit_tsne.py
Merge branch 'master' of code:cdsc_reddit into excise_reindex
[cdsc_reddit.git] / clustering / fit_tsne.py
index 28b0fd30630e4a666d619974f321cffb4ba37470..55d72394c8fd32a13a4336463f636fc29a6bb4d3 100644 (file)
@@ -5,7 +5,7 @@ from numpy import random
 import numpy as np
 from sklearn.manifold import TSNE
 
-similarities = "term_similarities_10000.feather"
+similarities = "/gscratch/comdata/output/reddit_similarity/subreddit_author_tf_similarities_10000.parquet"
 
 def fit_tsne(similarities, output, learning_rate=750, perplexity=50, n_iter=10000, early_exaggeration=20):
     '''
@@ -17,7 +17,7 @@ def fit_tsne(similarities, output, learning_rate=750, perplexity=50, n_iter=1000
     df = pd.read_feather(similarities)
 
     n = df.shape[0]
-    mat = np.array(df.drop('subreddit',1),dtype=np.float64)
+    mat = np.array(df.drop('_subreddit',1),dtype=np.float64)
     mat[range(n),range(n)] = 1
     mat[mat > 1] = 1
     dist = 2*np.arccos(mat)/np.pi
@@ -26,7 +26,7 @@ def fit_tsne(similarities, output, learning_rate=750, perplexity=50, n_iter=1000
 
     tsne_fit_whole = tsne_fit_model.fit_transform(dist)
 
-    plot_data = pd.DataFrame({'x':tsne_fit_whole[:,0],'y':tsne_fit_whole[:,1], 'subreddit':df.subreddit})
+    plot_data = pd.DataFrame({'x':tsne_fit_whole[:,0],'y':tsne_fit_whole[:,1], '_subreddit':df['_subreddit']})
 
     plot_data.to_feather(output)
 

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