【七天入门ML与DL-02】fit_transform和fit、transform

本文详细介绍了如何在Python的sklearn库中使用StandardScaler类的fit_transform方法,它与先fit后transform的步骤等价,并强调了在后续转换中避免重复fit的重要性。通过实例演示,展示了如何高效地对数据进行标准化操作。

fit_transform()的作用是 对输入的数据做变换
等价于
fit+transform

from sklearn.preprocessing import  StandardScaler
s=StandardScaler()
data=[[1,2,3],[4,5,
以下报错是什么原因:TypeError: only length-1 arrays can be converted to Python scalars The above exception was the direct cause of the following exception: Traceback (most recent call last): File "C:\PyCharm\Py_Projects\SJWL.py", line 91, in <module> data = scaler.fit_transform(data)#必须先fit_transform训练集,测试集用相同的参数transform File "C:\Users\Gallcions\anaconda3\envs\DL\lib\site-packages\sklearn\utils\_set_output.py", line 319, in wrapped data_to_wrap = f(self, X, *args, **kwargs) File "C:\Users\Gallcions\anaconda3\envs\DL\lib\site-packages\sklearn\base.py", line 918, in fit_transform return self.fit(X, **fit_params).transform(X) File "C:\Users\Gallcions\anaconda3\envs\DL\lib\site-packages\sklearn\preprocessing\_data.py", line 894, in fit return self.partial_fit(X, y, sample_weight) File "C:\Users\Gallcions\anaconda3\envs\DL\lib\site-packages\sklearn\base.py", line 1389, in wrapper return fit_method(estimator, *args, **kwargs) File "C:\Users\Gallcions\anaconda3\envs\DL\lib\site-packages\sklearn\preprocessing\_data.py", line 930, in partial_fit X = validate_data( File "C:\Users\Gallcions\anaconda3\envs\DL\lib\site-packages\sklearn\utils\validation.py", line 2944, in validate_data out = check_array(X, input_name="X", **check_params) File "C:\Users\Gallcions\anaconda3\envs\DL\lib\site-packages\sklearn\utils\validation.py", line 1055, in check_array array = _asarray_with_order(array, order=order, dtype=dtype, xp=xp) File "C:\Users\Gallcions\anaconda3\envs\DL\lib\site-packages\sklearn\utils\_array_api.py", line 839, in _asarray_with_order array = numpy.asarray(array, order=order, dtype=dtype) File "C:\Users\Gallcions\anaconda3\envs\DL\lib\site-packages\pandas\core\generic.py", line 1899, in __array__ return np.asarray(self._values, dtype=dtype) ValueError: setting an array element with a sequence.
03-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值