This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import random | |
import os | |
import tweepy | |
def get_auth(key_file): | |
consumer_key, consumer_secret, access_token, access_token_secret = open(key_file, 'r').readline().rstrip().split(' ') | |
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_token, access_token_secret) | |
return auth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from sklearn.feature_extraction.text import CountVectorizer | |
cv = CountVectorizer(analyzer='char_wb', ngram_range=(2,2), min_df = 0) | |
corpus = [u'私は男です私は', u'私は女です。'] | |
for text in corpus: | |
print text | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
from scipy.spatial import distance | |
from sklearn.cluster import DBSCAN | |
S = numpy.array([[0,0.9],[0.1,0.8],[0.9,0.1],[0.85,0.05],[0.9,0.05],[0.05,0.85],[0.5,0.4]]) | |
dbs = DBSCAN(eps=0.2, min_samples=3) | |
dbs.fit(S) | |
dbs.labels_ # => array([ 1., 1., 0., 0., 0., 1., -1.]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
twitter_timestamp_str = "Tue Apr 16 04:00:29 +0000 2013" | |
format_str = "%a %b %d %H:%M:%S +0000 %Y" | |
encoded_timestamp = time.strptime(twitter_timestamp_str, format_str) | |
print time.mktime(encoded_timestamp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nltk | |
text_str = "I have written this book and these papers." | |
text = nltk.word_tokenize(text_str) | |
result = nltk.pos_tag(text) | |
nouns = [r[0] for r in result if r[1] == 'NN' or r[1] == 'NNS'] |
NewerOlder