gpt4 book ai didi

python - “元组”对象不可调用

转载 作者:行者123 更新时间:2023-12-01 21:51:59 30 4
gpt4 key购买 nike

<分区>

我为自定义转换定义了以下类,并使用 Scikit-Learn 实现了必要的功能方法:

from sklearn.base import BaseEstimator, TransformerMixin
rooms_ix, bedrooms_ix, population_ix, household_ix = 3, 4, 5, 6

class CombinedAttributesAdder(BaseEstimator, TransformerMixin):
def __init__(self, add_bedrooms_per_room = True): # no *args or **kargs
self.add_bedrooms_per_room = add_bedrooms_per_room
def fit(self, X, y=None):
return self # nothing else to do
def transform(self, X, y=None):
rooms_per_household = X[:, rooms_ix] / X[:, household_ix]
population_per_household = X[:, population_ix] / X[:, household_ix]
if self.add_bedrooms_per_room:
bedrooms_per_room = X[:, bedrooms_ix] / X[:, rooms_ix]
return np.c_[X, rooms_per_household, population_per_household,bedrooms_per_room]
else:
return np.c_[X, rooms_per_household, population_per_household]

attr_adder = CombinedAttributesAdder(add_bedrooms_per_room=False)
housing_extra_attribs = attr_adder.transform(housing.values)

然后我像这样在管道中调用类和其他类:

from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler

num_pipeline = Pipeline([
('imputer', SimpleImputer(strategy="median"))
('attribs_adder', CombinedAttributesAdder()),
('std_scaler', StandardScaler()),
])

housing_num_tr = num_pipeline.fit_transform(housing_num)

这会产生上述错误消息:

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-52-bcea5f2689c0> in <module>
4 num_pipeline = Pipeline([
5 ('imputer', SimpleImputer(strategy="median"))
----> 6 ('attribs_adder', CombinedAttributesAdder()),
7 ('std_scaler', StandardScaler()),
8 ])

TypeError: 'tuple' object is not callable

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com