【问题标题】:Type error during training of Decision Tree model in Python?在 Python 中训练决策树模型时出现类型错误?
【发布时间】:2021-05-22 19:09:24
【问题描述】:

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

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))

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

错误屏幕:

【问题讨论】:

  • edit 包含X_train_DTy_train_DT 的样本

标签: python pandas model decision-tree


【解决方案1】:

max_features = sqrt 应该是max_features = 'sqrt'

【讨论】:

    猜你喜欢
    • 2021-05-18
    • 1970-01-01
    • 2020-08-18
    • 2022-06-22
    • 1970-01-01
    • 2019-11-21
    • 1970-01-01
    • 2019-05-06
    • 1970-01-01
    相关资源
    最近更新 更多