使用步骤名称从列表中删除步骤
Deleting a step from a list using the step name
我在使用步骤名称从列表中删除预处理步骤时遇到了一些问题,或者我可以使用索引值轻松删除步骤,但我如何才能对步骤名称执行相同操作
代码
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)
您可以先找到您的项目索引:
ind = [t[0] for t in preprocessing].index('maxabs_scaler')
然后删除项目:
del preprocessing[ind]
我在使用步骤名称从列表中删除预处理步骤时遇到了一些问题,或者我可以使用索引值轻松删除步骤,但我如何才能对步骤名称执行相同操作
代码
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)
您可以先找到您的项目索引:
ind = [t[0] for t in preprocessing].index('maxabs_scaler')
然后删除项目:
del preprocessing[ind]