|

楼主 |
发表于 2024-10-26 12:57:15
|
显示全部楼层
- #对非dummy特征进行batchnormalization
- import sklearn.preprocessing as preprocessing
- scaler = preprocessing.StandardScaler()
- id_column = full_dataset['Id'] #先排除id列
- non_dummy_features = full_dataset.drop(columns='Id').select_dtypes(include=['int64', 'float64']) # 识别非dummy特征
- full_dataset[non_dummy_features] = scaler.fit_transform(full_dataset[non_dummy_features])# 对非dummy特征进行标准化
- full_dataset['Id'] = id_column #把id列加回dataframe中
- full_dataset[['Id'] + non_dummy_features.columns.to_list()]
复制代码
报错如下
- ---------------------------------------------------------------------------
- ValueError Traceback (most recent call last)
- /tmp/ipykernel_30/3989952025.py in ?()
- 3 scaler = preprocessing.StandardScaler()
- 4
- 5 id_column = full_dataset['Id'] #先排除id列
- 6 non_dummy_features = full_dataset.drop(columns='Id').select_dtypes(include=['int64', 'float64']) # 识别非dummy特征
- ----> 7 full_dataset[non_dummy_features] = scaler.fit_transform(full_dataset[non_dummy_features])# 对非dummy特征进行标准化
- 8 full_dataset['Id'] = id_column #把id列加回dataframe中
- 9 full_dataset[['Id'] + non_dummy_features.columns.to_list()]
- /opt/conda/lib/python3.10/site-packages/pandas/core/frame.py in ?(self, key)
- 4085 return self._getitem_slice(key)
- 4086
- 4087 # Do we have a (boolean) DataFrame?
- 4088 if isinstance(key, DataFrame):
- -> 4089 return self.where(key)
- 4090
- 4091 # Do we have a (boolean) 1d indexer?
- 4092 if com.is_bool_indexer(key):
- /opt/conda/lib/python3.10/site-packages/pandas/core/generic.py in ?(self, cond, other, inplace, axis, level)
- 10980 stacklevel=2,
- 10981 )
- 10982
- 10983 other = common.apply_if_callable(other, self)
- > 10984 return self._where(cond, other, inplace, axis, level)
- /opt/conda/lib/python3.10/site-packages/pandas/core/generic.py in ?(self, cond, other, inplace, axis, level, warn)
- 10669 raise ValueError(msg.format(dtype=cond.dtype))
- 10670 else:
- 10671 for _dt in cond.dtypes:
- 10672 if not is_bool_dtype(_dt):
- > 10673 raise ValueError(msg.format(dtype=_dt))
- 10674 if cond._mgr.any_extension_types:
- 10675 # GH51574: avoid object ndarray conversion later on
- 10676 cond = cond._constructor(
- ValueError: Boolean array expected for the condition, not int64
复制代码 |
|