에 맞는 후 모든 대치 값을 인쇄하려고합니다 SimpleImputer
. 단독으로 사용 SimpleImputer
하는 경우 인스턴스의 statistics_
속성 에서이를 검색 할 수 있습니다 .
이것은 잘 작동합니다.
s = SimpleImputer(strategy='mean')
s.fit(df[['feature_1', 'feature_2']])
print(s.statistics_)
그러나 SimpleImputer
파이프 라인에서 사용할 때는 그렇게 할 수 없습니다 .
작동하지 않습니다.
numeric_transformer = Pipeline(steps=[
('simple_imputer', SimpleImputer(strategy='mean')),
('scaler', StandardScaler())])
categorical_features = ['feature_3']
categorical_transformer = Pipeline(steps=[
('simple_imputer', SimpleImputer(strategy='most_frequent')),
('one_hot', OneHotEncoder(handle_unknown='ignore'))])
preprocessor = ColumnTransformer(
transformers=[
('num', numeric_transformer, numeric_features),
('cat', categorical_transformer, categorical_features)])
clf = Pipeline(steps=[('preprocessor', preprocessor),
('classifier', RandomForestClassifier(n_estimators=100))])
clf.fit(df[numeric_features + categorical_features], df['target'])
print(clf.named_steps['preprocessor'].transformers[0][1].named_steps['simple_imputer'].statistics_)
다음과 같은 오류가 발생합니다.
AttributeError Traceback (most recent call last)
<ipython-input-523-7390eac0d9d6> in <module>
19 clf.fit(df[numeric_features + categorical_features], df['target'])
20
---> 21 print(clf.named_steps['preprocessor'].transformers[0][1].named_steps['simple_imputer'].statistics_)
AttributeError: 'SimpleImputer' object has no attribute 'statistics_
나는 내가 맞는 SimpleImputer
물체 의 정확한 인스턴스를 잡고 있다고 믿는다 . statistics_
대치 값을 인쇄하기 위해 속성을 검색 할 수없는 이유는 무엇 입니까?
특히 sklearn
파이프 라인의 구조 / 속성을 탐색하는 데 도움이되는 자동 완성 기능을 사용하기 때문에 파이프 라인 작업시 '점'표기법을 사용하는 것이 더 쉽습니다 . 또한 더 읽기 쉬운 추가 보너스가 있습니다.
다음 줄을 사용하여의 statistics_
속성에 액세스 할 수 있습니다 SimpleImputer
.
clf.named_steps.preprocessor.named_transformers_.num.named_steps.simple_imputer.statistics_
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다