<commit_before>from ESLmodels.base import BaseStatModel
from ESLmodels.base import np
from ESLmodels.utils import lazy_method
from itertools import combinations



class LinearModel(BaseStatModel):
    def __init__(self, train_x, train_y, features_name=None):
        super().__init__(train_x, train_y, features_name)
        self.beta_hat = None
        self.intercept = None

    def pre_processing_x(self, x):
        x = self.standardize(x)
        return x

    def pre_processing_y(self, y):
        return y.reshape(y.size,1)

    def predict(self, x):
        x = self.pre_processing_x(x)
        x = np.insert(x, 0, 1, axis=0)
        return  x @ self.beta_hat

    @property
    @lazy_method
    def sigma_hat(self):
        """
        (3.8)
        """
        # because we already add intercept to train x, so col_num is (p+1)

        N, col_num = self.train_x.shape

        return self.math.sum((self.y_hat - self.train_y)**2) / (N-col_num)


    @property
    @lazy_method
    def std_err(self):
        var_beta_hat = self.math.inv(self.train_x.T @ self.train_x) * self.sigma_hat
        return var_beta_hat.diagonal() ** 0.5
<commit_msg>fix wrong<commit_after>from ESLmodels.base import BaseStatModel
from ESLmodels.base import np
from ESLmodels.utils import lazy_method
from itertools import combinations



class LinearModel(BaseStatModel):
    def __init__(self, train_x, train_y, features_name=None):
        super().__init__(train_x, train_y, features_name)
        self.beta_hat = None
        self.intercept = None

    def pre_processing_x(self, x):
        x = self.standardize(x)
        return x

    def pre_processing_y(self, y):
        return y.reshape(y.size,1)

    def predict(self, x):
        x = self.pre_processing_x(x)
        x = np.insert(x, 0, 1, axis=1)
        return  x @ self.beta_hat

    @property
    @lazy_method
    def sigma_hat(self):
        """
        (3.8)
        """
        # because we already add intercept to train x, so col_num is (p+1)

        N, col_num = self.train_x.shape

        return self.math.sum((self.y_hat - self.train_y)**2) / (N-col_num)


    @property
    @lazy_method
    def std_err(self):
        var_beta_hat = self.math.inv(self.train_x.T @ self.train_x) * self.sigma_hat
        return var_beta_hat.diagonal() ** 0.5

{'fraction_non_alphanumeric': 0.10571923743500866, 'fraction_numerical': 0.008665511265164644, 'mean_word_length': 2.5523076923076924, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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}}
{'dir': 'git-commits-cleaned', 'id': '475193', 'n_tokens_mistral': 816, 'n_tokens_neox': 783, 'n_words': 181}