class PMMLConsumer::MLModel
Attributes
fields_type[RW]
model_node[RW]
Public Class Methods
new(model_node, field_type)
click to toggle source
# File lib/pmml_consumer/ml_model.rb, line 6 def initialize(model_node, field_type) @model_node = model_node @fields_type = filter_field(field_type) @target_fields = target_fields end
Public Instance Methods
cast_input(input)
click to toggle source
# File lib/pmml_consumer/ml_model.rb, line 16 def cast_input(input) @fields_type.each do |field_name, field_type| input[field_name] = if input[field_name].nil? && !field_type["missingValueReplacement"].nil? field_type["missingValueReplacement"] elsif input[field_name].nil? && field_type["missingValueReplacement"].nil? raise "value '#{field_name}' not found and no value replacement set" else case field_type["dataType"] when "double" input[field_name].to_f when "integer" input[field_name].to_i when "string" input[field_name].to_s else raise "unknow dataType: #{field_type["dataType"]}" end end if field_type["values"].is_a?(Array) && !field_type["values"].include?(input[field_name]) raise "not a valid value: #{input[field_name]}" end end input end
filter_field(field_type)
click to toggle source
# File lib/pmml_consumer/ml_model.rb, line 41 def filter_field(field_type) @model_node.xpath("xmlns:MiningSchema/xmlns:MiningField").each do |mining_field| unless mining_field.attributes["usageType"].nil? || mining_field.attributes["usageType"].value == "active" field_type.delete(mining_field.attributes["name"].value) end end field_type end
predict(input)
click to toggle source
# File lib/pmml_consumer/ml_model.rb, line 12 def predict(input) raise "not implemented" end
target_fields()
click to toggle source
# File lib/pmml_consumer/ml_model.rb, line 50 def target_fields @model_node.xpath("xmlns:MiningSchema/xmlns:MiningField[@usageType='target']").map do |mining_field| mining_field["name"] end end