LoslegenKostenlos loslegen

Automatisches rekursives Feature Elimination

Jetzt automatisieren wir diesen rekursiven Prozess. Wickle einen Recursive Feature Eliminator (RFE) um unseren Logistic-Regression-Schätzer und übergib die gewünschte Anzahl an Features.

Alle nötigen Funktionen und Pakete sind bereits geladen, und die Features wurden für dich skaliert.

Diese Übung ist Teil des Kurses

Dimensionsreduktion in Python

Kurs anzeigen

Anleitung zur Übung

  • Erstelle das RFE mit einem LogisticRegression()-Schätzer und wähle 3 Features aus.
  • Gib die Features und ihr Ranking aus.
  • Gib die Features aus, die nicht eliminiert werden.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# 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.") 
Code bearbeiten und ausführen