我正在使用sklearn minmaxscaler代码,我从lynda.com上脱离了预测代码的数据集。功能护林员应为(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]范围之外的值。这是可以预期的。