시작하기무료로 시작하기

자동화된 재귀적 특징 제거

이제 이 재귀 과정을 자동화해 보겠습니다. Logistic regression 추정기를 Recursive Feature Eliminator(RFE)로 감싸고, 선택할 특징 수를 지정해 주세요.

필요한 함수와 패키지는 모두 미리 로드되어 있으며, 특징들은 이미 스케일링되어 있어요.

이 연습은 강의의 일부입니다

Python으로 배우는 차원 축소

강의 보기

연습 안내

  • LogisticRegression() 추정기와 선택할 특징 수 3개로 RFE를 생성하세요.
  • 특징들과 그 ranking을 출력하세요.
  • 제거되지 않은 특징들을 출력하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Create the RFE with a LogisticRegression estimator and 3 features to select
rfe = ____(estimator=____, n_features_to_select=____, verbose=1)

# Fits the eliminator to the data
rfe.fit(X_train, y_train)

# Print the features and their ranking (high = dropped early on)
print(dict(zip(X.columns, rfe.____)))

# Print the features that are not eliminated
print(X.columns[rfe.____])

# Calculates the test set accuracy
acc = accuracy_score(y_test, rfe.predict(X_test))
print(f"{acc:.1%} accuracy on test set.") 
코드 편집 및 실행