Permalink
Browse files

Merge branch 'master' of github.com:cathywu/Sentiment-Analysis

Conflicts:
	ngrams.py
	validate.py
  • Loading branch information...
2 parents 9d738a5 + 718dfff commit f0d6be960b0c90884d3bd92a6caa035d209758b5 @pranjalv123 pranjalv123 committed Jan 11, 2012
View
2 classifier.py 100644 → 100755
@@ -1,3 +1,5 @@
+#!/usr/bin/python
+
import random
import data
from numpy import *
View
0 data.py 100644 → 100755
No changes.
View
2 movie.py 100644 → 100755
@@ -1,3 +1,5 @@
+#!/usr/bin/python
+
import data
import ngrams
import validate
View
19 ngrams.py 100644 → 100755
@@ -1,6 +1,9 @@
+#!/usr/bin/python
+
import collections
import data
from numpy import *
+
from scipy.sparse import lil_matrix, csr_matrix
def words(s):
words = []
@@ -61,16 +64,16 @@ def ngrams_to_dictionary(grams):
def ngrams_to_matrix(grams, classes):
- print "a"
+ print "Entering ngrams_to_matrix"
keysets = [set(k) for k in grams]
allgramset = set()
print "b"
allgramset = apply(allgramset.union, keysets)
print "c"
allgrams = list(allgramset)
- print "d"
+ print "> Listed"
vecs = []
- print "e"
+ print "> []"
allgramsdict = {}
for i in range(len(allgrams)):
allgramsdict[allgrams[i]] = i
@@ -126,10 +129,12 @@ def ngram_vector(n, s, dictionary, allgramsdict = {}):
return array(vec)
if __name__ == "__main__":
- print ngrams(3, "Now is the time for all good men to not come to the aid of their party! Now is the time for all bad women to leave the aid of their country? This, being war, is bad")
+ print "Trigram example: %s" % ngrams(3, "Now is the time for all good men to not come to the aid of their party! Now is the time for all bad women to leave the aid of their country? This, being war, is bad")
g1 = ngrams(1, "Hello how are you")
g2 = ngrams(1, "Are you feeling well")
g3 = ngrams(1, "Well hello there")
- print g3
- print ngram_vector(1, "how are you today", ["how", "seven", "today", "three"])
- print ngrams_to_matrix([g1, g2, g3], [1, 2, 1]).asMatrix()
+
+
+ print "Unigram example: %s" % g3
+ print "Matrix example: %s" % ngrams_to_matrix([g1, g2, g3], [1, 2, 1]).asMatrix()
+
@@ -0,0 +1,5 @@
+repo: ca168779ff303e9b1e4d234628ccce62aec13c58
+node: ebd93ccda8c4159f9af0db6e758a9c26b580203d
+branch: default
+latesttag: null
+latesttagdistance: 19
@@ -0,0 +1,9 @@
+syntax: glob
+build
+*.patch
+*.pyc
+*.log
+*.so
+*.so.old
+*.swp
+*.dat
View
@@ -0,0 +1,65 @@
+PySVMLight
+==========
+
+A Python binding to the [SVM-Light](http://svmlight.joachims.org/) support vector machine library by Thorsten Joachims.
+
+Written by Bill Cauchois (<wcauchois@gmail.com>), with thanks to Lucas Beyer and n0mad for their contributions.
+
+Installation
+------------
+PySVMLight uses distutils for setup. Installation is as simple as
+
+ $ chmod +x setup.py
+ $ ./setup.py --help
+ $ ./setup.py build
+
+If you want to install SVMLight to your PYTHONPATH, type:
+
+ $ ./setup.py install
+
+(You may need to execute this command as the superuser.) Otherwise, look in the build/ directory to find svmlight.so and copy that file to the directory of your project. You should now be able to `import svmlight`.
+
+Getting Started
+---------------
+See examples/simple.py for example usage.
+
+Reference
+---------
+
+If you type `help(svmlight)`, you will see that there are currently three functions.
+
+ learn(training_data, **options) -> model
+
+Train a model based on a set of training data. The training data should be in the following format:
+
+ >> (<label>, [(<feature>, <value>), ...])
+
+or
+
+ >> (<label>, [(<feature>, <value>), ...], <queryid>)
+
+See examples/data.py for an example of some training data. Available options include (corresponding roughly to the command-line options for `svmlight` detailed on [this page](http://svmlight.joachims.org/) under the section titled "How to use"):
+
+ - `type`: select between 'classification', 'regression', 'ranking' (preference ranking), and 'optimization'.
+ - `kernel`: select between 'linear', 'polynomial', 'rbf', and 'sigmoid'.
+ - `verbosity`: set the verbosity level (default 0).
+ - `C`: trade-off between training error and margin.
+ - `poly_degree`: parameter d in polynomial kernel.
+ - `rbf_gamma`: parameter gamma in rbf kernel.
+ - `coef_lin`
+ - `coef_const`
+
+The result of this call is a model that you can pass to classify().
+
+ classify(model, test_data, **options) -> predictions
+
+Classify a set of test data using the provided model. The test data should be in the same format as training data (see above). The result will be a list of floats, corresponding to predicted labels for each of the test instances.
+
+ write_model(model, filename) -> None
+
+Write the provided model to the specified file. The file format used is the same format as that used by the command-line `svmlight` program.
+
+ read_model(filename) -> model
+
+Read a model that was saved using write_model().
+
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.

0 comments on commit f0d6be9

Please sign in to comment.