M3 Wrap-up quiz

My coding line does not work for question 3 :I have issue using the list of preprocessors into GridSearchCV
with:

model = Pipeline(steps=[ ("preprocessor",preprocessor ),   
    ("classifier", KNeighborsClassifier(n_neighbors=5)),])

param_grid = {
    'preprocessor': (all_preprocessors),
    'classifier__n_neighbors': (5, 51, 101)}

I get an error:

File "<ipython-input-59-c925c30e7818>", line 19
    param_grid = {
               ^
SyntaxError: invalid syntax

Could you provide more hints by giving the definition of all_preprocessors and preprocessor as well.

Change my code to rotate through models but still an error

#test different pre processors model

model = Pipeline(steps=[ ("preprocessor",preprocessor ),   
    ("classifier", KNeighborsClassifier(n_neighbors=5)),
])

from sklearn.preprocessing import MinMaxScaler
from sklearn.preprocessing import QuantileTransformer
from sklearn.preprocessing import PowerTransformer
from sklearn.model_selection import GridSearchCV
from sklearn.model_selection import train_test_split

data_train, data_test, target_train, target_test = train_test_split(
    data, target, random_state=42)   
all_preprocessors = [
    None,
    StandardScaler(),
    MinMaxScaler(),
    QuantileTransformer(n_quantiles=100),
    PowerTransformer(method="box-cox"),
for i in range(len(all_processors))
    param_grid = {
    'preprocessor': All_processors[i],
    'classifier__n_neighbors': (5, 51, 101)}
    model_grid_search = GridSearchCV(model, param_grid=param_grid,
                                 n_jobs=4, cv=2)
    model_grid_search.fit(data_train, target_train)
    accuracy = model_grid_search.score(data_test, target_test)
    cv_results["test_score"]

and the message is :

File "<ipython-input-4-80c3b4b2092e>", line 23
    for i in range(len(all_processors))
    ^
SyntaxError: invalid syntax

you are missing a colon at the end of the for statement.

Note: Be aware that you can add three backticks before and after code snippet such that the rendering look nicer and easier to read

```python
# My python code
```

you are missing a ] at the end.
You don’t need to have the for loop indeed.

Yes. Thanks a lot for the quality of your support. Managed to solve it but finally forgot to integrate the scoring=“balanced_accuracy”… :weary:

Learning is a process that takes time :slight_smile: Happy that you resolve your issue.