eureka 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Bjørn Arild Mæland
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,25 @@
1
+ = Eureka
2
+
3
+ JRuby wrapper for Weka 3 (http://www.cs.waikato.ac.nz/ml/weka/).
4
+
5
+ Targets Weka 3.6.1, but it should work with earlier versions. Make sure to have
6
+ weka.jar on your CLASSPATH.
7
+
8
+ For examples of usage, look at the specs.
9
+
10
+ Created by Bjørn Arild Mæland [github.com/Chrononaut]
11
+
12
+ == Note on Patches/Pull Requests
13
+
14
+ * Fork the project.
15
+ * Make your feature addition or bug fix.
16
+ * Add tests for it. This is important so I don't break it in a
17
+ future version unintentionally.
18
+ * Commit, do not mess with rakefile, version, or history.
19
+ (if you want to have your own version, that is fine but
20
+ bump version in a commit by itself I can ignore when I pull)
21
+ * Send me a pull request. Bonus points for topic branches.
22
+
23
+ == Copyright
24
+
25
+ Copyright (c) 2009 Bjørn Arild Mæland. See LICENSE for details.
@@ -0,0 +1,40 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "rake"
3
+ require "spec/rake/spectask"
4
+ require 'jeweler'
5
+
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "eureka"
8
+ gem.version = "0.0.1"
9
+ gem.summary = "Use Weka from JRuby"
10
+ gem.description = "Weka wrapper for JRuby"
11
+ gem.email = "bjorn.maeland@gmail.com"
12
+ gem.homepage = "http://github.com/Chrononaut/eureka"
13
+ gem.authors = ["Bjørn Arild Mæland"]
14
+ gem.add_development_dependency "rspec", ">= 1.2.9"
15
+ end
16
+
17
+ Jeweler::GemcutterTasks.new
18
+
19
+ Spec::Rake::SpecTask.new(:spec) do |spec|
20
+ spec.libs << 'lib' << 'spec'
21
+ spec.spec_files = FileList['spec/*_spec.rb']
22
+ end
23
+
24
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
25
+ spec.libs << 'lib' << 'spec'
26
+ spec.pattern = 'spec/*_spec.rb'
27
+ spec.rcov = true
28
+ end
29
+
30
+ task :default => :spec
31
+
32
+ require 'rake/rdoctask'
33
+ Rake::RDocTask.new do |rdoc|
34
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
35
+
36
+ rdoc.rdoc_dir = 'rdoc'
37
+ rdoc.title = "eureka #{version}"
38
+ rdoc.rdoc_files.include('README*')
39
+ rdoc.rdoc_files.include('lib/**/*.rb')
40
+ end
@@ -0,0 +1,8 @@
1
+ require "java"
2
+
3
+ # weka.jar must be on your CLASSPATH
4
+ require "weka.jar"
5
+
6
+ $:.unshift(here = File.dirname(__FILE__))
7
+
8
+ require "eureka/core"
@@ -0,0 +1,79 @@
1
+ # Core extensions
2
+ class Array
3
+ def to_fast_vector
4
+ FastVector.new(self)
5
+ end
6
+ end
7
+
8
+ # Eureka
9
+ module Eureka
10
+ import "weka.core.Attribute"
11
+ import "weka.core.FastVector"
12
+ import "weka.core.Instances"
13
+ end
14
+
15
+ module Java::WekaCore
16
+
17
+ class Attribute
18
+ alias :[] :value
19
+ end
20
+
21
+ class FastVector
22
+
23
+ include Enumerable
24
+
25
+ def initialize(int_or_array=0)
26
+ if int_or_array.kind_of?(Fixnum)
27
+ super(int_or_array)
28
+ else
29
+ super(int_or_array.size)
30
+ int_or_array.each { |arg| self.add_element(arg) }
31
+ end
32
+ end
33
+
34
+ alias :length :size
35
+ alias :first :first_element
36
+ alias :last :last_element
37
+ alias :<< :add_element
38
+ alias :[] :element_at
39
+ alias :include? :contains
40
+
41
+ def each
42
+ size.times { |i| yield self[i] }
43
+ end
44
+
45
+ end
46
+
47
+ class Instances
48
+
49
+ include Enumerable
50
+
51
+ class << self
52
+ # Reads in instances using the standard Weka ARFF format
53
+ def from_arff(path)
54
+ data = self.new(java.io.BufferedReader.new(java.io.FileReader.new(path)))
55
+ data.set_class_index(data.num_attributes - 1)
56
+ return data
57
+ end
58
+
59
+ # http://weka.sourceforge.net/doc/weka/core/converters/C45Loader.html
60
+ def from_c45
61
+ raise
62
+ end
63
+
64
+ # http://weka.sourceforge.net/doc/weka/core/converters/CSVLoader.html
65
+ def from_csv
66
+ raise
67
+ end
68
+ end
69
+
70
+ alias :<< :add
71
+ alias :[] :instance
72
+
73
+ def each
74
+ num_instances.times { |i| yield self[i] }
75
+ end
76
+
77
+ end
78
+
79
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Weka Core" do
4
+ describe "FastVector" do
5
+ before(:all) do
6
+ @fv = FastVector.new(("a".."z").to_a)
7
+ end
8
+
9
+ it "should have Ruby-like aliases"do
10
+ @fv.length.should == @fv.size
11
+ @fv.first.should == @fv.first_element
12
+ @fv.last.should == @fv.last_element
13
+ end
14
+
15
+ it "should instanciate from an array" do
16
+ FastVector.new(("a".."z").to_a).length.should == 26
17
+ end
18
+
19
+ it "should know if it includes a specific element" do
20
+ @fv.include?("a").should be_true
21
+ @fv.include?("1").should be_false
22
+ @fv[0].should == "a"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ @relation stock
2
+
3
+ @attribute percent_change_since_open real
4
+ @attribute percent_change_from_day_low real
5
+ @attribute percent_change_from_day_high real
6
+ @attribute action {buy, sell, hold}
7
+
8
+ @data
9
+ -0.21,0.05,-0.2,hold
10
+ -2.1,0.1,-2.3,sell
11
+ 0.23,0.18,-0.04,buy
12
+ -0.24,0.16,-0.15,hold
13
+ -2.5,-0.1,-2.2,sell
14
+ 0.31,0.29,-0.1,buy
15
+ -0.19,0.04,-0.18,hold
16
+ -2.7,0.4,-2.4,sell
17
+ 0.21,0.28,-0.08,buy
@@ -0,0 +1,17 @@
1
+ @relation stock
2
+
3
+ @attribute percent_change_since_open real
4
+ @attribute percent_change_from_day_low real
5
+ @attribute percent_change_from_day_high real
6
+ @attribute action {buy, sell, hold}
7
+
8
+ @data
9
+ -0.2,0.1,-0.22,hold
10
+ -2.2,0.0,-2.5,sell
11
+ 0.2,0.21,-0.01,buy
12
+ -0.22,0.12,-0.25,hold
13
+ -2.0,0.0,-2.1,sell
14
+ 0.28,0.26,-0.04,buy
15
+ -0.12,0.08,-0.14,hold
16
+ -2.6,0.1,-2.6,sell
17
+ 0.24,0.25,-0.03,buy
@@ -0,0 +1,47 @@
1
+ @relation xor
2
+
3
+ @attribute x {TRUE, FALSE}
4
+ @attribute y {TRUE, FALSE}
5
+ @attribute xor {TRUE, FALSE}
6
+
7
+ @data
8
+ FALSE,FALSE,FALSE
9
+ FALSE,TRUE,TRUE
10
+ TRUE,FALSE,TRUE
11
+ TRUE,TRUE,FALSE
12
+ FALSE,FALSE,FALSE
13
+ FALSE,TRUE,TRUE
14
+ TRUE,FALSE,TRUE
15
+ TRUE,TRUE,FALSE
16
+ FALSE,FALSE,FALSE
17
+ FALSE,TRUE,TRUE
18
+ TRUE,FALSE,TRUE
19
+ TRUE,TRUE,FALSE
20
+ FALSE,FALSE,FALSE
21
+ FALSE,TRUE,TRUE
22
+ TRUE,FALSE,TRUE
23
+ TRUE,TRUE,FALSE
24
+ FALSE,FALSE,FALSE
25
+ FALSE,TRUE,TRUE
26
+ TRUE,FALSE,TRUE
27
+ TRUE,TRUE,FALSE
28
+ FALSE,FALSE,FALSE
29
+ FALSE,TRUE,TRUE
30
+ TRUE,FALSE,TRUE
31
+ TRUE,TRUE,FALSE
32
+ FALSE,FALSE,FALSE
33
+ FALSE,TRUE,TRUE
34
+ TRUE,FALSE,TRUE
35
+ TRUE,TRUE,FALSE
36
+ FALSE,FALSE,FALSE
37
+ FALSE,TRUE,TRUE
38
+ TRUE,FALSE,TRUE
39
+ TRUE,TRUE,FALSE
40
+ FALSE,FALSE,FALSE
41
+ FALSE,TRUE,TRUE
42
+ TRUE,FALSE,TRUE
43
+ TRUE,TRUE,FALSE
44
+ FALSE,FALSE,FALSE
45
+ FALSE,TRUE,TRUE
46
+ TRUE,FALSE,TRUE
47
+ TRUE,TRUE,FALSE
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'eureka'
5
+ require "spec"
6
+ require 'spec/autorun'
7
+
8
+ Spec::Runner.configure do |config|
9
+
10
+ end
11
+
12
+ include Eureka
@@ -0,0 +1,42 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ import "weka.classifiers.meta.FilteredClassifier"
4
+ import "weka.classifiers.trees.J48"
5
+ import "weka.filters.unsupervised.attribute.Remove"
6
+
7
+ describe "Stock data example" do
8
+
9
+ before(:all) do
10
+ @training_data = Instances.from_arff(File.dirname(__FILE__) +
11
+ "/data/stock_training_data.arff")
12
+ @testing_data = Instances.from_arff(File.dirname(__FILE__) +
13
+ "/data/stock_testing_data.arff")
14
+ end
15
+
16
+ it "should know the number of attributes and instances in model" do
17
+ @training_data.num_attributes.should == 4
18
+ @training_data.num_instances.should == 9
19
+ end
20
+
21
+ it "should build and test a classifier" do
22
+
23
+ rm = Remove.new # Filter for removing samples
24
+ rm.set_attribute_indices("1") # Remove 1st attribute
25
+
26
+ fc = FilteredClassifier.new
27
+ fc.set_filter(rm)
28
+ fc.set_classifier(J48.new) # A classifier for decision trees
29
+ fc.build_classifier(@training_data) # Train the classifier
30
+
31
+ # Test using stock_testing_data.arff:
32
+ @testing_data.to_a[0..2].each do |instance|
33
+ predicted = fc.classify_instance(instance).to_i
34
+ given = instance.class_value.to_i
35
+ given.should == predicted
36
+ #print "given value: #{@testing_data.class_attribute[given]}"
37
+ #puts ". predicted value: #{@testing_data.class_attribute[predicted]}"
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,28 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ import "weka.classifiers.lazy.IBk"
4
+
5
+ describe "XOR example" do
6
+
7
+ before(:all) do
8
+ @training_data = Instances.from_arff(File.dirname(__FILE__) +
9
+ "/data/xor.arff")
10
+ end
11
+
12
+ it "should build and test a classifier" do
13
+ # Uses the IBk K-nearest neighbours classifier to solve the XOR problem.
14
+ # http://weka.sourceforge.net/doc/weka/classifiers/lazy/IBk.html
15
+ ibk = IBk.new
16
+
17
+ ibk.build_classifier(@training_data)
18
+
19
+ # FALSE, FALSE
20
+ @training_data.class_attribute[ibk.classify_instance(@training_data[0])].should ==
21
+ "FALSE"
22
+
23
+ # FALSE, TRUE
24
+ @training_data.class_attribute[ibk.classify_instance(@training_data[1])].should ==
25
+ "TRUE"
26
+ end
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ required_ruby_version: !ruby/object:Gem::Requirement
3
+ requirements:
4
+ - - '>='
5
+ - !ruby/object:Gem::Version
6
+ version: "0"
7
+ version:
8
+ email: bjorn.maeland@gmail.com
9
+ cert_chain: []
10
+
11
+ summary: Use Weka from JRuby
12
+ post_install_message:
13
+ extra_rdoc_files:
14
+ - LICENSE
15
+ - README.rdoc
16
+ homepage: http://github.com/Chrononaut/eureka
17
+ signing_key:
18
+ name: eureka
19
+ rdoc_options:
20
+ - --charset=UTF-8
21
+ rubyforge_project:
22
+ autorequire:
23
+ licenses: []
24
+
25
+ executables: []
26
+
27
+ description: Weka wrapper for JRuby
28
+ specification_version: 3
29
+ default_executable:
30
+ files:
31
+ - .document
32
+ - .gitignore
33
+ - LICENSE
34
+ - README.rdoc
35
+ - Rakefile
36
+ - lib/eureka.rb
37
+ - lib/eureka/core.rb
38
+ - spec/core_spec.rb
39
+ - spec/data/stock_testing_data.arff
40
+ - spec/data/stock_training_data.arff
41
+ - spec/data/xor.arff
42
+ - spec/spec.opts
43
+ - spec/spec_helper.rb
44
+ - spec/stock_spec.rb
45
+ - spec/xor_spec.rb
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - '>='
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ extensions: []
53
+
54
+ rubygems_version: 1.3.5
55
+ requirements: []
56
+
57
+ authors:
58
+ - "Bj\xc3\xb8rn Arild M\xc3\xa6land"
59
+ date: 2009-10-26 23:00:00 +00:00
60
+ platform: ruby
61
+ test_files:
62
+ - spec/spec_helper.rb
63
+ - spec/xor_spec.rb
64
+ - spec/core_spec.rb
65
+ - spec/stock_spec.rb
66
+ version: !ruby/object:Gem::Version
67
+ version: 0.0.1
68
+ require_paths:
69
+ - lib
70
+ dependencies:
71
+ - !ruby/object:Gem::Dependency
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: 1.2.9
77
+ version:
78
+ type: :development
79
+ version_requirement:
80
+ name: rspec
81
+ bindir: bin
82
+ has_rdoc: true