class Scoruby::Models::NaiveBayes::ModelData
Attributes
category_features[R]
labels[R]
numerical_features[R]
threshold[R]
Public Class Methods
new(xml)
click to toggle source
# File lib/scoruby/models/naive_bayes/model_data.rb, line 9 def initialize(xml) @xml = xml fetch_threshold fetch_features_data fetch_label_counts end
Private Instance Methods
fetch_category(category)
click to toggle source
# File lib/scoruby/models/naive_bayes/model_data.rb, line 62 def fetch_category(category) category_data = {} category.child.children.each do |label| category_data[label.attr('value')] = label.attr('count') end category_data end
fetch_category_feature(feature)
click to toggle source
# File lib/scoruby/models/naive_bayes/model_data.rb, line 53 def fetch_category_feature(feature) return unless feature.children.any? { |f| f.name == 'PairCounts' } feature_data = {} feature.children.each do |category| feature_data[category.attr('value')] = fetch_category(category) end feature_data end
fetch_features_data()
click to toggle source
# File lib/scoruby/models/naive_bayes/model_data.rb, line 23 def fetch_features_data @category_features = {} @numerical_features = {} @xml.xpath('//BayesInput').each do |feature| field_name = feature.attr('fieldName').to_sym @category_features[field_name] = fetch_category_feature(feature) @numerical_features[field_name] = fetch_numerical_feature(feature) end end
fetch_label_counts()
click to toggle source
# File lib/scoruby/models/naive_bayes/model_data.rb, line 33 def fetch_label_counts @labels = {} @xml.xpath('//BayesOutput//TargetValueCount').each do |l| l.attr('value') @labels[l.attr('value')] = { 'count': l.attr('count').to_f } end end
fetch_numerical_feature(feature)
click to toggle source
# File lib/scoruby/models/naive_bayes/model_data.rb, line 41 def fetch_numerical_feature(feature) return unless feature.child.name == 'TargetValueStats' features_data = {} feature.child.children.each do |child| features_data[child.attr('value').strip] = { mean: child.child.attr('mean'), variance: child.child.attr('variance') } end features_data end
fetch_threshold()
click to toggle source
# File lib/scoruby/models/naive_bayes/model_data.rb, line 18 def fetch_threshold @threshold = @xml.xpath('//NaiveBayesModel').attr('threshold') .value.to_f end