Skip to content

Instantly share code, notes, and snippets.

View fannix's full-sized avatar

fannix fannix

  • Peking University
  • Beijing
View GitHub Profile
@fannix
fannix / .vimrc
Created April 17, 2011 12:51
my vimrc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Sets how many lines of history VIM has to remember
set history=300
" Enable filetype plugin
filetype plugin on
filetype indent on
@fannix
fannix / kernel_ap.py
Created April 22, 2011 02:09
kernel affinity propagation with shotgun generated features
#!/usr/bin/env python2
from nltk.corpus.reader import TaggedCorpusReader
from nltk.tokenize import RegexpTokenizer
from shogun.Kernel import CommUlongStringKernel
from shogun.Features import StringUlongFeatures, StringCharFeatures, RAWBYTE
from shogun.PreProc import SortUlongString
from scikits.learn.cluster import affinity_propagation
import numpy as np
def read_reviews():
@fannix
fannix / xmonad.hs
Created April 24, 2011 01:31
xmonad
import XMonad
import Data.List
import XMonad.Hooks.ManageHelpers
import XMonad.Util.EZConfig
import XMonad.Config.Gnome
import XMonad.Config.Desktop (desktopLayoutModifiers)
import XMonad.Layout.NoBorders (smartBorders)
import XMonad.Layout.PerWorkspace (onWorkspace)
import XMonad.Layout.CenteredMaster (centerMaster)
import XMonad.Layout.SimpleFloat (simpleFloat)
@fannix
fannix / gist:1447153
Created December 8, 2011 14:39
nltk and sklearn
#!/usr/bin/env python2
import random
import nltk
from sklearn.linear_model import LogisticRegression
import numpy as np
from sklearn.feature_extraction.text import CountVectorizer
from nltk.corpus import movie_reviews
documents = [(movie_reviews.raw(fileid), category)
@fannix
fannix / cross_validation.py
Created December 10, 2011 15:08
cross validation
from sklearn.datasets import load_svmlight_file
from sklearn.naive_bayes import MultinomialNB
from sklearn.svm.sparse import LinearSVC
from sklearn.cross_validation import StratifiedKFold
from sklearn import metrics
import numpy as np
X, y = load_svmlight_file("fr.vec")
y[y == -1] = 0
kf = StratifiedKFold(y, k = 10, indices=True)
@fannix
fannix / nb_cross_validation.py
Created December 15, 2011 10:15
Naive Bayes with sparse matrix with Stratified KFold cross validation
from sklearn.datasets import load_svmlight_file
from sklearn.naive_bayes import MultinomialNB
from sklearn.cross_validation import StratifiedKFold
from sklearn import metrics
X, y = load_svmlight_file("mpqa_en.vec")
kf = StratifiedKFold(y, k = 10, indices=True)
clf = MultinomialNB()
for train_index, test_index in kf:
X_train, X_test = X[train_index], X[test_index]
y_train, y_test = y[train_index], y[test_index]
@fannix
fannix / about.md
Created March 28, 2012 01:32 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer
@fannix
fannix / lingpipe_segmenter.py
Created November 17, 2012 00:43
Stanford Tagger Jython Wrapper
#encoding:utf-8
from java.io import FileInputStream
from java.io import ObjectInputStream
import sys
jarfiles = ["/opt/lingpipe-segmenter/lingpipe-4.0.1.jar", "/opt/lingpipe-segmenter/zhToksDemo.jar"]
for jar in jarfiles:
if jar not in sys.path:
sys.path.append(jar)
@fannix
fannix / edge_list_to_vna.py
Created November 23, 2012 02:33
networkX and graph util
"""
convert an edge list to the graph VNA format.
VNA format can be read and visualized by Gephi
"""
import sys
def edge_list_to_vna(edge_list):
"""edge_list is a list of 3-tuples: [from, to, weight]
@fannix
fannix / redis.py
Created November 30, 2012 07:44
Redis
r = redis.StrictRedis(host='127.0.0.1', port=6379, db=0)
r.get('users:leto')