MCPcopy Create free account
hub / github.com/catboost/catboost / QualityBenchmark

Function QualityBenchmark

library/cpp/linear_regression/benchmark/main.cpp:13–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11
12template <typename TLRSolver>
13void QualityBenchmark(const TPool& originalPool) {
14 auto measure = [&](const double injureFactor, const double injureOffset) {
15 TPool injuredPool = originalPool.InjurePool(injureFactor, injureOffset);
16
17 static const size_t runsCount = 10;
18 static const size_t foldsCount = 10;
19
20 TMeanCalculator determinationCoefficientCalculator;
21
22 TPool::TCVIterator learnIterator = injuredPool.CrossValidationIterator(foldsCount, TPool::LearnIterator);
23 TPool::TCVIterator testIterator = injuredPool.CrossValidationIterator(foldsCount, TPool::TestIterator);
24
25 for (size_t runNumber = 0; runNumber < runsCount; ++runNumber) {
26 for (size_t foldNumber = 0; foldNumber < foldsCount; ++foldNumber) {
27 learnIterator.ResetShuffle();
28 learnIterator.SetTestFold(foldNumber);
29 testIterator.ResetShuffle();
30 testIterator.SetTestFold(foldNumber);
31
32 TLRSolver solver;
33 for (; learnIterator.IsValid(); ++learnIterator) {
34 solver.Add(learnIterator->Features, learnIterator->Goal, learnIterator->Weight);
35 }
36 TLinearModel model = solver.Solve();
37
38 TDeviationCalculator goalsCalculator;
39 TKahanAccumulator<double> errorsCalculator;
40 for (; testIterator.IsValid(); ++testIterator) {
41 const double prediction = model.Prediction(testIterator->Features);
42 const double goal = testIterator->Goal;
43 const double weight = testIterator->Weight;
44 const double error = goal - prediction;
45
46 goalsCalculator.Add(goal, weight);
47 errorsCalculator += error * error * weight;
48 }
49
50 const double determinationCoefficient = 1 - errorsCalculator.Get() / goalsCalculator.GetDeviation();
51 determinationCoefficientCalculator.Add(determinationCoefficient);
52 }
53 }
54
55 return determinationCoefficientCalculator.GetMean();
56 };
57
58 Cout << TypeName<TLRSolver>() << ":\n";
59 Cout << "\t" << Sprintf("base : %.10lf\n", measure(1., 0.));
60 Cout << "\t" << Sprintf("injure1 : %.10lf\n", measure(1e-1, 1e+1));
61 Cout << "\t" << Sprintf("injure2 : %.10lf\n", measure(1e-3, 1e+4));
62 Cout << "\t" << Sprintf("injure3 : %.10lf\n", measure(1e-3, 1e+5));
63 Cout << "\t" << Sprintf("injure4 : %.10lf\n", measure(1e-3, 1e+6));
64 Cout << "\t" << Sprintf("injure5 : %.10lf\n", measure(1e-4, 1e+6));
65 Cout << "\t" << Sprintf("injure6 : %.10lf\n", measure(1e-4, 1e+7));
66 Cout << Endl;
67}
68
69template <typename TLRSolver>
70void SpeedBenchmark(const TPool& originalPool) {

Callers

nothing calls this directly

Calls 12

SprintfFunction · 0.85
InjurePoolMethod · 0.80
ResetShuffleMethod · 0.80
SetTestFoldMethod · 0.80
PredictionMethod · 0.80
GetDeviationMethod · 0.80
GetMeanMethod · 0.80
IsValidMethod · 0.45
AddMethod · 0.45
SolveMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected