Question: Here are the details I need to create a custom transformer, that performs two computations: 1. Adds an attribute to the end of the numerical

Here are the details I need to create a custom transformer, that performs two computations:

1. Adds an attribute to the end of the numerical data (i.e. new last column) that is equal to 315 for each observation. In other words, for each instance, you will cube the 1 column and then divide by the 5 column.

2. Drops the entire 4 feature column if the passed function argument drop_x4 is True and doesn't drop the column if drop_x4 is False.

The class should include an input parameter with a default value of True that deletes the 4 feature column when its value is True, but preserves the 4 feature column when you pass a value of False

This is the code I came up with but for some reason it isn't working and I can't figure out why. Can someone please help?

from sklearn.base import BaseEstimator, TransformerMixin class Assignment4Transformer(BaseEstimator, TransformerMixin): def __init__(self,drop_x4= True): self.drop_x4 = drop_x4 def fit(self, custom_transform, y=None): return self def transform(self, custom_transform): if self.drop_x4: custom_transform = custom_transform.drop('x4', axis = 1) return custom_transform else: x6 = (custom_transform['x1'].pow(3)) / custom_transform['x5'] custom_transform['x6'] = x6 return custom_transform

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!