This repository has been archived on 2026-06-23. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
cas-pml/SL/aufgaben/template/4_WS/WS 11 Vorlage.ipynb
T
2026-05-21 14:16:30 +02:00

4.9 KiB

WS 11 permutation_importance

  • ermitteln Sie die Importance der Features der Rohdaten von melb_data.csv unter Einsatz von sklearn.inspection.ermutation_importance
  • setzen Sie dazu minimales Feature Engineering wie folgt ein:
    • entfernen fragwürdiger Variablen: 'Unnamed: 0', 'Suburb', 'Address', 'SellerG', 'Postcode', 'Bedroom2', 'Date', 'CouncilArea'
    • One-Hot encoding aller verbleibenden kategorialen Variablen (der Parameter dummy_na=True von pd.get_dummies() erstellt auch Dummy-Variablen für NAs)
    • einsetzen von geschätzten Werten für NAs in verbleibenden numerischen Variablen mit sklearn.impute.KNNImputer
  • danach:
    • features - target - split
    • kein train - test - split
    • ermitteln der Importance unter Einsatz von
      • sklearn.inspection.permutation_importance
      • sklearn.tree.DecisionTreeRegressor
    • tabellarische und graphische Darstellung der Ergebnisse
In [4]:
## prepare env, read and prepare data
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns; sns.set()

codepath = '../2_code'
datapath = '../3_data'
from sys import path; path.insert(1, codepath)
from os import chdir; chdir(datapath)
In [5]:
## read data
data = pd.read_csv('melb_data.csv')
In [6]:
## drop columns
vars_to_drop = ['Unnamed: 0', 'Suburb', 'Address', 'SellerG', 'Postcode', 'Bedroom2', 'Date', 'CouncilArea']
data = data.drop(vars_to_drop, axis=1)
In [7]:
## one-hot encode (incl. NAs)
data = pd.get_dummies(data, drop_first=False, dummy_na=True)
In [8]:
## KNNImputer for NAs
## tbd


In [9]:
## features - target - split
## tbd


In [10]:
## permutation_importance
## tbd


In [ ]:
## collect results in a dataframe, ordered by mean
## tbd


In [12]:
## visualize results
## tbd