gpt4 book ai didi

python - MinMaxScaler 无法正确缩放

转载 作者:行者123 更新时间:2023-12-01 01:21:11 24 4
gpt4 key购买 nike

我正在使用从 Lynda.com 获取的 sklearn MinMaxScaler 代码来缩放预测代码的数据集。特征范围应该是 (0,1),但我注意到我的试验数据中有些列大于 1。我相信这导致我的预测代码输出不正确。有人可以帮忙吗? Belo 是我正在使用的代码...

import pandas as pd
from sklearn.preproMinmaxcessing import MinMaxScaler

# Load training data set from CSV file
training_data_df = pd.read_csv("10596_data_training.csv")

# Load testing data set from CSV file
test_data_df = pd.read_csv("10596_data_test.csv")

# Load the trial data set from CSV file
trial_data_df = pd.read_csv("day05.csv")

# Data needs to be scaled to a small range like 0 to 1 for the neural
# network to work well.
scaler = MinMaxScaler(feature_range=(0, 1))

# Scale both the training inputs and outputs
scaled_training = scaler.fit_transform(training_data_df)
scaled_testing = scaler.transform(test_data_df)
scaled_trial = scaler.transform(trial_data_df)

# Print out the adjustment that the scaler applied to the total_earnings column of data
print("Note: total_hours values were scaled by multiplying by {:.10f} and adding {:.6f}".format(scaler.scale_[40], scaler.min_[40]))

# Create new pandas DataFrame objects from the scaled data
scaled_training_df = pd.DataFrame(scaled_training, columns=training_data_df.columns.values)
scaled_testing_df = pd.DataFrame(scaled_testing, columns=test_data_df.columns.values)
scaled_trial_df = pd.DataFrame(scaled_trial, columns=trial_data_df.columns.values)

# Save scaled data dataframes to new CSV files
scaled_training_df.to_csv("10596_data_training_scaled.csv", index=False)
scaled_testing_df.to_csv("10596_data_test_scaled.csv", index=False)
scaled_trial_df.to_csv("day05_scaled.csv", index=False)

最佳答案

您正在数据的子集上“训练”MinMaxScaler,然后转换不同的子集。 MinMaxScaler 只是减去训练集的最小值,然后除以最大值。如果试验集的值大于训练集的最大值或小于训练集的最小值,则您的值将超出 [0,1] 范围。这是预期的并且可以接受的。

关于python - MinMaxScaler 无法正确缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53819718/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com