【发布时间】:2020-12-18 11:12:50
【问题描述】:
我被困在这个循环的错误之处,以对具有 25 个特征的数据框执行逻辑回归。
当我重塑它给出错误: “ValueError:预期的 2D 数组,得到 1D 数组: 数组=[-12.36677125 -12.91946925 -12.89317629 -13.16951215 -12.20588875 -12.44694704 -12.71370778 -12.69351738 -12.89451587 -12.0776727 -12.63723271 -13.39461116 -12.52027792]。 如果您的数据具有单个特征,则使用 array.reshape(-1, 1) 重塑您的数据,如果它包含单个样本,则使用 array.reshape(1, -1)。"
peptides = ['AYSLFSYNTQGR','IVLGQEQDSYGGK','EQLTPLIK','SPELQAEAK','SPELQAEAK','ALVQQMEQLR','SGVQQLIQYYQDQK','VVVHPDYR','GFVVAGPSR','CLCACPFK','VVEESELAR','FCDMPVFENSR','GYSIFSYATK',
'EPGCGCCSVCAR',
'LIQGAPTIR',
'YYLQGAK',
'ALGHLDLSGNR',
'DLLLPQPDLR',
'GPLQLER',
'IISIMDEK',
'LQDAEIAR',
'QINDYVEK',
'SVLGQLGITK',
'ADLSGITGAR',
'EQLSLLDR']
这是我想要交互的肽列表。它们应该是 X_train 的列标题。
LR_scores = []
logit_roc_auc =[]
y_pred = []
acc_score = []
for peptide in peptides:
model=LogisticRegression()
model.fit(X_train[peptide], y_train)
score = model.score(X_test[peptide], y_test)
y_pred=model.predict(X_test[peptide])
acc_score = accuracy_score(y_test, y_pred)
LR_scores.append(peptide,acc_score)
#Classification Report
print (classification_report(y_test,y_pred))
#Confusion Matrix
cnf_matrix = confusion_matrix(y_test,y_pred)
print(cnf_matrix)
#ROC_AUC Curves
y_predict_proba = model.predict_proba(X_test[peptide])
probabilities = np.array(y_predict_proba)[:, 1]
fpr, tpr, thresholds = roc_curve(y_test, probabilities, pos_label=1)
roc_auc = auc(fpr, tpr)
logit_roc_auc = roc_auc_score(y_test, model.predict(X_test[peptide]))
感谢任何帮助。
【问题讨论】:
标签: pandas numpy loops machine-learning logistic-regression