TransWikia.com

Syntax error but nothing appears to be wrong?

Data Science Asked by payne on June 28, 2021

I’m trying to create a decision tree, and everything appeared to be going smoothly until I encountered this syntax error. I don’t see what the issue is?

print ("start fitting the data")
import warnings
warnings.filterwarnings("ignore")

for cv in tqdm(range(3, 6)):
    create_grid = GridSearchCV(pipeline, param_grid=check_params, cv=cv)
    create_grid.fit(X_train.fillna(X_train.mean(), y_train.fillna(y_train.mean()))
    print("score for %d fold CV := %3.2f" %(cv, create_grid.score(X_test, y_test)))
    print ("!!!! best fit parameters from GridSearchCV !!!!")
    print (create_grid.best_params_)

print ("loop has exited")

jupyter throws the error:

  File "<ipython-input-38-6b9dca710e77>", line 8
    print("score for %d fold CV := %3.2f" %(cv, create_grid.score(X_test, y_test)))
        ^
SyntaxError: invalid syntax

One Answer

In the second line of the for loop

create_grid.fit(X_train.fillna(X_train.mean(), y_train.fillna(y_train.mean()))

You need an extra closing parenthesis like so

create_grid.fit(X_train.fillna(X_train.mean(), y_train.fillna(y_train.mean())))

Answered by A Kareem on June 28, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP