Class: ModelFox::MulticlassClassificationPredictOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/modelfox/modelfox.rb

Overview

‘predict` outputs `MulticlassClassificationPredictOutput` when the model’s task is multiclass classification.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class_name:, probability:, probabilities:, feature_contributions:) ⇒ MulticlassClassificationPredictOutput

Returns a new instance of MulticlassClassificationPredictOutput.



77
78
79
80
81
82
# File 'lib/modelfox/modelfox.rb', line 77

def initialize(class_name:, probability:, probabilities:, feature_contributions:)
  @class_name = class_name
  @probability = probability
  @probabilities = probabilities
  @feature_contributions = feature_contributions
end

Instance Attribute Details

#class_nameObject (readonly)

This is the name of the predicted class.



70
71
72
# File 'lib/modelfox/modelfox.rb', line 70

def class_name
  @class_name
end

#feature_contributionsObject (readonly)

If computing feature contributions was enabled in the predict options, this value will explain the model’s output, showing how much each feature contributed to the output. This value maps from class names to ‘FeatureContributions` values for each class. The class with the `FeatureContributions` value with the highest `output_value` is the predicted class.



76
77
78
# File 'lib/modelfox/modelfox.rb', line 76

def feature_contributions
  @feature_contributions
end

#probabilitiesObject (readonly)

This value maps from class names to the probability the model assigned to each class.



74
75
76
# File 'lib/modelfox/modelfox.rb', line 74

def probabilities
  @probabilities
end

#probabilityObject (readonly)

This is the probability the model assigned to the predicted class.



72
73
74
# File 'lib/modelfox/modelfox.rb', line 72

def probability
  @probability
end

Instance Method Details

#to_json(*args) ⇒ Object



83
84
85
# File 'lib/modelfox/modelfox.rb', line 83

def to_json(*args)
  {'class_name' => @class_name, "probability" => @probability, "probabilities" => @probabilities}.to_json(*args)
end