我们在训练DL模型以预测贷款得分(分类为0、1或3)时遇到以下问题。
这些步骤是:
conditions = [
(df2['Credit Score'] >= 0) & (df2['Credit Score'] < 1000),
(df2['Credit Score'] >= 1000) & (df2['Credit Score'] < 6000),
(df2['Credit Score'] >= 6000) & (df2['Credit Score'] <= 7000)]
choices = [0,1,2]
df2['Scoring'] = np.select(conditions, choices)
array = df2.values
X = np.vstack((array[:,2:3].T, array[:,5:15].T)).T
Y = array[:,15:]
N = Y.shape[0]
T = np.zeros((N, np.max(Y)+1))
for i in range(N):
T[i,Y[i]] = 1
x_train, x_test, y_train, y_test = train_test_split(X, T, test_size=0.2, random_state=42)
model = Sequential()
model.add(Dense(80, input_shape=(11,), activation='tanh'))
model.add(Dropout(0.2))
model.add(Dense(80, activation='tanh'))
model.add(Dropout(0.1))
model.add(Dense(40, activation='relu'))
model.add(Dense(3, activation='softmax'))
epochs =200
learning_rate = 0.00001
decay_rate = learning_rate / epochs
momentum = 0.002
sgd = SGD(lr=learning_rate, momentum=momentum, decay=decay_rate, nesterov=False)
ad = Adamax(lr=learning_rate)
epochs = 200
batch_size = 16
history = model.fit(x_train, y_train, validation_data=(x_test, y_test), nb_epoch=epochs,
batch_size=batch_size,validation_split=0.1)
print ('fit done!')
指标
365/365 [==============================]-0s 60us / sample-损耗:0.0963-acc:0.9808测试装置损失:0.096准确性:0.981
text1 = [1358,1555,1,3,1741,8,0,1596,1518,0,0] #scoring 0
text2 = [1454,1601,3,11,1763,10,0,685,1044,0,0] #scoring 1
text3 = [1209,1437,3,11,199,18,1,761,1333,1,0] #scoring 2
tmp = np.vstack(text1).T
textA = tmp.reshape(1,-1)
tmp = np.vstack(text2).T
textB = tmp.reshape(1,-1)
tmp = np.vstack(text3).T
print(tmp)
textC = tmp.reshape(1,-1)
p = model.predict(textA)
t = p[0]
print(textA,np.argmax(t))
p = model.predict(textB)
t = p[0]
print(textB,np.argmax(t))
p = model.predict(textC)
t = p[0]
print(textC,np.argmax(t))
问题:预测中的输出始终相同!!!
[9.9205679e-01 3.8634153e-04 7.5568780e-03] [[1358 1555 1 3 1741 8 0 1596 1518 0 0]] 0 ---得分0
[0.9862417 0.00205712 0.01170125] [[1454 1601 3 11 1763 10 0 685 1044 0 0]] 0 ---得分0
[9.9251783e-01 2.5733517e-04 7.2247880e-03] [[1209 1437 3 11 199 18 1 761 1333 1 0]] 0 ----得分0
发生这种现象的原因是什么?
提前致谢!
您的数据集非常不平衡。观察它的一种好方法是:如果总是预测0可使您达到98%的准确度,那么说某物属于另一个类是非常冒险的(或者必须非常明显)。NN可能发现的使少数派类别与多数派类别(0)不同的每个模式都必须非常独特,因为即使重叠很小,不预测0的成本也很高。
考虑以下示例:您有一个包含两个类A和B的数据集,这两个类都遵循正态分布。A类的均值为1和std 1,B的均值为3和std 0.1。您有1,000,000个类别0的样本和20,000个类别1的样本,因此始终预测A会为您提供98%的准确性。B类的所有样本将位于2.743和3.257之间,置信度为99%。在这些值之间,A类预计将有29,300个样本,因此,预测B类观测到的任何观测值的成本将在29,300个A样本中产生误差,但是将所有事物预测为A的成本将仅在20,000个B样本中产生误差。 。
该示例以图形方式显示如下:
import numpy as np
import matplotlib.pyplot as plt
# Get A and B
A = np.random.normal(1, 1, 1000000)
B = np.random.normal(3, 0.1, 20000)
# Count the number of observations in A for each B
B.sort()
a = A[np.logical_and(A >= B.min(), A <= B.max())]
a = [(a<i).sum() for i in B]
# Plot results
plt.plot(B, np.arange(B.shape[0]), label='Class B')
plt.plot(B, a, label='Class A')
plt.ylabel('Count of samples')
plt.xlabel('Values')
plt.legend()
plt.show()
请参阅有关平衡数据集的这篇文章:https : //www.kdnuggets.com/2017/06/7-techniques-handle-imbalanced-data.html
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句