| 1423 | |
| 1424 | |
| 1425 | TVector<NJson::TJsonValue> TFullModel::GetModelClassLabels() const { |
| 1426 | TVector<NJson::TJsonValue> classLabels; |
| 1427 | |
| 1428 | TMaybe<TClassLabelOptions> classOptions; |
| 1429 | |
| 1430 | // "class_params" is new, more generic option, used for binclass as well |
| 1431 | for (const auto& paramName : {"class_params", "multiclass_params"}) { |
| 1432 | if (ModelInfo.contains(paramName)) { |
| 1433 | classOptions.ConstructInPlace(); |
| 1434 | classOptions->Load(ReadTJsonValue(ModelInfo.at(paramName))); |
| 1435 | break; |
| 1436 | } |
| 1437 | } |
| 1438 | if (classOptions.Defined()) { |
| 1439 | if (classOptions->ClassLabels.IsSet()) { |
| 1440 | classLabels = classOptions->ClassLabels.Get(); |
| 1441 | if (!classLabels.empty()) { |
| 1442 | return classLabels; |
| 1443 | } |
| 1444 | } |
| 1445 | if (classOptions->ClassesCount.IsSet()) { |
| 1446 | const size_t classesCount = SafeIntegerCast<size_t>(classOptions->ClassesCount.Get()); |
| 1447 | if (classesCount) { |
| 1448 | return GetSequentialIntegerClassLabels(classesCount); |
| 1449 | } |
| 1450 | } |
| 1451 | if (classOptions->ClassToLabel.IsSet()) { |
| 1452 | classLabels.reserve(classOptions->ClassToLabel->size()); |
| 1453 | for (float label : classOptions->ClassToLabel.Get()) { |
| 1454 | classLabels.emplace_back(int(label)); |
| 1455 | } |
| 1456 | return classLabels; |
| 1457 | } |
| 1458 | } |
| 1459 | if (ModelInfo.contains("params")) { |
| 1460 | const TString& modelInfoParams = ModelInfo.at("params"); |
| 1461 | NJson::TJsonValue paramsJson = ReadTJsonValue(modelInfoParams); |
| 1462 | if (paramsJson.Has("data_processing_options") |
| 1463 | && paramsJson["data_processing_options"].Has("class_names")) { |
| 1464 | |
| 1465 | const NJson::TJsonValue::TArray& classLabelsJsonArray |
| 1466 | = paramsJson["data_processing_options"]["class_names"].GetArraySafe(); |
| 1467 | |
| 1468 | if (!classLabelsJsonArray.empty()) { |
| 1469 | classLabels.assign(classLabelsJsonArray.begin(), classLabelsJsonArray.end()); |
| 1470 | return classLabels; |
| 1471 | } |
| 1472 | } |
| 1473 | } |
| 1474 | |
| 1475 | const TMaybe<NCatboostOptions::TLossDescription> lossDescription = GetLossDescription(*this); |
| 1476 | if (lossDescription.Defined() && IsClassificationObjective(lossDescription->GetLossFunction())) { |
| 1477 | const size_t dimensionsCount = GetDimensionsCount(); |
| 1478 | return GetSequentialIntegerClassLabels((dimensionsCount == 1) ? 2 : dimensionsCount); |
| 1479 | } |
| 1480 | |
| 1481 | return classLabels; |
| 1482 | } |
no test coverage detected