Class Ai4r::Classifiers::Prism
In: lib/ai4r/classifiers/prism.rb
Parent: Classifier

Introduction

This is an implementation of the PRISM algorithm (Cendrowska, 1987) Given a set of preclassified examples, it builds a set of rules to predict the class of other instaces.

  1. Cendrowska (1987). PRISM: An algorithm for inducing modular rules.

International Journal of Man-Machine Studies. 27(4):349-370.

Methods

Attributes

data_set  [R] 
rules  [R] 

Public Instance methods

Build a new Prism classifier. You must provide a DataSet instance as parameter. The last attribute of each item is considered as the item class.

You can evaluate new data, predicting its class. e.g.

  classifier.eval(['New York',  '<30', 'F'])  # => 'Y'

This method returns the generated rules in ruby code. e.g.

  classifier.get_rules
    # => if age_range == '<30' then marketing_target = 'Y'
   elsif age_range == '>80' then marketing_target = 'Y'
   elsif city == 'Chicago' and age_range == '[30-50)' then marketing_target = 'Y'
   else marketing_target = 'N'
   end

It is a nice way to inspect induction results, and also to execute them:

       age_range = '[30-50)'
       city = 'New York'
       eval(classifier.get_rules)
       puts marketing_target
        'Y'

Protected Instance methods

pt = [p, t] p = occurrences of attribute value with instance classified as class_value t = occurrences of attribute value a pt is better if:

  1- its ratio is higher
  2- its ratio is equal, and has a higher p

Returns a structure with the folloring format:

> {attr1_label => { :attr1_value1 => [p, t], attr1_value2 => [p, t], … },

    attr2_label => { :attr2_value1 => [p, t], attr2_value2 => [p, t], ... },
    ...
    }

where p is the number of instances classified as class_value with that attribute value, and t is the total number of instances with that attribute value

returns a single conditional term: {attrN_label => attrN_valueM} selecting the attribute with higher pt ratio (occurrences of attribute value classified as class_value /

 occurrences of attribute value)

[Validate]