Getting error in Assignment1

Hi! I can’t figure out why I am getting the error:
Q8: FAIL
The ridge linear regression model was not trained properly
AssertionError : After fitting, ‘model.coef_’ must be a list of 304 weights

The code I have written is:
train_inputs, val_inputs, train_targets, val_targets = train_test_split(inputs_df[numeric_cols + encoded_cols], targets, test_size=0.25, random_state=42)
model = Ridge()
model.fit(train_inputs, train_targets)

X_train = train_inputs[numeric_cols + encoded_cols]
X_val = val_inputs[numeric_cols + encoded_cols]

train_preds = model.predict(X_train)
train_rmse = mean_squared_error(train_targets, train_preds)
val_preds = model.predict(X_val)
val_rmse = mean_squared_error(val_targets, val_preds)

weights = model.coef_

Your model.coef_ has 303 features, whereas it should contain 304, did you drop any feature by mistake?

No! I didn’t. I have 43 categorical columns and 36 numeric columns. And after encoding, categorical columns sum up o 267. So before train-test split shape of my df is (1460, 346) and after the split:
train_inputs.shape, val_inputs.shape, train_targets.shape, val_targets.shape
=> ((1095, 303), (365, 303), (1095,), (365,))

It’s working now. I found my mistake.

1 Like

@birajde i am also getting a error in which all questions are PASS but it is showing FAIL grade

Screenshot (155)