Keras:培训时准确性不变的原因

时间:2017-11-30 00:25:57

标签: keras

我尝试在Keras中运行churn_modeling.csv文件,但我没有进行模型学习。这是我的代码:

# -*- coding: utf-8 -*-
import keras
from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import SGD
import pandas as pd 
import numpy as np 

#read from CSV file ,convert categorial value to one-hot-encoding and convert the result to numpy array
df=pd.read_csv("churn_modelling.csv")
X=pd.get_dummies(df, columns=['Geography','Gender'])
X=X[['CreditScore','Age','Tenure','Balance','NumOfProducts','HasCrCard','IsActiveMember','EstimatedSalary','Geography_France','Geography_Germany','Geography_Spain','Gender_Female','Gender_Male','Exited']]
dataset=X.as_matrix()


X_train=dataset[:,0:13]
Y_train=dataset[:,13]

model=Sequential()
model.add(Dense(26, input_dim=13,  activation='relu'))
#model.add(Dense(15, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
sgd = SGD(lr=0.02)
model.compile(loss='binary_crossentropy', optimizer=sgd, metrics=['accuracy'])

model.fit(X_train,Y_train, validation_split=0.05, epochs=10, batch_size=200)

这是我得到的输出: 训练9500个样本,验证500个样本

Epoch 1/10
9500/9500 [==============================] - 0s - loss: 3.7996 - acc: 0.7637 - val_loss: 2.8045 - val_acc: 0.8260
Epoch 2/10
9500/9500 [==============================] - 0s - loss: 3.3085 - acc: 0.7947 - val_loss: 2.8045 - val_acc: 0.8260
Epoch 3/10
9500/9500 [==============================] - 0s - loss: 3.3085 - acc: 0.7947 - val_loss: 2.8045 - val_acc: 0.8260
Epoch 4/10
9500/9500 [==============================] - 0s - loss: 3.3085 - acc: 0.7947 - val_loss: 2.8045 - val_acc: 0.8260
Epoch 5/10
9500/9500 [==============================] - 0s - loss: 3.3085 - acc: 0.7947 - val_loss: 2.8045 - val_acc: 0.8260
Epoch 6/10
9500/9500 [==============================] - 0s - loss: 3.3085 - acc: 0.7947 - val_loss: 2.8045 - val_acc: 0.8260
Epoch 7/10
9500/9500 [==============================] - 0s - loss: 3.3085 - acc: 0.7947 - val_loss: 2.8045 - val_acc: 0.8260
Epoch 8/10
9500/9500 [==============================] - 0s - loss: 3.3085 - acc: 0.7947 - val_loss: 2.8045 - val_acc: 0.8260
Epoch 9/10
9500/9500 [==============================] - 0s - loss: 3.3085 - acc: 0.7947 - val_loss: 2.8045 - val_acc: 0.8260
Epoch 10/10
9500/9500 [==============================] - 0s - loss: 3.3085 - acc: 0.7947 - val_loss: 2.8045 - val_acc: 0.8260

即使我用100个纪元运行程序,我仍然得到相同的结果val_acc:0.8260。谢谢

1 个答案:

答案 0 :(得分:1)

似乎如果重新训练训练集,准确度会略微提高86%。我使用了以下代码:

from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler(feature_range=(0, 1))
rescaledX_train = scaler.fit_transform(X_train)