Code Monkey home page Code Monkey logo

fic-prototype's Introduction

fic-prototype

Python implementation of BNS for Bi-Normal Separation, a high performance alternative to Tf-Idf scoring for text classification.

BnsTransformer and BnsVectorizer are structured to be used with Scikit-Learn.

Implemented to follow the Scikit-learn convention and usage pattern:

corpus = "/path/to/text/corpus" #note: positive and negative docs are in seperate folders
label_names = ['positive', 'negative']

textfiles = load_files(corpus, categories=label_names, load_content=False)
data = [cs.open(filename, 'r', 'UTF-8').read() for filename in notices.filenames]

#Tokenize and get counts for all documents, becomes a numpy data structure
#in a format suitable for scikit-learn
countVec = CountVectorizer(stop_words="english", binary=True,
                           ngram_range=(1, 1), strip_accents='unicode')
X = countVec.fit_transform(data)
Y = texfiles.target       

#the counts are now used to compute the BNS score, we are ready to classify/cluster/whatever
vocab = countVec.vocabulary_
bns = BnsTransformer(y=Y, vocab=vocab)
X_bns = bns.transform(X)

Reference: BNS Feature Scaling: An Improved Representation over TF·IDF for SVM Text Classification. G. Forman. CIKM'08. HPL-2007-32R1. link to paper: http://www.hpl.hp.com/techreports/2007/HPL-2007-32R1.html

fic-prototype's People

Contributors

dumoulma avatar npow avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.