Untitled

 avatar
unknown
plain_text
2 years ago
513 B
66
Indexable
class LinearRegression:
    def fit(self, train_features, train_target, **kwargs):
        X = np.concatenate((np.ones((train_features.shape[0], 1)), train_features), axis=1)
        y = train_target
        w = ((np.linalg.inv(X.T @ X) @ X.T) @ y)
        if 'key' in kwargs:
            key = kwargs['key']
            self.w = inv(key) @ w[1:]
        else:
            self.w = w[1:]
        self.w0 = w[0]

    def predict(self, test_features):
        return test_features.dot(self.w) + self.w0
Editor is loading...