iT邦幫忙

第 11 屆 iT 邦幫忙鐵人賽

DAY 24
0

新增特徵

features = features.drop(['Utilities', 'Street', 'PoolQC',], axis=1)


# 根據其他特徵的文字敘述 組成新的特徵 

features['YrBltAndRemod']=features['YearBuilt']+features['YearRemodAdd']
features['TotalSF']=features['TotalBsmtSF'] + features['1stFlrSF'] + features['2ndFlrSF']

features['Total_sqr_footage'] = (features['BsmtFinSF1'] + features['BsmtFinSF2'] +
                                 features['1stFlrSF'] + features['2ndFlrSF'])

features['Total_Bathrooms'] = (features['FullBath'] + (0.5 * features['HalfBath']) +
                               features['BsmtFullBath'] + (0.5 * features['BsmtHalfBath']))

features['Total_porch_sf'] = (features['OpenPorchSF'] + features['3SsnPorch'] +
                              features['EnclosedPorch'] + features['ScreenPorch'] +
                              features['WoodDeckSF'])

有些變數是泳池、車庫面積等等,但是這沒有在模型中明確的表示出這棟房子擁有這個特徵,因此新增有泳池、車庫等等的特徵

features['haspool'] = features['PoolArea'].apply(lambda x: 1 if x > 0 else 0)
features['has2ndfloor'] = features['2ndFlrSF'].apply(lambda x: 1 if x > 0 else 0)
features['hasgarage'] = features['GarageArea'].apply(lambda x: 1 if x > 0 else 0)
features['hasbsmt'] = features['TotalBsmtSF'].apply(lambda x: 1 if x > 0 else 0)
features['hasfireplace'] = features['Fireplaces'].apply(lambda x: 1 if x > 0 else 0)
features.shape

上一篇
DAY[23]-Kaggle實戰 特徵轉換
下一篇
DAY[25]-Kaggle實戰 特徵處理(2)
系列文
Python機器學習介紹與實戰30

尚未有邦友留言

立即登入留言