我有一个回归问题,我试图从Excel工作表中预测列set_random_seed(7)
df = pd.read_excel("ABC_sheet.xlsx")
data = df.iloc[:, 0:2]
labels_column = df['C']
training_data = data
training_labels = labels_column
print("Creating the pickle_model ...")
model = Sequential()
model.add(Dense(300, input_dim=2, activation='relu'))
model.add(Dense(300, activation='relu'))
model.add(Dense(300, activation='relu'))
model.add(Dense(300, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.summary()
print("pickle_models Fitting ...")
model.fit(training_data, training_labels, epochs=20000, verbose=1)
print("Training has been completed successfully!")
# Expected Res: 0.00531548914829121
Xnew0 = np.array([[0.54, 0.63446746]])
# Expected Res: 6.34934075187519E-07
Xnew = np.array([[0.44, 0.37447464]])
# Expected Res: 0.0000628
Xnew2 = np.array([[0.53, 0.00063189]])
# Expected Res: 0.00531548914829121
Xnew3 = np.array([[0.54, 0.63446746]])
ynew = model.predict(Xnew0)
ynew2 = model.predict(Xnew)
ynew3 = model.predict(Xnew2)
ynew5 = model.predict(Xnew3)
print("Predicted1 =%s, Predicted2 =%s, Predicted3 =%s, Predicted4 =%s, Predicted4 =%s" % (ynew[0], ynew2[0], ynew3[0], ynew5[0]))
的值(附有图片)。
Predicted1 =[0.00591827], Predicted2 =[6.762405e-08], Predicted3 =[0.00139873], Predicted4 =[0.00591827]
输出:
Predicted3 =[0.00139873]
结果与预期结果不符。由于Expected Res: 0.0000628
应该更接近def GetNormalizedValue(val, min, max):
if val > max:
val = max
if val < min:
val = min
if min == max:
return 0
denominator = max - min
numerator = float(val) - min
value = numerator / denominator
# print(value)
return value
def NormalizeData(df):
for index, row in df.iterrows():
col_A = row['A']
col_B = row['B']
col_C = row['C']
column_A = GetNormalizedValue(col_A, 0, 100)
column_B = GetNormalizedValue(col_B, 0, 1000000)
column_C = GetNormalizedValue(col_C, 1, 10000)
我也尝试使用不同数量的层/神经元。有什么帮助吗?
已编辑:
System.setProperty("webdriver.chrome.verboseLogging", "false");