首页 > 解决方案 > Python:TypeError:“类型”和“类型”的实例之间不支持“<”。Model.fit() 不起作用

问题描述

尝试在 Python 中绘制部分依赖图时遇到问题。我使用随机森林分类器创建模型:

model = RandomForestClassifier()
model.fit(X,y)

之后我想绘制对模型中一些特征的部分依赖。我试图通过运行以下代码来做到这一点

# PDP plot for most important feature of the model
from sklearn.inspection import plot_partial_dependence
disp1 = plot_partial_dependence(model.fit(X, y), X,
                                [8, 11,  12], target = int)  

但是,在这里我收到错误:TypeError: '<' not supported between 'type' and 'type' 我怎样才能让部分依赖图运行?

X (pandas.dataframe):16 列和 94.347 行的 DataFrame。

Location                    int64
Complex                     int64
OR                          int64
Surgery                     int64
Operating region            int64
Urgency                     int64
Specialism                  int64
Surgeon                     int64
Size of surgical team       int64
Gender head surgeon         int64
Gender patient              int64
Age                         int64
BMI                         object
Weekday (Sunday =1)         int64
Time of Day                 int64
Expected Operating Time     int64
dtype: object

Y (pandas.series):int64,1 列和 94.347 行

标签: pythonpandasmodel

解决方案


推荐阅读