Intermediate model that filters y in Scikit-learn pipelines

I want to implement a predicting architecture which features an intermediate classifier. This model will be fitted and then predict probabilities for the classes of a binary feature on another sector of the training set. Then the transformer will remove every instance whose probability is smaller than a given value. Obviously, the y values corresponding to those instances should also be removed. This is not supported by the default sklearn behaviour, which does not allow for y to be transformed within a pipeline to be optimized through, e.g., GridSearchCV.

My custom model-transformer is the following (I’m using sklearn==1.4.0, this is very important):

class My_Int_Classifier(BaseEstimator, TransformerMixin):
    def __init__(self, pctg_int_model=0.5, int_target=None, thres_prob=0.5, y_final_target=None, **kwargs):
        self.model=RandomForestClassifier(n_estimators=100, criterion='gini', max_depth=None,
                                          min_weight_fraction_leaf=0.0, max_features='sqrt',
                                          max_leaf_nodes=None, min_impurity_decrease=0.0,
                                          bootstrap=True, oob_score=False, n_jobs=None,
                                          random_state=None, verbose=0, warm_start=False,
                                          class_weight=None, ccp_alpha=0.0, max_samples=None,
                                          monotonic_cst=None, min_samples_split=2, min_samples_leaf=1)
        self.__dict__.update(kwargs)
        self.pctg_int_model =pctg_int_model
        self.int_target = int_target
        self.thres_prob =thres_prob
        self.y_final_target=y_final_target
        self.model=self.model.set_params(**kwargs)

    def fit(self, x, y=None):
        int_X=X.iloc[0:math.floor(self.pctg_int_model*len(X))]
        self.model.fit(int_X.drop(self.int_target, axis=1), int_X[self.int_target])
        return self
        
    def transform(self, x, y=None):
        remaining_X=X.iloc[math.floor(self.pctg_int_model*len(x)):]
        remaining_X=remaining X.drop(self.int_target, axis=1)
        remaining_y = self.y_final_target.iloc[math.floor(self.pctg_int_model*len(self.y_final_target)):]
        probs = self.model.predict proba (remaining X)[:0]
        remaining_X['proba_int'] = probs
        remaining_X = remaining_X.reset_index(drop=True)
        remaining_y=remaining_y.reset_index(drop=True)
        remaining_y= pd.Series(remaining_y, name='remaining_y')
        df = pd.concat([remaining X, remaining_y])
        df =df[df['proba_int']<=self.thres_prob]
        remaining_X=df.drop('remaining y', axis-1)
        remaining_y=df['remaining_y']
        return (remaining_X, remaining_y)

and corresponding fit_transform. This works fine in isolation, the problem is that I need to pass remaining_y as the new y in the following (last) estimator in a pipeline of the form

int_model = My_Int_Classifier(int_target='int_binary_target', y_final_target=y_train)

pipeline_rfr = Pipeline([('scaler', StandardScaler()), ('int_model', model_rfr), ('final_model', RandomForestRegressor())])

which doesn’t work.

I would like a solution such as below, of the form provided here:

class MyWrapperEstimator(RealEstimator):
    def fit(X, y=None):
        if isinstance(X, tuple):
            X, y = X
        super().fit(X=X, y=y)

so that I could wrap the last RandomForestRegressor in this class, but this did not work as well.

Any insight is greatly appreciated.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật