svmredlight 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ module SVMLight
2
+ # A document is the Ruby representation of a DOC structure in SVMlight, it contains a
3
+ # queryid, a slackid, a costfactor ( c ) and a vector with feature numbers and their
4
+ # correspondent weights.
5
+ class Document
6
+
7
+ # @param [Hash] vector a hash where the keys are feature numbers and the values its weights
8
+ # @param [Hash] opts the options coincide with SVMLight parameters to the create_example function, the default values for all the options are 0
9
+ # @option [:docnum] Numeric docum
10
+ # @option [:costfactor] Numeric costfactor
11
+ # @option [:slackid] Numeric slackid
12
+ # @option [:queryid] Numeric queryid
13
+ def self.new(vector, opts={})
14
+ opts.default = 0
15
+ docnum = opts[:docnum]
16
+ costfactor = opts[:costfactor]
17
+ slackid = opts[:slackid]
18
+ queryid = opts[:queryid]
19
+
20
+ create(docnum, costfactor, slackid, queryid, vector.to_a)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ module SVMLight
2
+ # A model is the product of training a SVM, once created it can take documents as inputs
3
+ # and act of them (by for instance classifying them). Models can also be read from files
4
+ # created by svm_learn.
5
+ class Model
6
+ TYPES = [:classification]
7
+
8
+ # Learns a model from a set of labeled documents.
9
+ # @param [Symbol] type, what kind of model is this, classification, regression, etc. for now the only valid value is classification.
10
+ # @param [Array] documents_and_lables documents and labels is an array of arrays where each inner array must have two elements, the first, a Document and the second a classification (normally +1 and -1)
11
+ # @param [Hash] learn_params each key of learn_params is a string it that maps to a field of the LEARN_PARM struct in SVMLight
12
+ # @param [Hash] kernel_params each key of kernel_params is a string it that maps to a field of the KERNEL_PARM struct in SVMLight
13
+ # @param [Array|Nil] alphas an array of alpha values
14
+ def self.new(type, documents_and_lables, learn_params, kernel_params, alphas = nil )
15
+ raise ArgumentError, "Supporte types are (for now) #{TYPES}" unless TYPES.include? type
16
+
17
+ learn_classification(documents_and_lables, learn_params, kernel_params, false, alphas)
18
+ end
19
+
20
+ private_class_method :learn_classification
21
+ end
22
+ end
@@ -0,0 +1,4 @@
1
+ require File.dirname(__FILE__) + '/../ext/svmredlight'
2
+ require 'svmredlight/model'
3
+ require 'svmredlight/document'
4
+
@@ -0,0 +1,73 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{svmredlight}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Camilo Lopez"]
12
+ s.date = %q{2011-09-11}
13
+ s.description = %q{Ruby interface to SVMLight}
14
+ s.email = %q{camilo@camilolopez.com}
15
+ s.extensions = ["ext/extconf.rb"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "examples/example1/example.rb",
29
+ "examples/example1/test.dat",
30
+ "examples/example1/train.dat",
31
+ "examples/example1/words",
32
+ "ext/extconf.rb",
33
+ "ext/svmredlight.c",
34
+ "lib/svmredlight.rb",
35
+ "lib/svmredlight/document.rb",
36
+ "lib/svmredlight/model.rb",
37
+ "svmredlight.gemspec",
38
+ "test/assets/model",
39
+ "test/helper.rb",
40
+ "test/test_document.rb",
41
+ "test/test_model.rb"
42
+ ]
43
+ s.homepage = %q{http://github.com/camilo/svmredlight}
44
+ s.licenses = ["MIT"]
45
+ s.require_paths = ["lib"]
46
+ s.rubygems_version = %q{1.5.0}
47
+ s.summary = %q{Ruby interface to SVMLight}
48
+
49
+ if s.respond_to? :specification_version then
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
54
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
55
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
56
+ s.add_development_dependency(%q<ZenTest>, [">= 0"])
57
+ s.add_development_dependency(%q<ruby-debug19>, [">= 0"])
58
+ else
59
+ s.add_dependency(%q<shoulda>, [">= 0"])
60
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
61
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
62
+ s.add_dependency(%q<ZenTest>, [">= 0"])
63
+ s.add_dependency(%q<ruby-debug19>, [">= 0"])
64
+ end
65
+ else
66
+ s.add_dependency(%q<shoulda>, [">= 0"])
67
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
68
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
69
+ s.add_dependency(%q<ZenTest>, [">= 0"])
70
+ s.add_dependency(%q<ruby-debug19>, [">= 0"])
71
+ end
72
+ end
73
+