我在使用步骤的名称从列表中删除预处理步骤时遇到了一些问题,或者我可以使用索引值轻松删除步骤,但是如何使用步骤的名称执行相同的操作
代码
from sklearn.preprocessing import MaxAbsScaler
from sklearn.pipeline import Pipeline
# list to which preprocessing steps will be added
preprocessing=[]
#appending MaxAbsScaler into the list
preprocessing.append(('maxabs_scaler',
MaxAbsScaler(copy=1)))
#placing the list inside pipeline
pipe=Pipeline(preprocessing)
#deleting MaxAbsScaler from the list
#this crashes
preprocessing.pop('maxabs_scaler')
print(preprocessing)发布于 2021-11-21 20:05:40
您可以首先找到您的项目的索引:
ind = [t[0] for t in preprocessing].index('maxabs_scaler')然后删除项目:
del preprocessing[ind]https://stackoverflow.com/questions/70057108
复制相似问题