From 8d48d7f14660df457b3fbc1c75aee5894103eb74 Mon Sep 17 00:00:00 2001 From: jason_cv Date: Mon, 27 Apr 2020 17:39:54 -0500 Subject: [PATCH] Regresion Lasso --- RegresionLasso.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 RegresionLasso.py diff --git a/RegresionLasso.py b/RegresionLasso.py new file mode 100644 index 0000000..d383b7b --- /dev/null +++ b/RegresionLasso.py @@ -0,0 +1,30 @@ +from sklearn.linear_model import Lasso +from sklearn.preprocessing import PolynomialFeatures +import numpy as np +import matplotlib.pyplot as plt +############################### +#Datos originales +############################### +m = 100 +X = 6 * np.random.rand(m, 1) - 3 +y = 0.5 * X**2 + X + 2 + np.random.randn(m, 1) + +plt.plot(X,y,".",label = "Datos originales") +############################### +poly_features = PolynomialFeatures(degree=2, include_bias=False) +X_pol = poly_features.fit_transform(X) +lasso_reg = Lasso(alpha=0.1) +lasso_reg.fit(X_pol, y) +yout=lasso_reg.predict(X_pol) +plt.plot(X,yout,"*",label = "Predicciones") + + + +# naming the x axis +plt.xlabel('Eje X') +# naming the y axis +plt.ylabel('Eje Y') +# giving a title to my graph + +plt.legend() +plt.show()