Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
513 B
63
Indexable
Never
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