pplonski / my_ml_service

My Machine Learning Web Service

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to run the prediction View

M0315G opened this issue · comments

While running the predict View on the URL:
http://127.0.0.1:8000/api/v1/income_classifier/predict,
I'm getting the following error:

Request Method: POST
Request URL: http://127.0.0.1:8000/api/v1/income_classifier/predict
Django version: 3.1.4

Exception Type: | FieldError
Exception Value: | Cannot resolve keyword 'status' into field. Choices are: code, created_at, description, id, mlalgorithmstatus, mlrequest, name, owner, parent_endpoint, parent_endpoint_id, version

Specifically, it's showing an error at the line:
algs = MLAlgorithm.objects.filter(parent_endpoint__name = endpoint_name, status__status = algorithm_status, status__active=True)
of the below predict code according to the stack trace. Let me know if you require the full stack trace to look at.

The code for the Predict View is as follow:

`class PredictView(views.APIView):
def post(self, request, endpoint_name, format=None):

    algorithm_status = self.request.query_params.get("status", "production")
    algorithm_version = self.request.query_params.get("version")

    algs = MLAlgorithm.objects.filter(parent_endpoint__name = endpoint_name, status__status = algorithm_status, status__active=True)

    if algorithm_version is not None:
        algs = algs.filter(version = algorithm_version)

    if len(algs) == 0:
        return Response(
            {"status": "Error", "message": "ML algorithm is not available"},
            status=status.HTTP_400_BAD_REQUEST,
        )
    if len(algs) != 1 and algorithm_status != "ab_testing":
        return Response(
            {"status": "Error", "message": "ML algorithm selection is ambiguous. Please specify algorithm version."},
            status=status.HTTP_400_BAD_REQUEST,
        )
    alg_index = 0
    if algorithm_status == "ab_testing":
        alg_index = 0 if rand() < 0.5 else 1

    algorithm_object = registry.endpoints[algs[alg_index].id]
    prediction = algorithm_object.compute_prediction(request.data)


    label = prediction["label"] if "label" in prediction else "error"
    ml_request = MLRequest(
        input_data=json.dumps(request.data),
        full_response=prediction,
        response=label,
        feedback="",
        parent_mlalgorithm=algs[alg_index],
    )
    ml_request.save()

    prediction["request_id"] = ml_request.id

    return Response(prediction)`

I'm stuck at it since a day, would be great if you could help me out.
Thanks

commented

Hard to guess ... Can you provide more details? Have you changes anything in the code? How are you running the project? Have you applied the database migration?

Hard to guess ... Can you provide more details? Have you changes anything in the code? How are you running the project? Have you applied the database migration?

There was some error in the database. I viewed the file and it lacked some attributes. Making the migrations again worked.

Thanks