Module: Cabalist::ModelAdditions

Defined in:
lib/cabalist/model_additions.rb

Overview

Core functionality of Cabalist.

This module is a placeholder for methods that are mixed in with ActiveRecord::Base as well as those that are created by calling acts_as_cabalist method from within the class definition of an inheriting class.

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (void) acts_as_cabalist(opts = {})

This method returns an undefined value.

Class helper to add Cabalist functionality to a Rails model.

Parameters:

  • opts (Hash) (defaults to: {})

    An options hash.

Options Hash (opts):

  • :features (Array) — default: required

    Array of symbols representing name of the model attributes used as features (predictors) to train the classifier.

  • :class_variable (Symbol) — default: required

    Symbol representing the name of the model attribute to be predicted by the classifier.

  • :collection (Symbol) — default: optional

    Symbol representing the class method used to pull data to be used to train the classifier. By default, the method used will be :manually_classified which is a scope added by this helper call. Anything returning either an ActiveRecord::Relation or an Array of objects of this given class will do.

  • :algorithm (Symbol) — default: optional

    Symbol representing the algorithm to be used by the classifier. The library currently supports a number of algorithms provided by the ai4r gem. Accepted values are as following:

    • :hyperpipes for Hyperpipes

    • :ib1 for Simple Instance Based Learning

    • :id3 for Iterative Dichotomiser 3

    • :one_r for One Attribute Rule

    • :prism for PRISM

    • :zero_r for ZeroR



39
# File 'lib/cabalist/model_additions.rb', line 39

def self.acts_as_cabalist(opts={}) end

+ (ActiveRecord::Relation) auto_classified

Automatically classified records.

Named scope which returns objects that were classified automatically. That means they have their class variable value set as well as non-nil value of autoclassified_at attribute.

Returns:

  • (ActiveRecord::Relation)


57
# File 'lib/cabalist/model_additions.rb', line 57

def self.auto_classified() end

+ (Ai4r::Classifiers::Object) build_model

Build the classification model from scratch.

You should probably not use this method directly as it will go ahead and compute the classifier anew each and every time instead of looking at any cached versions.

Returns:

  • (Ai4r::Classifiers::Object)

    one of classifiers from the Ai4r::Classifiers module, depending on the value (and presence) of the :algorithm option in the acts_as_cabalist method call.



121
# File 'lib/cabalist/model_additions.rb', line 121

def self.build_model() end

+ (Array) class_variable_domain

Show possible values for the classification.

This method will return all unique values of the class variable that the classifier knows about. If any new values have been added after the classifier has last been retrained, they will not find their way here.

Returns:

  • (Array)

    an Array containing all unique class variable values.



151
# File 'lib/cabalist/model_additions.rb', line 151

def self.class_variable_domain() end

+ (Ai4r::Classifiers::Object) classifier

Get the classification model for a given class.

This method will try to find a ready model in the local cache but having failed that will resort to the ‘train_model’ to create one.

Returns:

  • (Ai4r::Classifiers::Object)

    one of classifiers from the Ai4r::Classifiers module, depending on the value (and presence) of the :algorithm option in the acts_as_cabalist method call.



142
# File 'lib/cabalist/model_additions.rb', line 142

def self.classifier() end

+ (Symbol) get_class_variable_name

Get name of class variable.

This method returns the class variable name (as symbol) as it has been passed to the acts_as_cabalist method call as :class_variable option.

Returns:

  • (Symbol)


110
# File 'lib/cabalist/model_additions.rb', line 110

def self.get_class_variable_name() end

+ (Array) get_feature_names

Get names of feature attributes.

This method returns the Array of attribute names (as symbols) as they have been passed to the acts_as_cabalist method call as :features option.

Returns:

  • (Array)

    an Array of symbols representing feature names



102
# File 'lib/cabalist/model_additions.rb', line 102

def self.get_feature_names() end

+ (ActiveRecord::Relation) manually_classified

Manually classified records.

Named scope which returns objects that were classified but not automatically, that is they have their class variable value set but autoclassified_at nil.

Returns:

  • (ActiveRecord::Relation)


48
# File 'lib/cabalist/model_additions.rb', line 48

def self.manually_classified() end

+ (ActiveRecord::Relation) not_classified

Records that have not yet been classified.

Named scope which returns objects that were classified automatically. That means they have their class variable value set as well as non-nil value of autoclassified_at attribute.

Returns:

  • (ActiveRecord::Relation)


66
# File 'lib/cabalist/model_additions.rb', line 66

def self.not_classified() end

Instance Method Details

- (Object) classify

Get predicted value of the class variable

This method will query the classifier of the instance’s corresponding class for the predicted classification of this instance, given the value of its features.

Returns:

  • (Object)

    predicted value of the class variable



160
# File 'lib/cabalist/model_additions.rb', line 160

def classify() end

- (self) classify!

Set the class variable to the value suggested by the classifier

This method will query the classifier of the instance’s corresponding class for the predicted classification of this instance, given the value of its features and then set the class variable to that value.

Returns:

  • (self)

    the current object instance



169
# File 'lib/cabalist/model_additions.rb', line 169

def classify!() end

- (Object) get_class_variable

Value of the class variable.

This method returns the value of an attribute passed as the :class_variable option of the acts_as_cabalist method call.

Returns:

  • (Object)

    the value of the class variable



84
# File 'lib/cabalist/model_additions.rb', line 84

def get_class_variable() end

- (Array) get_features

Get an array of features.

Returns an Array of values which result from methods passed as the :feature option of the acts_as_cabalist method call. Each of this methods is called upon current instance and results are returned.

Returns:

  • (Array)

    array of values corresponding to attributes selected as features



76
# File 'lib/cabalist/model_additions.rb', line 76

def get_features() end

- (Object) set_class_variable(new_class_variable)

Set the value of the class variable.

This method sets the value of an attribute passed as the :class_variable option of the acts_as_cabalist method call to the new value.

Parameters:

  • new_class_variable (Object)

    the new value of the class variable

Returns:

  • (Object)


94
# File 'lib/cabalist/model_additions.rb', line 94

def set_class_variable(new_class_variable) end

- (Object) teach(new_class_variable)

Set the value of the class variable.

This method sets the value of an attribute passed as the :class_variable option of the acts_as_cabalist method call to the new value and sets the autoclassified_at to nil so that current object is not treated as automatically classified.

Parameters:

  • new_class_variable (Object)

    the new value of the class variable

Returns:

  • (Object)


180
# File 'lib/cabalist/model_additions.rb', line 180

def teach(new_class_variable) end

- (Ai4r::Classifiers::Object) train_model

Build the classification model from scratch and store it in cache.

This method will use a ‘build_model’ call to create a model from scratch but once it has been created, it will also be immediately stored in the cache for further retrieval using the ‘classifier’ method.

Returns:

  • (Ai4r::Classifiers::Object)

    one of classifiers from the Ai4r::Classifiers module, depending on the value (and presence) of the :algorithm option in the acts_as_cabalist method call.



132
# File 'lib/cabalist/model_additions.rb', line 132

def train_model() end