Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SEVERE: Failed to evaluate org.jpmml.evaluator.InvalidResultException #84

Closed
gopinathankm opened this issue Nov 20, 2017 · 4 comments
Closed

Comments

@gopinathankm
Copy link

Hello
My scenario is as follows:
Using Linear Regression I trying to predict power generated based on the values of temperature, vacuum, pressure and humidity which is inspired and Adapted from "http://datascience-enthusiast.com" and applying model to real time data from Kafka topic. Properly generated pickled .pkl.z file and converts to PMML using JPMML as suggested https://github.com/jpmml/jpmml-sklearn.

  1. Kafka Producer, a Python program (kafka_producer.py) randomly generates data within some ranges as float and converts string and sending to Kafka topic as bytes.

  2. Kafka Consumer, a python program(kafka_consumer) which act as Openscoring python client, reads the data from Kafka topic, converts byte string to string and finally to a dictionary which form the arguments like arguments = {"AT" : 9.2, "V" : 39.82, "AP" : 1013.19, "RH" : 91.25} for result = os.evaluate("CCPP", arguments) statement.

  3. It works well and predict power, but after showing the result correctly for 4 to 10 records,
    Openscoring server throws SEVERE: INFO:
    Received EvaluationRequest{id=null, arguments={AT=12.12, V=41.35, AP=1031.67, RH=66.32}}
    Nov 20, 2017 6:39:16 AM org.openscoring.service.ModelResource evaluate
    INFO: Returned EvaluationResponse{id=null, result={PE=472.152110955029}}
    Nov 20, 2017 6:39:17 AM org.openscoring.service.ModelResource evaluate
    INFO: Received EvaluationRequest{id=null, arguments={AT=34.06, V=51.53, AP=1016.22, RH=91.7}}
    Nov 20, 2017 6:39:17 AM org.openscoring.service.ModelResource evaluate
    INFO: Returned EvaluationResponse{id=null, result={PE=444.9147880324237}}
    Nov 20, 2017 6:39:18 AM org.openscoring.service.ModelResource evaluate
    INFO: Received EvaluationRequest{id=null, arguments={AT=20.41, V=50.33, AP=1018.19, RH=100.18}}
    Nov 20, 2017 6:39:18 AM org.openscoring.service.ModelResource doEvaluate
    SEVERE: Failed to evaluate
    org.jpmml.evaluator.InvalidResultException (at or around line 130)
    at org.jpmml.evaluator.FieldValueUtil.performInvalidValueTreatment(FieldValueUtil.java:178)

    at org.jpmml.evaluator.FieldValueUtil.prepareInputValue(FieldValueUtil.java:90)
    at org.jpmml.evaluator.InputField.prepare(InputField.java:64)

  4. Kafka Consumer stops and show: raise Exception(self.message)
    Exception: Bad Request

kafka_producer.py
import random
import time
from kafka import KafkaProducer
from kafka.errors import KafkaError
producer = KafkaProducer(bootstrap_servers='localhost:9092')
topic = "power"
for i in range(1000):
AT = "19.651231"
V = "54.305804"
AP = "1013.259078"
RH = "73.308978"
def getAT():
return str(round(random.uniform(2.0, 38.0),2))
def getV():
return str(round(random.uniform(26.0, 81.5),2))
def getAP():
return str(round(random.uniform(993.0, 1033.0),2))
def getRH():
return str(round(random.uniform(26.0, 101.0),2))
# arguments = {"AT" :9.2, "V" : 39.82, "AP" : 1013.19, "RH" : 91.25}
message = "{"AT" : " + getAT() + "," + ""V" : " +getV() + "," + ""AP" : " +getAP() + "," + ""RH" : " + getRH() + "}"
producer.send(topic, key=str.encode('key_{}'.format(i)), value=(message.encode('utf-8')))
time.sleep(1)
producer.close()

kafka_consumer.py
import ast
from kafka import KafkaConsumer
import openscoring
import os
os = openscoring.Openscoring("http://localhost:8080/openscoring")
kwargs = {"auth" : ("admin", "adminadmin")}
os.deploy("CCPP", "/home/gopinathankm/jpmml-sklearn-master/ccpp.pmml", **kwargs)
consumer = KafkaConsumer('power', bootstrap_servers='localhost:9092')
for message in consumer:
arguments =message.value
argsdict = arguments.decode("utf-8")
dict = ast.literal_eval(argsdict)
print(dict)
result = os.evaluate("CCPP", dict)
print(result)

For some data generated it is not working, I really don't know how bad request is generated.
Any assistance will be highly appreciated.
Regards
Gopinathan K.M

@vruusmann
Copy link
Member

Exception type InvalidResultException means that the evaluation of a model could not be completed successfully, because one or more input field values are outside of their declared range.

def getAT():
return str(round(random.uniform(2.0, 38.0),2))
def getV():
return str(round(random.uniform(26.0, 81.5),2))
def getAP():
return str(round(random.uniform(993.0, 1033.0),2))
def getRH():
return str(round(random.uniform(26.0, 101.0),2))

The value ranges of your PMML document and Python script do not match. Either delete PMML document value ranges (so that all input values are considered to be valid), or contract Python script value ranges.

@gopinathankm
Copy link
Author

I will try both.
Many Thanks.

@gopinathankm
Copy link
Author

I will try both and see.
Many thanks.

Gopinathan K.M

@gopinathankm
Copy link
Author

gopinathankm commented Nov 20, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants