<jupyter_start><jupyter_text>box plot<jupyter_code>class BoxnWhisker(BaseViz):
    def __init__(self, features, values, result):
        self.features, self.values = features, values
        self.result = result
        
    @classmethod
    def from_df(cls, df, features = None):
        values = df.values.T if features is None else df[to_iter(features)].values.T
        features = features or df.columns        
        return cls.from_series(features, values)
    
    @classmethod
    def from_series(cls, features, values):
        result = pd.DataFrame(columns=['Feature', 'Min', 'Q1', 'Median', 'Q3', 'Max'])
        for f, v in zip(features, values): 
            Min, Q1, Median, Q3, Max = cls.calculate(v)
            result = df_append(result, f, Min, Q1, Median, Q3, Max)
        return cls(to_iter(features), to_iter(values), result)        
    
    @staticmethod
    def calculate(values):
        Median = np.median(values)
        Q1, Q3 = np.percentile(values, [25,75])
        IQR = Q3 - Q1
        Min, Max = Q1 - IQR*1.5, Q3 + IQR*1.5
        return Min, Q1, Median, Q3, Max

    def plot(self, orient = 'h', **kwarg): 
        for f, v in zip(self.features, self.values): plot_boxnwhisker(f, v, orient = orient, **kwarg)
def plot_boxnwhisker(feature, value, orient = 'h', **kwarg):
    plt.figure()
    sns.boxplot(data = value, orient = orient, **kwarg).set(ylabel=feature)
bw = BoxnWhisker.from_df(app_train, ['CNT_CHILDREN', 'AMT_INCOME_TOTAL'])
bw.plot()
bw.result<jupyter_output><empty_output><jupyter_text>remove outlier<jupyter_code>def boxnwhisker_value(values):
    Median = np.median(values)
    Q1, Q3 = np.percentile(values, [25,75])
    IQR = Q3 - Q1
    Min, Max = Q1 - IQR*1.5, Q3 + IQR*1.5
    return Min, Q1, Median, Q3, Max, IQR
class TBPreProc:
    def __init__(self, *args): self.args = args
        
    def __call__(self, df, pp_outp): return self.func(df, pp_outp, *self.args)
    
    @staticmethod
    def func(*args): None
#need to do
class remove_outlier(TBPreProc):
    @staticmethod
    def func(df, pp_outp):
        return filter_outlier(df, pp_outp['cons'])[0]
def filter_outlier(df, cons):
    filt =  np.full(df.shape[0], True)
    for f, v in df[cons].items():
        Min, _, _, _, Max, _ = boxnwhisker_value(v)
        inlier = np.logical_and(v.values >= Min, v.values <= Max)
        pdb.set_trace()
        filt = np.logical_and(filt, inlier)
    return df[filt], filt
app_train.shape
app_train_proc.shape<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13690952762209768, 'fraction_numerical': 0.016012810248198558, 'mean_word_length': 3.0306451612903227, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '321359', 'license': 'MIT', 'n_tokens_mistral': 948, 'n_tokens_neox': 919, 'n_words': 212, 'path': 'nbs/old nbs/boxplot.ipynb', 'repo_name': 'KienVu2368/taproc', 'size': '2498'}