Browse Source

Modelo lineal regularizado Ridge

master
parent
commit
5d896bf714
1 changed files with 21 additions and 0 deletions
  1. +21
    -0
      RegresionRidge.py

+ 21
- 0
RegresionRidge.py View File

@ -0,0 +1,21 @@
from sklearn.linear_model import Ridge
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,".")
###############################
poly_features = PolynomialFeatures(degree=2, include_bias=False)
X_pol = poly_features.fit_transform(X)
ridge_reg = Ridge(alpha=1, solver="cholesky")
ridge_reg.fit(X_pol, y)
yout=ridge_reg.predict(X_pol)
print(ridge_reg.predict(1.5,2))
plt.plot(X,yout,"*")
plt.show()

Loading…
Cancel
Save