我有大约 45000
个样本的数据集,每个样本的二进制输出为 0
或 1
。但是在使用 sklearn 包中的 MLP 分类器之后,我获得了一个无论输入是什么,输出始终为 1
的模型。 0
类的精度为零。我尝试更改模型的超参数,但输出是相同的。谁能建议一种克服它的方法?
precision recall f1-score support
0 0.00 0.00 0.00 19967
1 0.57 1.00 0.73 26688
avg / total 0.33 0.57 0.42 46655
PS:我的代码
loc = './new_attributes_66.csv'
data = pd.read_csv(loc)
scaler = MinMaxScaler(feature_range = (-1,1))
scaler.fit(data)
data = scaler.transform(data)
print data
input = data[:,0:64]
output = data[:,65]
X_tr, X_tst, y_tr, y_tst = train_test_split(input, output, test_size=0.1)
clf = MLPClassifier(solver='sgd', alpha=1e-5, hidden_layer_sizes=(40,121), random_state=0, warm_start = True, tol = 0.0000001, early_stopping = False, learning_rate='adaptive',learning_rate_init = 0.1, max_iter=10000,shuffle=True,verbose=True)
clf.fit(X_tr,y_tr)
predicted = clf.predict(input)
#print "Accuracy using MLP classifier: "
print metrics.precision_score(output, predicted)
#print confusion_matrix(y_tst,predicted)
print metrics.classification_report(output,predicted)
#print clf.coefs_
数据集 (csv) 链接:https://app.box.com/s/vfqgool2u9ovdc9oyi9elq99aor6c6gk
更新: 我已经根据最新的结果修改了我的代码和结果。我可以提高精确度和召回率:
precision recall f1-score support
-1.0 0.53 0.10 0.17 19967
1.0 0.58 0.93 0.72 26688
avg / total 0.56 0.58 0.48 46655
准确度为58.14 %
。还可以通过哪些其他方式来改变超参数?
最佳答案
您的数据可能存在类别不平衡问题。可能出现的情况是,带有标签1
的样本数量远远多于带有标签0
的样本数量。有多种方法可以解决类别不平衡问题:
- Combating Imbalanced classes in machine Learning
- Perform under sample and over sampling to tackle class imbalance
- Stratified split - Sklearn
- SMOTE
您还可以尝试检查不同的 alpha 值或不同形状的隐藏层。也许您当前使用的配置无法正确学习。
关于python - 使用 MLP 分类器,类的精度为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46425023/