尝试使用sc.fit_transform(X),我在同一模型上的准确性大幅下降。在不缩放我的数据集的值的情况下,我得到 80 - 82% 的准确度值。当我尝试使用 缩放它们时sc.fit_transform(X),我得到 70 - 74% 的准确度值。
准确度大幅下降的原因可能是什么?
编辑:
这是我正在使用的代码:
# read the dataset file
basic_df = pd.read_csv('posts.csv', sep=';', encoding = 'ISO-8859-1', parse_dates=[2], dayfirst=True)
# One-Hot-Encoding for categorical (strings) features
basic_df = pd.get_dummies(basic_df, columns=['industry', 'weekday', 'category_name', 'page_name', 'type'])
# bring the label column to the end
cols = list(basic_df.columns.values) # Make a list of all of the columns in the df
cols.pop(cols.index('successful')) # Remove target column from list
basic_df = basic_df[cols+['successful']] # Add it at the end of dataframe
dataset = basic_df.values
# separate the data from the labels
X = dataset[:,0:45].astype(float)
Y = dataset[:,45]
#standardizing the input feature
X = sc.fit_transform(X)
# evaluate model with standardized dataset
#estimator = KerasClassifier(build_fn=create_baseline, epochs=5, batch_size=5, verbose=0)
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.3, random_state=seed)
#estimator.fit(X_train, Y_train)
#predictions = estimator.predict(X_test)
#list(predictions)
# build the model
model = Sequential()
model.add(Dense(100, input_dim=45, kernel_initializer='normal', activation='relu'))
model.add(Dense(50, kernel_initializer='normal', activation='relu'))
model.add(Dense(1, kernel_initializer='normal', activation='sigmoid'))
# Compile model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# Fit the model
history = model.fit(X_train, Y_train, validation_split=0.3, epochs=500, batch_size=10)
有一部分代码被注释了,因为我一开始就尝试使用 KerasClassifier。但是,当我使用 fit_transform(X) 时,这两种方法最终的准确度都要低得多(如上所述)。在不使用 fit_transform(X) 的情况下,我得到了 80 - 82% 的准确率。没有 70 - 74%。怎么会?难道我做错了什么?缩放输入数据并不总是会导致更好的(或至少几乎相同的精度结果)并且主要是更快的拟合?为什么使用它的时候准确率会有这么大的下降?
PS: 'sc' 是 StandardScaler() --> sc = StandardScaler()

