Browse Source

Regresión Elastica

master
parent
commit
b490268a98
1 changed files with 29 additions and 0 deletions
  1. +29
    -0
      RegresionElastic.py

+ 29
- 0
RegresionElastic.py View File

@ -0,0 +1,29 @@
from sklearn.linear_model import ElasticNet
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)
elastic_net = ElasticNet(alpha=0.1, l1_ratio=0.5)
elastic_net.fit(X_pol, y)
yout=elastic_net.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()

Loading…
Cancel
Save