Automatyczna rekurencyjna eliminacja cech
Czas zautomatyzować ten rekurencyjny proces. Owiń rekurencyjny eliminator cech (RFE) wokół estymatora regresji logistycznej i podaj mu żądaną liczbę cech do wybrania.
Wszystkie niezbędne funkcje i pakiety zostały już wczytane, a cechy zostały przeskalowane.
To ćwiczenie jest częścią kursu
Redukcja wymiarowości w Pythonie
Instrukcje do ćwiczenia
- Utwórz RFE z estymatorem
LogisticRegression()i wybierz 3 cechy. - Wyświetl cechy i ich ranking.
- Wyświetl cechy, które nie zostały wyeliminowane.
Interaktywne ćwiczenie praktyczne
Spróbuj tego ćwiczenia, uzupełniając ten przykładowy kod.
# 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.")