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.

28 lines
795 B

  1. from sklearn.linear_model import ElasticNet
  2. from sklearn.preprocessing import PolynomialFeatures
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5. ###############################
  6. #Datos originales
  7. ###############################
  8. m = 100
  9. X = 6 * np.random.rand(m, 1) - 3
  10. y = 0.5 * X**2 + X + 2 + np.random.randn(m, 1)
  11. plt.plot(X,y,".", label = "Datos originales")
  12. ###############################
  13. poly_features = PolynomialFeatures(degree=2, include_bias=False)
  14. X_pol = poly_features.fit_transform(X)
  15. elastic_net = ElasticNet(alpha=0.1, l1_ratio=0.5)
  16. elastic_net.fit(X_pol, y)
  17. yout=elastic_net.predict(X_pol)
  18. plt.plot(X,yout,"*", label = "Predicciones")
  19. # naming the x axis
  20. plt.xlabel('Eje X')
  21. # naming the y axis
  22. plt.ylabel('Eje Y')
  23. # giving a title to my graph
  24. plt.legend()
  25. plt.show()