from sklearn.pipeline import _name_estimators
class MajorityVoteClassifier(BaseEstimator,ClassifierMixin):
def __init__(self,classifiers,vote='classlabel',weights=None):
self.classifiers = classifiers
self.named_classifiers={key:value for key,value in
_name_estimators(classifiers)}
self.vote=vote
self.weights=weights
clf1=LogisticRegression(penalty='l2',C=0.001,random_state=1)
clf2=DecisionTreeClassifier(max_depth=1,criterion='entropy',
random_state=0)
clf3=KNeighborsClassifier(n_neighbors=1,p=2,metric='minkowski')
pipe1=Pipeline([['sc',StandardScaler()],['clf',clf1]])
pipe3=Pipeline([['sc',StandardScaler()],['clf',clf3]])
mv_clf=MajorityVoteClassifier(classifiers=[pipe1,clf2,pipe3])
我无法理解_name_estimators
是如何工作的,所以请
有人给我解释一下_name_estimators
在这段代码中做了什么
您可以在交互模式下运行:
所以基本上它返回元组,带有唯一的键。每个元组包含估计量+如果估计量是重复的,则包含它的出现和原始估计量值。你知道吗
你给函数名估计器一个n个估计器的列表,它返回一个n个元组的列表。每个元组中的第一个组件是描述估计器名称的字符串,每个元组的第二个组件是估计器对象
相关问题 更多 >
编程相关推荐