Sha256: 3be575054fb470aebee2ed12ae299d7caaa24b71c4af520025316f0624eb3929

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 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/ai4r/classifiers/id3'

# Load data from data_set.csv
data_filename = "#{File.dirname(__FILE__)}/data_set.csv"
data_set = Ai4r::Data::DataSet.new.load_data_and_labels_from_csv data_filename

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

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

# Try to predict some values
puts "Prediction samples:"
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

2 entries across 2 versions & 1 rubygems

Version Path
ai4r-1.4 examples/decision_trees/id3_example.rb
ai4r-1.3 examples/decision_trees/id3_example.rb