代碼:import?pandas?as?pd
import?tensorflow?as?tf
import?matplotlib?as?plt
data=pd.read_csv("datasets/credit-a.csv",header=None)
print(data.head())
print(data.iloc[:,-1].value_counts())#.iloc[]與loc一樣,中括號里面也是先行后列,行列標(biāo)簽用逗號分割
#data.iloc[:,-1].replace(-1,0)
x=data.iloc[:,:-1]#所有行,除了最后一列的所有列
y=data.iloc[:,-1].replace(-1,0)#用0替換掉改列所有的-1
model=tf.keras.Sequential()
model.add(tf.keras.layers.Dense(4,input_shape=(15,),activation='relu'))
model.add(tf.keras.layers.Dense(4,activation='relu'))
model.add(tf.keras.layers.Dense(1,activation='sigmoid'))
model.summary()
print("-----------------")
model.compile(optimizer='adam',loss='binary_crossentropy',metircs=['acc'])
history=model.fit(x,y,epochs=100)
history.history.keys()
plt.title('model?loss')
plt.ylabel('loss')
plt.xlabel('epochs')
plt.plot(history.epoch,history.history.get('loss'))
plt.show()
#model.evaluate(x,y)報(bào)錯(cuò):D:\Python\Anaconda3\python.exe D:/Python/workspace/Deeplearning/tensorflow2/Logisticsregression.py? ?0? ? ? 1? ? ? 2? ?3? ?4? ?5? ?6? ? ?7? ?8? ?9? ?10? 11? 12? ?13? ? ?14? 150? ?0? 30.83? 0.000? ?0? ?0? ?9? ?0? 1.25? ?0? ?0? ?1? ?1? ?0? 202? ? 0.0? -11? ?1? 58.67? 4.460? ?0? ?0? ?8? ?1? 3.04? ?0? ?0? ?6? ?1? ?0? ?43? 560.0? -12? ?1? 24.50? 0.500? ?0? ?0? ?8? ?1? 1.50? ?0? ?1? ?0? ?1? ?0? 280? 824.0? -13? ?0? 27.83? 1.540? ?0? ?0? ?9? ?0? 3.75? ?0? ?0? ?5? ?0? ?0? 100? ? 3.0? -14? ?0? 20.17? 5.625? ?0? ?0? ?9? ?0? 1.71? ?0? ?1? ?0? ?1? ?2? 120? ? 0.0? -1?1? ? 357-1? ? 296Name: 15, dtype: int642019-11-22 16:51:11.891738: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2Model: "sequential"_________________________________________________________________Layer (type)? ? ? ? ? ? ? ? ?Output Shape? ? ? ? ? ? ? Param #? ?=================================================================dense (Dense)? ? ? ? ? ? ? ? (None, 4)? ? ? ? ? ? ? ? ?64? ? ? ??_________________________________________________________________dense_1 (Dense)? ? ? ? ? ? ? (None, 4)? ? ? ? ? ? ? ? ?20? ? ? ??_________________________________________________________________dense_2 (Dense)? ? ? ? ? ? ? (None, 1)? ? ? ? ? ? ? ? ?5? ? ? ? ?=================================================================Total params: 89Trainable params: 89Non-trainable params: 0_________________________________________________________________-----------------WARNING:tensorflow:Falling back from v2 loop because of error: Failed to find data adapter that can handle input: <class 'pandas.core.frame.DataFrame'>, <class 'NoneType'>Traceback (most recent call last):? File "D:/Python/workspace/Deeplearning/tensorflow2/Logisticsregression.py", line 20, in <module>? ? history=model.fit(x,y,epochs=100)? File "D:\Python\Anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 728, in fit? ? use_multiprocessing=use_multiprocessing)? File "D:\Python\Anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training_arrays.py", line 674, in fit? ? steps_name='steps_per_epoch')? File "D:\Python\Anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training_arrays.py", line 189, in model_iteration? ? f = _make_execution_function(model, mode)? File "D:\Python\Anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training_arrays.py", line 565, in _make_execution_function? ? return model._make_execution_function(mode)? File "D:\Python\Anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 2184, in _make_execution_function? ? self._make_train_function()? File "D:\Python\Anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 2133, in _make_train_function? ? **self._function_kwargs)? File "D:\Python\Anaconda3\lib\site-packages\tensorflow_core\python\keras\backend.py", line 3772, in function? ? 'eager execution. You passed: %s' % (kwargs,))ValueError: Session keyword arguments are not support during eager execution. You passed: {'metircs': ['acc']}Process finished with exit code 1
信用卡邏輯回歸報(bào)錯(cuò)
qq_莫非
2019-11-22 17:05:09