Class: CompletionKit::MetricCalibrationStats
- Inherits:
-
Object
- Object
- CompletionKit::MetricCalibrationStats
- Defined in:
- app/services/completion_kit/metric_calibration_stats.rb
Defined Under Namespace
Classes: Result
Constant Summary collapse
- PROVISIONAL_MIN =
10- FIRM_MIN =
30
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(metric:, judge_version: nil) ⇒ MetricCalibrationStats
constructor
A new instance of MetricCalibrationStats.
Constructor Details
#initialize(metric:, judge_version: nil) ⇒ MetricCalibrationStats
Returns a new instance of MetricCalibrationStats.
38 39 40 41 |
# File 'app/services/completion_kit/metric_calibration_stats.rb', line 38 def initialize(metric:, judge_version: nil) @metric = metric @judge_version = judge_version end |
Class Method Details
.for(metric, judge_version: nil) ⇒ Object
34 35 36 |
# File 'app/services/completion_kit/metric_calibration_stats.rb', line 34 def self.for(metric, judge_version: nil) new(metric: metric, judge_version: judge_version).call end |
Instance Method Details
#call ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/services/completion_kit/metric_calibration_stats.rb', line 43 def call scope = Calibration.where(metric_id: @metric.id) scope = scope.where(judge_version_id: @judge_version.id) if @judge_version verdicts = scope.pluck(:verdict, :corrected_score, :response_id) n = verdicts.length agrees = verdicts.count { |v, _, _| v == "agree" } disagrees = verdicts.count { |v, _, _| v == "disagree" } borderlines = verdicts.count { |v, _, _| v == "borderline" } ci = CalibrationMath.wilson_interval(successes: agrees, n: n) pairs = score_pairs(verdicts) mae_value = CalibrationMath.mae(pairs) pearson_value = CalibrationMath.pearson(pairs) kappa_value = CalibrationMath.quadratic_weighted_kappa(pairs, categories: 1..5) Result.new( sample_size: n, agree_count: agrees, disagree_count: disagrees, borderline_count: borderlines, agreement_point: ci[:point], agreement_low: ci[:low], agreement_high: ci[:high], borderline_rate: n.zero? ? nil : borderlines.to_f / n, mae: mae_value, pearson: pearson_value, kappa: kappa_value, gate: gate_for(n) ) end |