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.
 

30 lines
765 B

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()