Neural network 我们能给Max&;使用MinMaxScaler Sklearn在规范化过程中静态最小值?

Neural network 我们能给Max&;使用MinMaxScaler Sklearn在规范化过程中静态最小值?,neural-network,normalization,scaling,Neural Network,Normalization,Scaling,所以,我有这个疑问,一直在寻找答案 下面是输入post请求 { "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 js

所以,我有这个疑问,一直在寻找答案

下面是输入post请求

{
    "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.]"
}
我只是想知道,在标准化计算过程中,我是否可以将静态值赋予最小值和最大值,以便得到如下所示的预期结果

{
    "PositiveEmotive": "[0.546]",
    "NegativeEmotive": "[1.]",
    "PositiveSentiment": "[0.598]",
    "NegativeSentiment": "[-0.6879.]",
    "FinalValue": "[1.4561]"
}

Hi-Sai,对于'minmaxscaler'(0,1)和'minmaxscaler1'(-1,1),您尝试只拟合2个值。这将最终导致将这些较低的值分别转换为0和-1,将较高的值分别转换为1和1。感谢akhil penta,我曾尝试将最大值和最小值保留在输入数组中,现在我能够获得所需的值。您好,Sai,对于“minmaxscaler”(0,1)和“minmaxscaler1”(-1,1),您尝试只拟合2个值。这将最终导致将这些较低的值分别转换为0和-1,将较高的值分别转换为1和1。感谢akhil penta,我已尝试将最大值和最小值保留在输入数组本身中,现在我能够获得所需的值。