Sha256: c63a5f86d2a5c4324cf7f144edb53243fec9b763f051aadaee3dccc411675f3e

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

# Author::    Sergio Fierens
# License::   MPL 1.1
# Project::   ai4r
# Url::       http://ai4r.rubyforge.org/
#
# You can redistribute it and/or modify it under the terms of 
# the Mozilla Public License version 1.1  as published by the 
# Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt

#require File.dirname(__FILE__) + '/../../lib/decision_tree/id3'
require File.dirname(__FILE__) + '/../../lib/ai4r/classifiers/id3'
require 'csv'

# Load data from data_set.csv
data_set = []
CSV::Reader.parse(File.open("#{File.dirname(__FILE__)}/data_set.csv", 'r')) do |row|
  data_set << row
end
data_labels = data_set.shift

# Build ID3 tree
id3 = Ai4r::Classifiers::ID3.new.build(data_set, data_labels)

# Show rules
puts "Discovered rules are:"
puts id3.to_s

# Try to predict some values
puts "['Moron Sur (GBA)','4','[86 m2 - 100 m2]'] => " + id3.eval(['Moron Sur (GBA)','4','[86 m2 - 100 m2]'])
puts "['Moron Sur (GBA)','3','[101 m2 - 125 m2]'] => " + id3.eval(['Moron Sur (GBA)','3','[101 m2 - 125 m2]'])
puts "['Recoleta (CABA)','3','[86 m2 - 100 m2]'] => " + id3.eval(['Recoleta (CABA)','3','[86 m2 - 100 m2]',])
puts "['Tigre (GBA)','3','[71 m2 - 85 m2]'] => " + id3.eval(['Tigre (GBA)','3','[71 m2 - 85 m2]',])

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ai4r-1.2 examples/decision_trees/id3_example.rb