Last answered:

03 Dec 2022

Posted on:

26 Oct 2021

0

AttributeError: 'CustomScaler' object has no attribute 'copy'

AttributeError: 'CustomScaler' object has no attribute 'copy' is the error encountered while standardising using CustomScaler. Can you please help me with this error?
Custom Scaler ErrorCustom Scaler Code
Please find the screenshots for reference. Even in the resource section, I guess Custom Scaler code is not available. Could you please check and correct me if I am wrong. Thank you in advance.

Please find the complete code here

3 answers ( 0 marked as helpful)
Instructor
Posted on:

01 Nov 2021

0

Hi Sarath!

Thanks for reaching out.

This error stems from the code you've executed previously in your *.ipynb file. We are aware that this may mean that you have made one of potentially a number of errors, but it is not exactly so.
From the screenshot you've shared, it seems that you may have not created the unscaled_inputs in the way shown in the course. Therefore, can you please revise/restart the kernel and re-run all cells in the suggested order, to ensure that this variable contains the relevant content?

Hope this helps but please feel free to get back to us should you need further assistance. Thank you.
Best,
Martin

Posted on:

20 Nov 2022

0

In Shaa Allah it works through this code:

class CustomScaler(BaseEstimator, TransformerMixin):

    def __init__(self, columns, copy=True, with_mean=True, with_std=True):
        self.columns = columns
        self.copy = copy
        self.with_mean = with_mean
        self.with_std = with_std

    def fit(self, X, y=None):
        self.scaler = StandardScaler(copy=self.copy, with_mean=self.with_mean, with_std=self.with_std)
        self.scaler.fit(X[self.columns], y)
        self.mean_ = np.mean(X[self.columns])
        self.var_ = np.var(X[self.columns])
        return self

    def transform(self, X, y=None, copy=None):
        init_col_order = X.columns
        X_scaled = pd.DataFrame(self.scaler.transform(X[self.columns]), columns=self.columns)
        X_not_scaled = X.loc[:, ~X.columns.isin(self.columns)]
        return pd.concat([X_not_scaled, X_scaled], axis = 1)[init_col_order]
Instructor
Posted on:

03 Dec 2022

0

Hi Barkamol!

Thanks for reaching out and sharing your solution with the Community!
Please do not hesitate to post a question should you need any assistance. Thank you.

Kind regards,
Martin

Submit an answer