Question: I need to create a custom transform using python. I have a data set and with the custom transform I need to add a column
I need to create a custom transform using python. I have a data set and with the custom transform I need to add a column to the end of the data which I was able to do. But I am confused about deleting the one column. I need the class to include a 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 its value is False. This is what I have so far but the column I am adding needs to cube the first column then divide the 5th column but when i run it its only dividing by the 5th not cubing it first.
from sklearn.base import BaseEstimator, TransformerMixin
x1_ix, x2_ix, x4_ix, x5_ix = 0,1,3,4
class Assignment4Transformer(BaseEstimator, TransformerMixin): def __init__(self, add_x6 = True): self.add_x6 = add_x6 def fit(self, data, y=None): return self def transform(self, data): x6 = data[:, (x1_ix**3)] / data[:, x5_ix] return np.c_[data, x6]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
