From 0cf454d073afa65916e7607b21e9bef8cf96d0e7 Mon Sep 17 00:00:00 2001 From: Jonas Gabriel Date: Fri, 17 Nov 2023 12:34:56 -0300 Subject: [PATCH] classifier statistics --- api/DataProcesser.py | 11 +++++++++++ api/NbEmotionsModel.py | 2 +- api/app.py | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/api/DataProcesser.py b/api/DataProcesser.py index c9daadfb..646f5d5c 100644 --- a/api/DataProcesser.py +++ b/api/DataProcesser.py @@ -21,6 +21,17 @@ def handle_classify(self, df, classifier): return classifier_switcher.get(classifier, lambda: "Invalid Classifier")(df) + def generate_statistics(self, df): + unique_labels = df['output_column'].unique() + + statistics = { + 'total_rows': len(df), + 'unique_labels': list(unique_labels), + 'label_counts': df['output_column'].value_counts().to_dict() + } + + return statistics + def preprocess_text(self, texto): if self.input_column is not None: # Verifique se a coluna foi definida # tiro tudo que não for texto e espaço diff --git a/api/NbEmotionsModel.py b/api/NbEmotionsModel.py index 40c744f6..07c68c3d 100644 --- a/api/NbEmotionsModel.py +++ b/api/NbEmotionsModel.py @@ -15,4 +15,4 @@ def make_prediction(my_sentence): new_sentence = tfidf_vectorizer.transform([my_sentence]) prediction = model.predict(new_sentence) - return prediction \ No newline at end of file + return prediction[0] \ No newline at end of file diff --git a/api/app.py b/api/app.py index 3a4ad7db..11ffcb86 100644 --- a/api/app.py +++ b/api/app.py @@ -40,8 +40,9 @@ def upload_file(): df = pd.DataFrame(selected_data, columns=['input_column']) result = data_processer.handle_classify(df, selected_classifier) + stats = data_processer.generate_statistics(result) - return jsonify({'result': result.to_json()}) + return jsonify({'result': result.to_json(), 'stats': stats}) @app.route('/get-classifiers', methods=["GET"]) def get_classifiers():