**已关闭。**此问题需要调试详细信息。它目前不接受答案。
**想要改进此问题?**更新问题,使其位于堆栈溢出主题上。
两天前关门了。
改进这个问题
我正试图在房价上竞争——先进的回归技术——卡格尔竞争
我正在编写一个自定义转换器,它可以与添加组合属性的scikit学习功能无缝配合使用
变压器有四个超参数( add_baths, add_bsmt_baths, add_above_grade_baths, add_porch_area
)默认设置为true。这个超参数可以让我很容易地发现添加这些属性是否有助于机器学习算法。
但问题是,当我将其中一个超参数设置为false时,类仍然会返回列,就像我将其设置为true一样
class CombinedAttributesAdder(BaseEstimator, TransformerMixin):
def __init__(self, add_baths=True, add_bsmt_baths=True, add_above_grade_baths=True, add_porch_area=True):
self.add_baths = add_baths
self.add_bsmt_baths = add_bsmt_baths
self.add_above_grade_baths = add_above_grade_baths
self.add_porch_area = add_porch_area
def fit(self, X, y=None):
return self
def transform(self, X):
X['T_FlrSF'] = X['1stFlrSF'] + X['2ndFlrSF']
if self.add_baths:
X['T_Bath'] = X['BsmtFullBath'] + X['BsmtHalfBath'] + X['FullBath'] + X['HalfBath']
if self.add_bsmt_baths:
X['T_BsmtBath'] = X['BsmtFullBath'] + X['BsmtHalfBath']
if self.add_above_grade_baths:
X['T_agBath'] = X['FullBath'] + X['HalfBath']
if self.add_porch_area:
X['T_Porch'] = X['OpenPorchSF'] + X['EnclosedPorch'] + X['3SsnPorch'] + X['ScreenPorch']
return X
attr_adder = CombinedAttributesAdder(add_baths=False, add_bsmt_baths=False)
housing_extra_attribs = attr_adder.transform(housing)
这里它应该返回所有列,因为我设置了参数 add_baths=False, add_bsmt_baths=False
它不应该创建 T_Bath
也不是 T_BsmtBath
柱
housing_extra_attribs.columns
...
Index(['Id', 'MSSubClass', 'MSZoning', 'LotFrontage', 'LotArea', 'Street',
'Alley', 'LotShape', 'LandContour', 'Utilities', 'LotConfig',
'LandSlope', 'Neighborhood', 'Condition1', 'Condition2', 'BldgType',
'HouseStyle', 'OverallQual', 'OverallCond', 'YearBuilt', 'YearRemodAdd',
'RoofStyle', 'RoofMatl', 'Exterior1st', 'Exterior2nd', 'MasVnrType',
'MasVnrArea', 'ExterQual', 'ExterCond', 'Foundation', 'BsmtQual',
'BsmtCond', 'BsmtExposure', 'BsmtFinType1', 'BsmtFinSF1',
'BsmtFinType2', 'BsmtFinSF2', 'BsmtUnfSF', 'TotalBsmtSF', 'Heating',
'HeatingQC', 'CentralAir', 'Electrical', '1stFlrSF', '2ndFlrSF',
'LowQualFinSF', 'GrLivArea', 'BsmtFullBath', 'BsmtHalfBath', 'FullBath',
'HalfBath', 'BedroomAbvGr', 'KitchenAbvGr', 'KitchenQual',
'TotRmsAbvGrd', 'Functional', 'Fireplaces', 'FireplaceQu', 'GarageType',
'GarageYrBlt', 'GarageFinish', 'GarageCars', 'GarageArea', 'GarageQual',
'GarageCond', 'PavedDrive', 'WoodDeckSF', 'OpenPorchSF',
'EnclosedPorch', '3SsnPorch', 'ScreenPorch', 'PoolArea', 'PoolQC',
'MiscFeature', 'MiscVal', 'MoSold', 'YrSold', 'SaleType',
'SaleCondition', 'T_FlrSF', 'T_Bath', 'T_BsmtBath', 'T_agBath',
'T_Porch'],
dtype='object')
暂无答案!
目前还没有任何答案,快来回答吧!