I am trying to make a simple model that returns the conditional expectation of a target with respect to the value observed for another variable.Basically, given a feature \$F\$, a level of this feature \$f\$, and a target \$y\$, the predicted value is:$$p=\mathbb{E}[y|F=f]$$As much as possible, I tried to follow sk-learns signatures and methods. How could I improve the readability of the code?import numpy as npimport pandas as pdclass ConditionalExpectation:    def __init__(self, feature_name, rare_threshold=10, verbose=False):        self._feature_name = feature_name        self._rare_name = __RARE__        self._target_name = __TARGET__        self._rare_threshold = rare_threshold        self._verbose = verbose    def fit(self, train, target):        feat = self._feature_name        self.train = train.copy()        self.train[self._target_name] = target        self._average = target.mean()        self._rare_values = self.train[feat].value_counts()[self.train[feat]].values < self._rare_threshold        self.train.loc[self._rare_values, feat] = self._rare_name        self.train.loc[self.train[feat].value_counts()[self.train[feat]].values < self._rare_threshold, feat] = self._rare_name        self._means = self.train.groupby([feat])[self._target_name].mean()        self._means[self._rare_name] = self._average        if(self._verbose):            print(Observed :  + str(len(self._means)) +  categories for variable :  + self._feature_name + .)        del self.train[self._target_name]        return self    def predict(self, test):        feat = self._feature_name        test = test.copy()        test.loc[self._rare_values, feat] = self._rare_name        criterion = ~test[feat].isin(set(self.train[feat]))        test.loc[criterion, feat] = self._average        return test[feat].replace(self._means, inplace=False)    def predict_proba(self, test):        return predict(self, test)    def get_params(self, deep=True):        return {feature_name: self._feature_name, rare_threshold: self._rare_threshold}
sk-learn like model
python;object oriented;machine learning