Esempio n. 1
0
    def executeProcessing(self, text, trainingFilePath, modelPath, vectorPath,
                          prediction_file_object):
        self.log_writer.log(prediction_file_object, 'Prediction begins now')
        try:
            with open(vectorPath, 'rb') as f:
                vectorizer = pickle.load(f)
            with open(modelPath, 'rb') as f:
                loaded_model = pickle.load(f)
            self.log_writer.log(
                prediction_file_object,
                'Prediction model and vectorizer instance loaded successfully')

        except Exception as e:
            self.log_writer.log(
                prediction_file_object,
                'Prediction unsuccessful due to model loading')

            raise e

        text = data_preprocessing_predict(text, self.stop_words_path,
                                          prediction_file_object)
        x = vectorizer.transform(text).toarray()
        prediction = loaded_model.predict(x)

        self.log_writer.log(prediction_file_object, 'Predictions generated')
        return prediction[0]
Esempio n. 2
0
    def executePreocessing(self, text, jsonFilePath,modelPath,vectorPath):
        df_pred = pd.DataFrame([text],columns=['text'])
        df_pred['text'] = data_preprocessing_predict(df_pred['text'], self.stop_words_path)
        df_pred['text'] = [" ".join(value) for value in df_pred['text'].values]

        with open(vectorPath,'rb') as f:
            vectorizer = pickle.load(f)
        with open(modelPath, 'rb') as f:
            model = pickle.load(f)
        pred_vector_ = vectorizer.transform(df_pred['text'])
        prediction = model.predict(pred_vector_)
        predictedProbability = model.predict_proba(pred_vector_)
        if list(predictedProbability.flatten())[0] == list(predictedProbability.flatten())[1]:
            return "UNKNOWN"
        elif list(predictedProbability.flatten())[np.argmax(predictedProbability)] > .3:
            return prediction
        else:
            return "UNKNOWN"