Ejemplos de Machine Learning para el uso y aplicación de regresiones
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
615 B

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. ###############################
  4. #Datos originales
  5. ###############################
  6. X = 2 * np.random.rand(100, 1)
  7. y = 4 + 3 * X + np.random.randn(100,1)
  8. plt.plot(X,y,".")
  9. ###############################
  10. X_b = np.c_[np.ones((100,1)), X] #Se agrega x0=1 para cada instancia
  11. theta_best=np.linalg.inv(X_b.T.dot(X_b)).dot(X_b.T).dot(y)
  12. X_new = np.array([[0], [2]])
  13. X_new_b = np.c_[np.ones((2, 1)), X_new] #Se agrega x0=1 para cada instancia
  14. y_predict = X_new_b.dot(theta_best)
  15. plt.plot(X_new, y_predict, "r-")
  16. plt.plot(X, y, "b.")
  17. plt.axis([0, 2, 0, 15])
  18. plt.show()