Skip to content

Commit

Permalink
fix linter issuses
Browse files Browse the repository at this point in the history
  • Loading branch information
shroukhegazi committed Mar 3, 2023
1 parent 96839dd commit 35cfbe2
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 22 deletions.
3 changes: 0 additions & 3 deletions agriwise/crop_recomendation/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from django.contrib import admin

# Register your models here.
4 changes: 2 additions & 2 deletions agriwise/crop_recomendation/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 0 additions & 3 deletions agriwise/crop_recomendation/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from django.db import models

# Create your models here.
3 changes: 0 additions & 3 deletions agriwise/crop_recomendation/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from django.test import TestCase

# Create your tests here.
3 changes: 0 additions & 3 deletions agriwise/crop_recomendation/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from django.shortcuts import render

# Create your views here.
37 changes: 29 additions & 8 deletions agriwise/ml/crop_recommendation/crop_recommendation.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand All @@ -30,5 +52,4 @@ def compute_prediction(self, input_data):
except Exception as e:
return {"status": "Error", "message": str(e)}


return prediction
return prediction

0 comments on commit 35cfbe2

Please sign in to comment.