From 35cfbe2cad78a8213634c9fe7a8e37038aa0a0bd Mon Sep 17 00:00:00 2001 From: shroukhegazi Date: Fri, 3 Mar 2023 23:32:10 +0200 Subject: [PATCH] fix linter issuses --- agriwise/crop_recomendation/admin.py | 3 -- agriwise/crop_recomendation/apps.py | 4 +- agriwise/crop_recomendation/models.py | 3 -- agriwise/crop_recomendation/tests.py | 3 -- agriwise/crop_recomendation/views.py | 3 -- .../crop_recommendation.py | 37 +++++++++++++++---- 6 files changed, 31 insertions(+), 22 deletions(-) diff --git a/agriwise/crop_recomendation/admin.py b/agriwise/crop_recomendation/admin.py index 8c38f3f..e69de29 100644 --- a/agriwise/crop_recomendation/admin.py +++ b/agriwise/crop_recomendation/admin.py @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/agriwise/crop_recomendation/apps.py b/agriwise/crop_recomendation/apps.py index e240c35..1b7e0cb 100644 --- a/agriwise/crop_recomendation/apps.py +++ b/agriwise/crop_recomendation/apps.py @@ -2,5 +2,5 @@ class CropRecomendationConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'agriwise.crop_recomendation' + default_auto_field = "django.db.models.BigAutoField" + name = "agriwise.crop_recomendation" diff --git a/agriwise/crop_recomendation/models.py b/agriwise/crop_recomendation/models.py index 71a8362..e69de29 100644 --- a/agriwise/crop_recomendation/models.py +++ b/agriwise/crop_recomendation/models.py @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/agriwise/crop_recomendation/tests.py b/agriwise/crop_recomendation/tests.py index 7ce503c..e69de29 100644 --- a/agriwise/crop_recomendation/tests.py +++ b/agriwise/crop_recomendation/tests.py @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/agriwise/crop_recomendation/views.py b/agriwise/crop_recomendation/views.py index 91ea44a..e69de29 100644 --- a/agriwise/crop_recomendation/views.py +++ b/agriwise/crop_recomendation/views.py @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. diff --git a/agriwise/ml/crop_recommendation/crop_recommendation.py b/agriwise/ml/crop_recommendation/crop_recommendation.py index 0b65c73..f7d05a3 100644 --- a/agriwise/ml/crop_recommendation/crop_recommendation.py +++ b/agriwise/ml/crop_recommendation/crop_recommendation.py @@ -1,10 +1,11 @@ -import numpy import joblib +import numpy import pandas as pd + class RandomForestClassifier: def __init__(self): - self.model = joblib.load('./random_forest.joblib') + self.model = joblib.load("./random_forest.joblib") def preprocessing(self, input_data): # JSON to pandas DataFrame @@ -14,13 +15,34 @@ def preprocessing(self, input_data): def predict(self, input_data): return self.model.predict_proba(input_data) - + def postprocessing(self, prediction): - categories = ['apple', 'banana', 'blackgram', 'chickpea', 'coconut', 'coffee', - 'cotton', 'grapes', 'jute', 'kidneybeans', 'lentil', 'maize', 'mango', 'mothbeans', 'mungbean', 'muskmelon', 'orange', 'papaya', 'pigeonpeas', 'pomegranate', 'rice', 'watermelon'] + categories = [ + "apple", + "banana", + "blackgram", + "chickpea", + "coconut", + "coffee", + "cotton", + "grapes", + "jute", + "kidneybeans", + "lentil", + "maize", + "mango", + "mothbeans", + "mungbean", + "muskmelon", + "orange", + "papaya", + "pigeonpeas", + "pomegranate", + "rice", + "watermelon", + ] index_max_predict = numpy.argmax(prediction) return categories[index_max_predict] - def compute_prediction(self, input_data): try: @@ -30,5 +52,4 @@ def compute_prediction(self, input_data): except Exception as e: return {"status": "Error", "message": str(e)} - - return prediction \ No newline at end of file + return prediction