Browse Source

Descenso por gradiente en lotes

master
parent
commit
7ffc0d53d1
1 changed files with 21 additions and 0 deletions
  1. +21
    -0
      Batchgradientdecent.py

+ 21
- 0
Batchgradientdecent.py View File

@ -0,0 +1,21 @@
import numpy as np
import matplotlib.pyplot as plt
###############################
#Datos originales
###############################
X = 2 * np.random.rand(100, 1)
y = 4 + 3 * X + np.random.randn(100,1)
plt.plot(X,y,".")
###############################
X_b = np.c_[np.ones((100,1)), X] #Se agrega x0=1 para cada instancia
eta = 0.1 #Pasos
n_itera = 1000
m=100
theta = np.random.randn(2,1) #Inicialización aleatoria
for iteracion in range (n_itera):
gradiente = 2/m * X_b.T.dot(X_b.dot(theta)-y)
theta = theta - eta * gradiente
print(theta)

Loading…
Cancel
Save