def fit(self, X, y=None):
<EOL>X = check_array(X)<EOL>self.inverse_influence_matrix = self.__make_inverse_matrix(X)<EOL>if self.threshold == '<STR_LIT>':<EOL><INDENT>self.threshold_value = <NUM_LIT:3> * (<NUM_LIT:1> + X.shape[<NUM_LIT:1>]) / X.shape[<NUM_LIT:0>]<EOL><DEDENT>elif self.threshold == '<STR_LIT>':<EOL><INDENT>if y is None:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>y = check_array(y, accept_sparse='<STR_LIT>', ensure_2d=False, dtype=None)<EOL>self.threshold_value = <NUM_LIT:0><EOL>score = <NUM_LIT:0><EOL>Y_pred, Y_true, AD = [], [], []<EOL>cv = KFold(n_splits=<NUM_LIT:5>, random_state=<NUM_LIT:1>, shuffle=True)<EOL>for train_index, test_index in cv.split(X):<EOL><INDENT>x_train = safe_indexing(X, train_index)<EOL>x_test = safe_indexing(X, test_index)<EOL>y_train = safe_indexing(y, train_index)<EOL>y_test = safe_indexing(y, test_index)<EOL>if self.reg_model is None:<EOL><INDENT>reg_model = RandomForestRegressor(n_estimators=<NUM_LIT>, random_state=<NUM_LIT:1>).fit(x_train, y_train)<EOL><DEDENT>else:<EOL><INDENT>reg_model = clone(self.reg_model).fit(x_train, y_train)<EOL><DEDENT>Y_pred.append(reg_model.predict(x_test))<EOL>Y_true.append(y_test)<EOL>ad_model = self.__make_inverse_matrix(x_train)<EOL>AD.append(self.__find_leverages(x_test, ad_model))<EOL><DEDENT>AD_ = unique(hstack(AD))<EOL>for z in AD_:<EOL><INDENT>AD_new = hstack(AD) <= z<EOL>if self.score == '<STR_LIT>':<EOL><INDENT>val = balanced_accuracy_score_with_ad(Y_true=hstack(Y_true), Y_pred=hstack(Y_pred), AD=AD_new)<EOL><DEDENT>elif self.score == '<STR_LIT>':<EOL><INDENT>val = rmse_score_with_ad(Y_true=hstack(Y_true), Y_pred=hstack(Y_pred), AD=AD_new)<EOL><DEDENT>if val >= score:<EOL><INDENT>score = val<EOL>self.threshold_value = z<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>self.threshold_value = self.threshold<EOL><DEDENT>return self<EOL>
Learning is to find the inverse matrix for X and calculate the threshold.

        Parameters
        ----------
        X : array-like or sparse matrix, shape (n_samples, n_features)
            The input samples. Use ``dtype=np.float32`` for maximum
            efficiency.
        y : array-like, shape = [n_samples] or [n_samples, n_outputs]
            The target values (real numbers in regression).

        Returns
        -------
        self : object