Skip to content

Instantly share code, notes, and snippets.

@occult
Created July 16, 2020 19:31
Show Gist options
  • Save occult/27c8abbbfb1d118021508e612a6c7fe4 to your computer and use it in GitHub Desktop.
Save occult/27c8abbbfb1d118021508e612a6c7fe4 to your computer and use it in GitHub Desktop.
Numeric features engineering
train_test_features['YearsSinceBuilt'] = train_test_features['YrSold'].astype(int) - train_test_features['YearBuilt'].astype(int)
train_test_features['YearsSinceRemod'] = train_test_features['YrSold'].astype(int) - train_test_features['YearRemodAdd'].astype(int)
train_test_features['TotalWalledArea'] = train_test_features['TotalBsmtSF'] + train_test_features['GrLivArea']
train_test_features['TotalPorchArea'] = train_test_features['OpenPorchSF'] + train_test_features['3SsnPorch'] + train_test_features['EnclosedPorch'] + train_test_features['ScreenPorch'] + train_test_features['WoodDeckSF']
train_test_features['TotalOccupiedArea'] = train_test_features['TotalWalledArea'] + train_test_features['TotalPorchArea']
train_test_features['OtherRooms'] = train_test_features['TotRmsAbvGrd'] - train_test_features['BedroomAbvGr'] - train_test_features['KitchenAbvGr']
train_test_features['TotalBathrooms'] = train_test_features['FullBath'] + (0.5 * train_test_features['HalfBath']) + train_test_features['BsmtFullBath'] + (0.5 * train_test_features['BsmtHalfBath'])
train_test_features['LotDepth'] = train_test_features['LotArea'] / train_test_features['LotFrontage']
train_test_features['YearAvg']= (train_test_features['YearRemodAdd']+train_test_features['YearBuilt'].astype(int))/2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment