-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from iurwpoietknckvjndfsm-gndvkd/authentication
added create_superuser method, Added ML dir and dependacies
- Loading branch information
Showing
13 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class CropRecomendationConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "agriwise.crop_recomendation" |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import joblib | ||
import numpy | ||
import pandas as pd | ||
|
||
|
||
class RandomForestClassifier: | ||
def __init__(self): | ||
self.model = joblib.load("./random_forest.joblib") | ||
|
||
def preprocessing(self, input_data): | ||
# JSON to pandas DataFrame | ||
input_data = pd.DataFrame(input_data, index=[0]) | ||
|
||
return 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", | ||
] | ||
index_max_predict = numpy.argmax(prediction) | ||
return categories[index_max_predict] | ||
|
||
def compute_prediction(self, input_data): | ||
try: | ||
input_data = self.preprocessing(input_data) | ||
prediction = self.predict(input_data)[0] # only one sample | ||
prediction = self.postprocessing(prediction) | ||
except Exception as e: | ||
return {"status": "Error", "message": str(e)} | ||
|
||
return prediction |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters