【问题标题】:Function not able to compute for multiple column matrix input函数无法计算多列矩阵输入
【发布时间】: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


    【解决方案1】:

    我猜这是因为您需要为每个模型使用单个变量,在您的代码中 Xtrain 包含所有变量。使用for 循环。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-17
      • 2022-01-15
      • 2020-07-21
      • 2021-02-11
      • 2019-04-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多