在 Python 中训练决策树模型期间输入错误?

时间:2021-02-19 19:02:17

标签: python pandas model decision-tree

我有如下代码和错误,错误在哪里?我能做什么?当我将此代码用于其他模型时,一切都很好:

X_DT = data_modelling.loc[:, data.columns != "wine_type"]
y_DT = data_modelling.loc[:, data.columns == "wine_type"]

#Loop to find optimal train / test split
for k in range(1, 10):
    X_train_DT, X_test_DT, y_train_DT, y_test_DT = train_test_split(X_DT,
                                                                    y_DT,
                                                                    test_size = 0.1*k,
                                                                    random_state = 777)
    
    
    DT = DecisionTreeClassifier(criterion = "gini",
                                splitter = "random",
                                max_depth = 12,
                                min_samples_split = 2,
                                min_samples_leaf = 3,
                                max_features = sqrt)
    DT.fit(X = X_train_DT, y = y_train_DT)
    
    prediction_train_DT = DT.predict(X_train_DT)
    #Prediction on test dataset
    prediction_test_DT = DT.predict(X_test_DT)
    
    #Printing results
    print(f"test: {k/10}, Train AUC:", round(roc_auc_score(y_train_DT, prediction_train_DT), 3),
          "Test AUC:", round(roc_auc_score(y_test_DT, prediction_test_DT), 3))

和错误: 类型错误:“numpy.ufunc”和“float”的实例之间不支持“>”

错误画面: enter image description here

1 个答案:

答案 0 :(得分:0)

max_features = sqrt 应该是 max_features = 'sqrt'