I am new to Machine Learning and practicing the codes on the book named "Hands-On Machine Learning with Scikit-Learn and TensorFlow" by Aurélien Géron. There is code regarding Pipeline which throwing an error named "AttributeError: 'longitude' is not a valid function for 'Series' object".
Here is the code that I am trying to run-
class DataFrameSelector(BaseEstimator, TransformerMixin):
def __init__(self, attribute_names):
self.attribute_names = attribute_names
def fit(self, X, y=None):
return X
def transform(self, X):
return X[self.attribute_names].values
num_attributes = list(housing_num)
cat_attributes = ['ocean_proximity']
num_pipeline = Pipeline([ ('selector', DataFrameSelector(num_attributes)),
('imputer', SimpleImputer(strategy='median')),
('Attribute_adder', CombinedAttributesAdder()),
('std_scaler', StandardScaler()) ])
cat_pipeline = Pipeline([ ('selector', DataFrameSelector(cat_attributes)),
('label_binarizer', OneHotEncoder()) ])
full_pipeline = FeatureUnion( transformer_list=[ ('num_pipeline', num_pipeline), ('cat_pipeline', cat_pipeline) ] )
housing_prepared = cat_pipeline.fit_transform(housing)
housing_prepared
Here is the link of the data that I am using: https://raw.githubusercontent.com/ageron/handson-ml/master/datasets/housing/housing.csv
When I re-run the code without the DataFrameSelector, it works just fine. So, I looked for a possible solution and found that instead of using the FeatureUnion class ColumnTransformer class would resolve the issue which works without the need of the DataFrameSelector class. That's really great and less time consuming but didn't find any solution about what's wrong with the above code. Any help would be very much appreciated regarding this issue.