【发布时间】:2022-02-16 18:23:13
【问题描述】:
有没有人有任何建议,以便我可以在输入具有超过 1 列的 X 矩阵时使用以下函数(即多元线性回归)?
def AUC_calculation(X, y, index_train, index_test):
Xtrain, ytrain = X[index_train], y[index_train]
Xtest, ytest = X[index_test], y[index_test]
model=model1.fit(np.c_[np.ones(len(Xtrain)), Xtrain],ytrain)
predprob=model.predict_proba(np.c_[np.ones(len(Xtest)), Xtest])[:,1]
fpr, tpr, _ = roc_curve(ytest, predprob, pos_label=1)
AUC1=auc(fpr,tpr)
return AUC1
def AUC_cross_validation(X, y, n_fold):
str_kf = StratifiedKFold(n_splits=n_fold)
list_auc = np.zeros(n_fold)
for j, (index_train, index_test) in enumerate(str_kf.split(X,y)):
list_auc[j]=AUC_calculation(X, y, index_train, index_test)
return list_auc
我在尝试时收到此错误。
AUC_cross_validation(Data1_num.drop(['loanDefault'], axis='columns'), Data1_num.loanDefault, 10)
"没有 [Int64Index([100, 101, 102, 103, 104, 105, 106, 107, 108, 109,\n ...\n 990, 991, 992, 993, 994, 995, 996 , 997, 998, 999],\n dtype='int64', length=900)] 在[列]"
【问题讨论】:
标签: python function statistics