Skip to content

Instantly share code, notes, and snippets.

@gileno
Created July 9, 2014 02:24
Show Gist options
  • Save gileno/1b58b43e7b1d13eabfaa to your computer and use it in GitHub Desktop.
Save gileno/1b58b43e7b1d13eabfaa to your computer and use it in GitHub Desktop.
Simples regressão linear múltipla
# -*- coding: utf-8 -*-
import numpy as np
def mmq(x, y):
u"""
x é uma matriz com as variáveis independentes
y é um array com a variável dependente
O retorno é um array contendo os valores dos beta's
"""
x = np.insert(x, 0, 1, axis=1)
x_t = np.transpose(x)
xt_x = np.dot(x_t, x)
inverse_xt_x = np.linalg.inv(xt_x)
xt_y = np.dot(x_t, y)
return np.dot(inverse_xt_x, xt_y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment