Я написал этот код из книги по практическому машинному обучению с scikit-learn и tenorflow, но я получил следующую ошибку при запуске показанного кода. Может кто-нибудь, пожалуйста, помогите мне с этой ошибкой? Спасибо
Код:
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):
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]
class DataFrameSelector(BaseEstimator, TransformerMixin):
def __init__(self,attribute_names):
self.attribute_names = attribute_names
def fit(self,X,y=None):
return self
def transform(self,X):
return X[self.attribute_names].values
from sklearn.pipeline import FeatureUnion
num_attribs = list(housing_num)
cat_attribs = ["ocean_proximity"]
num_pipeline = Pipeline([
('selsector',DataFrameSelector(num_attribs)),
('imputer', SimpleImputer(strategy='median')),
('attribs_adder', CombinedAttributesAdder()),
('std_scaler', StandardScaler()),
])
cat_pipeline = Pipeline([
('selector', DataFrameSelector(cat_attribs)),
('label_encoder', LabelBinarizer()),
])
full_pipeline = FeatureUnion(transformer_list = [
('num_pipeline', num_pipeline),
('cat_pipeline', cat_pipeline),
])
cat_pipeline.fit_transform(housing)
Ошибка:
TypeError Traceback (последний последний вызов) в ----> 1 cat_pipeline.fit_transform (корпус)
~ / anaconda3 / lib / python3 .7 / site-packages / sklearn / pipeline.py в fit_transform (self, X, y, ** fit_params) 391 возвращает Xt 392, если hasattr (last_step, 'fit_transform') : -> 393 return last_step.fit_transform (Xt, y, ** fit_params) 394 else: 395 return last_step.fit (Xt, y, ** fit_params) .transform (Xt)
Ошибка типа: fit_transform ( ) принимает 2 позиционных аргумента, но 3 были даны