Можем ли мы дать максимальные и минимальные значения статически при нормализации, используя MinMaxScaler Sklearn? - PullRequest
1 голос
/ 30 марта 2020

Итак, у меня есть это сомнение и я искал ответы.

Ниже приведен входной пост-запрос

{
    "emotive_Score": [0.89,0.57,0.089,0,0.004,0,0],
    "sentiment_Score": [1.521894,-6.4523187],
    "mood_score":[40]
}

И я использую следующий код для масштабирования значений.

from flask import Flask, request
from flask_restful import Resource, Api
from json import dumps
from sklearn import preprocessing
import numpy as np


class MoodScore(Resource):
    def post(self):
        json_data = request.get_json(force=True)
        if not json_data: 
             return {'message': 'No input data provided'}, 400    
        x = request.json['emotive_Score']
        x1 = request.json['sentiment_Score']
        x2 = request.json['mood_score']


        #Normalisation for Emotive Score
        xEmotive = np.array(x)

        PositiveEmotive = str(xEmotive[4]+xEmotive[6])

        NegativeEmotive = str(xEmotive[0]+xEmotive[1]+xEmotive[2]+xEmotive[3]+xEmotive[5])

        EmotiveScoreArray = (PositiveEmotive,NegativeEmotive)
        Nml = np.array(EmotiveScoreArray)
        float_array = Nml.astype(np.float)
        xM = float_array.reshape(-1,1)

        minmaxscaler = preprocessing.MinMaxScaler(feature_range=(0,1))
        Emotive = minmaxscaler.fit_transform(xM)


        #Normalisation for Sentiment Score
        xSentiment = np.array(x1)

        PositiveSentiment = str(xSentiment[0])

        NegativeSentiment = str(xSentiment[1])

        SentimentScoreArray = (PositiveSentiment,NegativeSentiment)

        Nml1 = np.array(SentimentScoreArray)
        float_array1 = Nml1.astype(np.float)
        xM1 = float_array1.reshape(-1,1)

        minmaxscaler1 = preprocessing.MinMaxScaler(feature_range=(-1,1))
        Sentiment = minmaxscaler1.fit_transform(xM1)


        return {'PositiveEmotive':str(Emotive[0]),'NegativeEmotive':str(Emotive[1]),'PositiveSentiment':str(Sentiment[0]),'NegativeSentiment':str(Sentiment[1]),'FinalValue':str(Emotive[0]+Emotive[1]+Sentiment[0]+Sentiment[1])}

        # return {'FinalScore': str(Sentiment)}


app = Flask(__name__)       
api = Api(app)
api.add_resource(MoodScore, '/moodScore')

if __name__ == '__main__':
     app.run(port='5005', host="0.0.0.0")

И я получаю следующее в качестве вывода:

{
    "PositiveEmotive": "[0.]",
    "NegativeEmotive": "[1.]",
    "PositiveSentiment": "[1.]",
    "NegativeSentiment": "[-1.]",
    "FinalValue": "[1.]"
}

Я просто хочу знать, могу ли я дать значения stati c для Min & Max во время вычисления нормализации так, что я могу получить желаемый результат, как показано ниже

{
    "PositiveEmotive": "[0.546]",
    "NegativeEmotive": "[1.]",
    "PositiveSentiment": "[0.598]",
    "NegativeSentiment": "[-0.6879.]",
    "FinalValue": "[1.4561]"
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...