def feature_scaling(x_train_input, x_test_input): print("\n*****FUNCTION feature_scaling*****") global SCALER x_train = x_train_input.copy(deep=True) x_test = x_test_input.copy(deep=True) SCALER = SklearnTransformerWrapper(transformer=MinMaxScaler(), variables=['Tenure', 'MonthlyCharges']) # fit,transform x_train SCALER.fit(x_train) x_train = SCALER.transform(x_train) # transform x_test x_test = SCALER.transform(x_test) return (x_train, x_test)
def test_error_when_inverse_transform_not_implemented(transformer): X = fetch_california_housing(as_frame=True).frame y = X["MedHouseVal"] X = X.drop(["MedHouseVal"], axis=1) tr_wrap = SklearnTransformerWrapper(transformer=transformer) tr_wrap.fit(X, y) X_tr = tr_wrap.transform(X) with pytest.raises(NotImplementedError): tr_wrap.inverse_transform(X_tr)
def test_selectKBest_all_variables(): X, y = load_boston(return_X_y=True) X = pd.DataFrame(X) selector = SklearnTransformerWrapper(transformer=SelectKBest(f_regression, k=5), ) selector.fit(X, y) X_train_t = selector.transform(X) pd.testing.assert_frame_equal(X_train_t, X[[2, 5, 9, 10, 12]])
def test_selectFromModel_all_variables(): X, y = load_boston(return_X_y=True) X = pd.DataFrame(X) lasso = Lasso(alpha=10, random_state=0) sfm = SelectFromModel(lasso, prefit=False) selector = SklearnTransformerWrapper(transformer=sfm) selector.fit(X, y) X_train_t = selector.transform(X) pd.testing.assert_frame_equal(X_train_t, X[[1, 9, 11, 12]])