У меня есть склеарн трубопровод.Один из его шагов - ExpressionTransformer(f"round(X[0]*{nRoundMin})/{nRoundMin}")
(импорт ExpressionTransformer из sklearn2pmml.preprocessing).Когда я пытаюсь записать этот конвейер в файл PMML, я получаю следующую ошибку:
Standard output is empty
Standard error:
Jun 27, 2019 8:39:55 AM org.jpmml.sklearn.Main run
INFO: Parsing PKL..
Jun 27, 2019 8:40:53 AM org.jpmml.sklearn.Main run
INFO: Parsed PKL in 58085 ms.
Jun 27, 2019 8:40:53 AM org.jpmml.sklearn.Main run
INFO: Converting..
Jun 27, 2019 8:41:03 AM org.jpmml.sklearn.Main run
SEVERE: Failed to convert
java.lang.IllegalArgumentException: round
at org.jpmml.sklearn.ExpressionTranslator.translateFunction(ExpressionTranslator.java:94)
at org.jpmml.sklearn.ExpressionTranslator.FunctionInvocationExpression(ExpressionTranslator.java:513)
at org.jpmml.sklearn.ExpressionTranslator.PrimaryExpression(ExpressionTranslator.java:416)
at org.jpmml.sklearn.ExpressionTranslator.UnaryExpression(ExpressionTranslator.java:374)
at org.jpmml.sklearn.ExpressionTranslator.MultiplicativeExpression(ExpressionTranslator.java:316)
at org.jpmml.sklearn.ExpressionTranslator.AdditiveExpression(ExpressionTranslator.java:280)
at org.jpmml.sklearn.ExpressionTranslator.ComparisonExpression(ExpressionTranslator.java:228)
at org.jpmml.sklearn.ExpressionTranslator.NegationExpression(ExpressionTranslator.java:217)
at org.jpmml.sklearn.ExpressionTranslator.LogicalAndExpression(ExpressionTranslator.java:187)
at org.jpmml.sklearn.ExpressionTranslator.LogicalOrExpression(ExpressionTranslator.java:166)
at org.jpmml.sklearn.ExpressionTranslator.IfElseExpression(ExpressionTranslator.java:147)
at org.jpmml.sklearn.ExpressionTranslator.Expression(ExpressionTranslator.java:140)
at org.jpmml.sklearn.ExpressionTranslator.translateExpressionInternal(ExpressionTranslator.java:134)
at org.jpmml.sklearn.ExpressionTranslator.translate(ExpressionTranslator.java:33)
at org.jpmml.sklearn.ExpressionTranslator.translate(ExpressionTranslator.java:22)
at sklearn2pmml.preprocessing.ExpressionTransformer.encodeFeatures(ExpressionTransformer.java:43)
at sklearn.pipeline.Pipeline.encodeFeatures(Pipeline.java:81)
, хотя round
находится во встроенных функциях PMML (http://dmg.org/pmml/v4-2-1/BuiltinFunctions.html#math). Как мне написатьэтот шаг конвейера для правильного перевода функции округления?
Если я удаляю функцию округления в приведенном выше ExpressionTransfomer
, PMML создается без каких-либо проблем.
Я также пыталсязамените выше ExpressionTransfomer
на
Pipeline([
("i", ExpressionTransformer("X[0]*"+str(nRoundMin))),
("r", FunctionTransformer(np.round)),
("f", ExpressionTransformer("X[0]/"+str(nRoundMin)))
])
и
Pipeline([
("i", ExpressionTransformer("X[0]*"+str(nRoundMin))),
("r", FunctionTransformer(round)),
("f", ExpressionTransformer("X[0]/"+str(nRoundMin)))
])
, но это не помогло.
[Редактировать] Следуя рекомендации user1808924, я такжепробовал ExpressionTransformer(f"numpy.rint(X[0]*{nRoundMin})/{nRoundMin}")
, что приводит к аналогичной ошибке:
Standard output is empty
Standard error:
Jun 27, 2019 12:38:51 PM org.jpmml.sklearn.Main run
INFO: Parsing PKL..
Jun 27, 2019 12:39:54 PM org.jpmml.sklearn.Main run
INFO: Parsed PKL in 63076 ms.
Jun 27, 2019 12:39:54 PM org.jpmml.sklearn.Main run
INFO: Converting..
Jun 27, 2019 12:40:05 PM org.jpmml.sklearn.Main run
SEVERE: Failed to convert
java.lang.IllegalArgumentException: numpy.rint
at org.jpmml.sklearn.ExpressionTranslator.translateFunction(ExpressionTranslator.java:94)
at org.jpmml.sklearn.ExpressionTranslator.FunctionInvocationExpression(ExpressionTranslator.java:513)
at org.jpmml.sklearn.ExpressionTranslator.PrimaryExpression(ExpressionTranslator.java:416)
at org.jpmml.sklearn.ExpressionTranslator.UnaryExpression(ExpressionTranslator.java:374)
at org.jpmml.sklearn.ExpressionTranslator.MultiplicativeExpression(ExpressionTranslator.java:316)
at org.jpmml.sklearn.ExpressionTranslator.AdditiveExpression(ExpressionTranslator.java:280)
at org.jpmml.sklearn.ExpressionTranslator.ComparisonExpression(ExpressionTranslator.java:228)
at org.jpmml.sklearn.ExpressionTranslator.NegationExpression(ExpressionTranslator.java:217)
at org.jpmml.sklearn.ExpressionTranslator.LogicalAndExpression(ExpressionTranslator.java:187)
at org.jpmml.sklearn.ExpressionTranslator.LogicalOrExpression(ExpressionTranslator.java:166)
at org.jpmml.sklearn.ExpressionTranslator.IfElseExpression(ExpressionTranslator.java:147)
at org.jpmml.sklearn.ExpressionTranslator.Expression(ExpressionTranslator.java:140)
at org.jpmml.sklearn.ExpressionTranslator.translateExpressionInternal(ExpressionTranslator.java:134)
at org.jpmml.sklearn.ExpressionTranslator.translate(ExpressionTranslator.java:33)
at org.jpmml.sklearn.ExpressionTranslator.translate(ExpressionTranslator.java:22)
at sklearn2pmml.preprocessing.ExpressionTransformer.encodeFeatures(ExpressionTransformer.java:43)