Skip to content

Instantly share code, notes, and snippets.

View Proteusiq's full-sized avatar

Prayson Wilfred Daniel Proteusiq

View GitHub Profile
# CoffeeScript version of Google Spreadsheet Driver for Tableau Data Web Connector
init = ->
if !tableau
alert 'init- tableau NOT defined!'
return
tableau.scriptVersion = '1.0'
tableau.log 'init'
tableau.initCallback()
from gensim.models import KeyedVectors
# Load gensim word2vec
w2v_path = '<Gensim File Path>'
w2v = KeyedVectors.load_word2vec_format(w2v_path)
import io
# Vector file, `\t` seperated the vectors and `\n` seperate the words
"""
from sklearn.feature_extraction.text import TfidfVectorizer, CountVectorizer
from sklearn.decomposition import NMF, LatentDirichletAllocation
import numpy as np
def display_topics(H, W, feature_names, documents, no_top_words, no_top_documents):
for topic_idx, topic in enumerate(H):
print "Topic %d:" % (topic_idx)
print " ".join([feature_names[i]
for i in topic.argsort()[:-no_top_words - 1:-1]])
top_doc_indices = np.argsort( W[:,topic_idx] )[::-1][0:no_top_documents]
@benrules2
benrules2 / Markov.py
Created January 5, 2017 23:35
Markov Chain message generator
import random
import sys
def build_chain(text, chain = {}):
words = text.split(' ')
index = 1
for word in words[index:]:
key = words[index - 1]
if key in chain:
chain[key].append(word)