| 696 | namespace NPmml { |
| 697 | |
| 698 | void OutputModel( |
| 699 | const TFullModel& model, |
| 700 | const TString& modelFile, |
| 701 | const NJson::TJsonValue& userParameters, |
| 702 | const THashMap<ui32, TString>* catFeaturesHashToString) { |
| 703 | |
| 704 | CB_ENSURE( |
| 705 | SafeIntegerCast<size_t>( |
| 706 | CountIf( |
| 707 | model.ModelTrees->GetCatFeatures(), |
| 708 | [](const TCatFeature& catFeature) { return catFeature.UsedInModel(); })) |
| 709 | == model.ModelTrees->GetOneHotFeatures().size(), |
| 710 | "PMML export requires that all categorical features in the model are one hot encoded"); |
| 711 | |
| 712 | CB_ENSURE( |
| 713 | model.GetDimensionsCount() == 1, |
| 714 | "PMML export currently supports only single-dimensional models"); |
| 715 | |
| 716 | CB_ENSURE_INTERNAL( |
| 717 | !model.ModelTrees->GetOneHotFeatures().size() || catFeaturesHashToString, |
| 718 | "catFeaturesHashToString has to be specified if the model contains one hot features"); |
| 719 | |
| 720 | // assumed regression by default |
| 721 | |
| 722 | bool isClassification = false; |
| 723 | const TString lossFunctionName = model.GetLossFunctionName(); |
| 724 | if (lossFunctionName) { |
| 725 | isClassification = IsClassificationObjective(lossFunctionName); |
| 726 | } |
| 727 | |
| 728 | TOFStream out(modelFile); |
| 729 | TXmlOutputContext xmlOut(&out, "PMML"); |
| 730 | xmlOut.AddAttr("version", "4.3") |
| 731 | .AddAttr("xmlns", "http://www.dmg.org/PMML-4_3") |
| 732 | .AddAttr("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); |
| 733 | |
| 734 | OutputHeader(model, userParameters, &xmlOut); |
| 735 | |
| 736 | OutputDataDictionary(model, isClassification, &xmlOut); |
| 737 | |
| 738 | OutputMiningModel(model, isClassification, catFeaturesHashToString, &xmlOut); |
| 739 | } |
| 740 | |
| 741 | } |
| 742 | } |
no test coverage detected