首页 > 其他分享 >4-观测值缩放

4-观测值缩放

时间:2023-02-09 00:02:17浏览次数:45  
标签:scalerd scaler 缩放 series 观测 pd inverted

import pandas as pd
import datetime
from sklearn.preprocessing import MinMaxScaler

# 加载数据
def parser(x):
    return datetime.datetime.strptime(x, '%Y/%m/%d')

ser = pd.read_csv('../LSTM系列/LSTM单变量1/data_set/shampoo-sales.csv', 
                header=0, parse_dates=[0], index_col=0, date_parser=parser).squeeze('columns')

X = ser.values
X = X.reshape(len(X), 1)  # MinMaxScaler函数需要矩阵作为输入,所以reshape数据为矩阵,因为是一维数组,所以生成的是n行1列的一个矩阵
scaler = MinMaxScaler(feature_range=(-1, 1))  # 定义缩放范围
scaler.fit(X)
scalerd_X = scaler.transform(X)
scalerd_series = pd.Series(scalerd_X[:, 0])
print(scalerd_series.head())

# 逆缩放
inverted_X = scaler.inverse_transform(scalerd_X)
inverted_series = pd.Series(inverted_X[:, 0])
print(inverted_series.head())

标签:scalerd,scaler,缩放,series,观测,pd,inverted
From: https://www.cnblogs.com/lotuslaw/p/17103776.html

相关文章