ageron / ageron/handson-ml2

[QUESTION] Chapter 4, how do I roll back model parameters? (Early Stopping)

Abierto
#573 3 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Jupyter Notebook
Estrellas
30k
Forks
13.1k
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Hi,

Please be patient, I am very new to machine learning. The Early Stopping section introduces an implementation. I ran the code and everything went smooth. My question is how I use the epoch and model that I just found. Here's the code:

```python

from copy import deepcopy

#Creating the data
np.random.seed(42)
m = 100
X = 6 * np.random.rand(m, 1) - 3
y = 2 + X + 0.5 * X**2 + np.random.randn(m, 1)

X_train, X_val, y_train, y_val = train_test_split(X[:50], y[:50].ravel(), test_size=0.5, random_state=10)

# Preparing the data
poly_scaler = Pipeline([
("poly_features", PolynomialFeatures(degree=90, include_bias=False)),
("std_scaler", StandardScaler())
])
X_train_poly_scaled = poly_scaler.fit_transform(X_train)
X_val_poly_scaled = poly_scaler.transform(X_val)

sgd_reg = SGDRegressor(max_iter=1, tol=-np.infty, warm_start=True, penalty=None, learning_rate="constant", eta0=0.0005)

minimum_val_error = float("inf")
best_epoch = None
best_model = None
for epoch in range(1000):
sgd_reg.fit(X_train_poly_scaled, y_train) #this continues where it left off
y_val_predict = sgd_reg.predict(X_val_poly_scaled)
val_error = mean_squared_error(y_val, y_val_predict)
if val_error < minimum_val_error:
minimum_val_error = val_error
best_epoch = epoch
best_model = deepcopy(sgd_reg)

```

**Versions**
- OS: Windows 10.0.19044 Build 19044
- Python: 3.9.7
- Scikit-Learn: 0.24.2

The best epoch is around 230 ish. I just don't understand how I can use best_model to make predictions on X. Thank you so much in advance.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.