Issue
While working on California Housing Dataset through Aurelian Gideon's book of O'Reilly publication, in the Custom Transformers section, I ran the code below :-
from sklearn.base import BaseEstimator, TransformerMixin
rooms_ix, bedrooms_ix, population_ix, households_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[:, households_ix]
population_per_household = X[:, population_ix] / X[:, households_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)
The error I get is as follows:-
File "<ipython-input-43-43e04d49480a>", line 16
return np.c_[X, rooms_per_household, population_per_household]
^
IndentationError: expected an indented block
Please suggest how to fix it?
Solution
housing.values is a function
You should use its "data" to perform transform task.
such as
housing["data"]
Answered By - jack sv
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.