简体   繁体   English

神经网络未在明确的线性可分离问题上收敛

[英]Neural network not converging on clear linearly seperable problem

I am developing a neural network in Keras and I want to test to make sure it works. 我正在Keras开发神经网络,我想进行测试以确保其正常工作。 The feature set is obviously linearly seperable ('A' and 'N' in the below figure) but for some reason when I run my neural network using heart rate variability (HRV in the figure) as the sole feature, it doesn't think the positive training examples ('A' training examples) are unique: 功能集显然是线性可分离的(下图中的“ A”和“ N”),但是由于某些原因,当我使用心率变异性(图中的HRV)作为唯一功能运行神经网络时,它并不认为积极的培训示例(“ A”培训示例)是独特的:

明显线性可分离

My neural network architecture is a simple one: 我的神经网络架构很简单:

model = Sequential()

model.add(Dense(10, input_shape=(None, X_train.shape[1]),
           activation='sigmoid'))

model.add(Dense(10, activation='sigmoid'))

model.add(Dense(1, activation='sigmoid'))

opt = tf.keras.optimizers.Adam(lr=learning_rate, decay=decay_rate)

model.compile(loss=loss_fn, optimizer=opt, metrics=['acc'])

model.fit(X_train, y_train, epochs=n_epochs, validation_data=(X_test, y_test))

When I test the accuracy using a confusion matrix, the NN overfits to the negative training examples: 当我使用混淆矩阵测试准确性时,NN过度适合于负面训练示例:

          precision    recall  f1-score   support

     0.0       0.72      1.00      0.84     20774
     1.0       0.00      0.00      0.00      8126

accuracy                           0.72     28900
macro avg       0.36      0.50      0.42     28900
weighted avg       0.52      0.72      0.60     28900

Any suggestions? 有什么建议么?

Edit: Additional hyperparamters 编辑:其他超参数

Training vector shape:(67432, 1, 1)
Example of first element:[[72.710655]

loss_fn = 'binary_crossentropy'
learning_rate = 1e-2
decay_rate = 1e-8
n_epochs = 10 (have varied this but still converges to negative training example)

Edit: Additional information 编辑:附加信息

I wanted to include how I formatting my arrays in case the issue is with that: 我想包括如何格式化数组,以防出现问题:

X_train = np.asarray(X_train).reshape(
    X_train.shape[0], 1, X_train.shape[1])

X_test = np.asarray(X_test).reshape(
    X_test.shape[0], 1, X_test.shape[1])

Since you have imbalanced data you may want to use class_weight in model.fit 由于您的数据不平衡,您可能需要在model.fit中使用class_weight

model.fit(X_train, y_train, epochs=n_epochs, validation_data=(X_test, y_test), class_weight=class_weight)

Here class_weight is a dictionary. 这里class_weight是字典。 One option you can try is to set the class weight inversely proportional to the class size, ie the number of data points of each class. 您可以尝试的一种选择是将班级权重与班级大小(即每个班级的数据点数)成反比。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM