ageron / ageron/handson-mlp

[bug] Chapter 2 Exercise 6

Abierto
#35 0 comentarios 0 reacciones 1 asignado Reclamado por @ageron Ver en GitHub
bug help wanted
Lenguaje dominante
Jupyter Notebook
Estrellas
2k
Forks
624
Merge medio
7 h 55 min
PR fusionados (30 d)
1

Descripción

### Enter the chapter number

Chapter 2 Exercise 6

### Enter the page number

_No response_

### What is the cell's number in the notebook

164

### Enter the environment you are using to run the notebook

None

### Describe your issue

class StandardScalerClone(TransformerMixin, BaseEstimator):
def __init__(self, with_mean=True): # no *args or **kwargs!
self.with_mean = with_mean

**def fit(self, X, y=None):
X = validate_data(self, X, ensure_2d=True)
self.n_features_in_ = X.shape[1]
if self.with_mean:
self.mean_ = np.mean(X, axis=0)
self.scale_ = np.std(X, axis=0, ddof=0)
self.scale_[self.scale_ == 0] = 1 # Avoid division by zero
return self**

def transform(self, X):
check_is_fitted(self)
X = validate_data(self, X, ensure_2d=True, reset=False)
if self.with_mean:
X = X - self.mean_
return X / self.scale_

def inverse_transform(self, X):
check_is_fitted(self)
X = validate_data(self, X, ensure_2d=True, reset=False)
return X * self.scale_ + self.mean_

def get_feature_names_out(self, input_features=None):
if input_features is None:
return getattr(self, "feature_names_in_",
[f"x{i}" for i in range(self.n_features_in_)])
else:
if len(input_features) != self.n_features_in_:
raise ValueError("Invalid number of features")
if hasattr(self, "feature_names_in_") and not np.all(
self.feature_names_in_ == input_features
):
raise ValueError("input_features ≠ feature_names_in_")
return input_features

I think we need to assign feature_names_in in the fit function as per the exercise?

### Enter what you expected to happen

_No response_

### If you found a workaround, describe it here

_No response_

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.