Я обучил модель в Python с использованием sklearn.neural_network.MLPClassifier (0.20.3) и сохранил ее в формате PMML с помощью sklearn2pmml (0.48.0). Сохраненная модель PMML работает должным образом при загрузке в Java с использованием org.jpmml:pmml-evaluator:1.4.14
.
Теперь я хочу загрузить модель PMML и делать прогнозы в C# с использованием пакета Syncfusion:
<ItemGroup>
<PackageReference Include="Syncfusion.PMML.AspNet" Version="17.4.0.44" />
</ItemGroup>
using System;
using Syncfusion.PMML;
namespace myprogram
{
class Program
{
static void Main(string[] args)
{
var predictors = new
{
predictor_1 = 0.05,
predictor_2 = 203.0,
predictor_3 = 400.0,
predictor_4 = 22.0,
predictor_5 = 9.01
};
string PmmlFilePath = “/project/model.pmml";
//Create instance for PMML Document
PMMLDocument pmmlDocument = new PMMLDocument(PmmlFilePath);
//Create instance for Mining model
NeuralNetworkModelEvaluator neuralNetworkModel = new NeuralNetworkModelEvaluator(pmmlDocument);
//Gets the predicted result
PredictedResult predictedResult = neuralNetworkModel.GetResult(predictors, null);
}
}
}
, но последняя строка приведенного выше кода вызывает следующее исключение:
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at Syncfusion.PMML.NeuralNetworkModelEvaluator.ComputeResult(Dictionary`2 fieldValuePair, NeuralNetworkModel neuralNetworkModel)
at Syncfusion.PMML.NeuralNetworkModelEvaluator.GetResult(Object obj, IModelOptions modelOptions)
at myprogram.Program.Main(String[] args) in /project/Program.cs:line 66
model.pmml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<PMML xmlns="http://www.dmg.org/PMML-4_3" xmlns:data="http://jpmml.org/jpmml-model/InlineTable" version="4.3">
<Header>
<Application name="JPMML-SkLearn" version="1.5.20"/>
<Timestamp>2020-20-15T03:42:46Z</Timestamp>
</Header>
<DataDictionary>
<DataField name="target_state" optype="categorical" dataType="string">
<Value value="RED"/>
<Value value="GREEN"/>
</DataField>
<DataField name="predictor_1" optype="continuous" dataType="double"/>
<DataField name="predictor_2" optype="continuous" dataType="double"/>
<DataField name="predictor_3" optype="continuous" dataType="double"/>
<DataField name="predictor_4" optype="continuous" dataType="double"/>
<DataField name="predictor_5" optype="continuous" dataType="double"/>
</DataDictionary>
<TransformationDictionary/>
<MiningModel functionName="classification">
<MiningSchema>
<MiningField name="target_state" usageType="target"/>
<MiningField name="predictor_1"/>
<MiningField name="predictor_2"/>
<MiningField name="predictor_3"/>
<MiningField name="predictor_4"/>
<MiningField name="predictor_5"/>
</MiningSchema>
<Segmentation multipleModelMethod="modelChain" x-missingPredictionTreatment="returnMissing">
<Segment id="1">
<True/>
<RegressionModel functionName="regression">
<MiningSchema>
<MiningField name="predictor_2"/>
<MiningField name="predictor_5"/>
<MiningField name="predictor_1"/>
<MiningField name="predictor_3"/>
<MiningField name="predictor_4"/>
</MiningSchema>
<Output>
<OutputField name="decisionFunction" optype="continuous" dataType="double" isFinalResult="false"/>
</Output>
<LocalTransformations>
<DerivedField name="robust_scaler(predictor_1)" optype="continuous" dataType="double">
<Apply function="/">
<Apply function="-">
<FieldRef field="predictor_1"/>
<Constant dataType="double">38.0</Constant>
</Apply>
<Constant dataType="double">36.0</Constant>
</Apply>
</DerivedField>
<DerivedField name="robust_scaler(predictor_3)" optype="continuous" dataType="double">
<Apply function="/">
<Apply function="-">
<FieldRef field="predictor_3"/>
<Constant dataType="double">29.5</Constant>
</Apply>
<Constant dataType="double">15.5</Constant>
</Apply>
</DerivedField>
<DerivedField name="robust_scaler(predictor_4)" optype="continuous" dataType="double">
<Apply function="/">
<Apply function="-">
<FieldRef field="predictor_4"/>
<Constant dataType="double">-2.0</Constant>
</Apply>
<Constant dataType="double">11.0</Constant>
</Apply>
</DerivedField>
</LocalTransformations>
<RegressionTable intercept="0.4485538242235567">
<NumericPredictor name="robust_scaler(predictor_1)" coefficient="0.09187667567720746"/>
<NumericPredictor name="predictor_2" coefficient="1.002293414783222337"/>
<NumericPredictor name="robust_scaler(predictor_3)" coefficient="-0.1790001566845147"/>
<NumericPredictor name="robust_scaler(predictor_4)" coefficient="-0.20065445270398309"/>
<NumericPredictor name="predictor_5" coefficient="-0.08789985419968031"/>
</RegressionTable>
</RegressionModel>
</Segment>
<Segment id="2">
<True/>
<RegressionModel functionName="classification" normalizationMethod="softmax">
<MiningSchema>
<MiningField name="target_state" usageType="target"/>
<MiningField name="decisionFunction"/>
</MiningSchema>
<Output>
<OutputField name="probability(RED)" optype="continuous" dataType="double" feature="probability" value="RED"/>
<OutputField name="probability(GREEN)" optype="continuous" dataType="double" feature="probability" value="GREEN"/>
</Output>
<RegressionTable intercept="0.0" targetCategory="RED">
<NumericPredictor name="decisionFunction" coefficient="-1.0"/>
</RegressionTable>
<RegressionTable intercept="0.0" targetCategory="GREEN">
<NumericPredictor name="decisionFunction" coefficient="1.0"/>
</RegressionTable>
</RegressionModel>
</Segment>
</Segmentation>
<ModelVerification recordCount="1">
<VerificationFields>
<VerificationField field="predictor_1" column="data:predictor_1"/>
<VerificationField field="predictor_2" column="data:predictor_2"/>
<VerificationField field="predictor_3" column="data:predictor_3"/>
<VerificationField field="predictor_4" column="data:predictor_4"/>
<VerificationField field="predictor_5" column="data:predictor_5"/>
<VerificationField field="probability(RED)" column="data:probability_RED" precision="1.0E-13" zeroThreshold="1.0E-13"/>
<VerificationField field="probability(GREEN)" column="data:probability_GREEN" precision="1.0E-13" zeroThreshold="1.0E-13"/>
</VerificationFields>
<InlineTable>
<row>
<data:predictor_1>595.0</data:predictor_1>
<data:predictor_2>0.0</data:predictor_2>
<data:predictor_3>201.0</data:predictor_3>
<data:predictor_4>-2.0</data:predictor_4>
<data:predictor_5>0.1</data:predictor_5>
<data:probability_RED>0.2555804919272633</data:probability_RED>
<data:probability_GREEN>0.9974195080727367</data:probability_GREEN>
</row>
</InlineTable>
</ModelVerification>
</MiningModel>
</PMML>
Может кто-нибудь, пожалуйста, помогите мне найти, где проблема есть