对于住房数据集,我尝试使用 sklearn_pandas 中的 DataFrameMapper() 在选定的列上应用多项式特征。
我的代码:
from sklearn.preprocessing import PolynomialFeatures
from sklearn_pandas import DataFrameMapper
mapper = DataFrameMapper([
('houseAge_income', PolynomialFeatures(2)),
('median_income', PolynomialFeatures(2)),
(['latitude', 'housing_median_age', 'total_rooms', 'population', 'median_house_value',
'ocean_proximity']], None)
])
poly_feature = mapper.fit_transform(housing)
当我尝试使用
houseAge_income.reshape(-1, 1)
在 DataFrameMapper() 中,我遇到了另一个问题:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2645 try:
-> 2646 return self._engine.get_loc(key)
2647 except KeyError:
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'houseAge_income.reshape(-1, 1)'
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
5 frames
/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2646 return self._engine.get_loc(key)
2647 except KeyError:
-> 2648 return self._engine.get_loc(self._maybe_cast_indexer(key))
2649 indexer = self.get_indexer([key], method=method, tolerance=tolerance)
2650 if indexer.ndim > 1 or indexer.size > 1:
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
谁能告诉我,我错过了什么?
白板的微信
相关分类