Invalid syntax error. Why?

def predict_price_multivariate(new_listing_value,feature_columns):
    temp_df = norm_train_df
    temp_df['distance'] = distance.cdist(temp_df[feature_columns],[new_listing_value[feature_columns]])
    temp_df = temp_df.sort_values('distance')
    knn_5 = temp_df.price.iloc[:5]
    predicted_price = knn_5.mean()
    return(predicted_price)cols = ['accommodates', 'bathrooms']

norm_test_df['predicted_price'] = norm_test_df[cols].apply(predict_price_multivariate,feature_columns=cols,axis=1)
norm_test_df['squared_error'] = (norm_test_df['predicted_price'] - norm_test_df['price'])**(2)
mse = norm_test_df['squared_error'].mean()
rmse = mse ** (1/2)
print(rmse)


  File "<ipython-input-36-59efb7b3f5b2>", line 7
    return(predicted_price)cols = 0
                              ^
SyntaxError: invalid syntax

Hi Ariana,

“return(predicted_price)cols = 0”

You ask why this is a syntax error. I’m sorry, I don’t understand the
question. It’s a syntax error because it is syntax which isn’t legal in
the language.

You cannot follow a bracketed word with another word:

(hello)world

is a syntax error. You also cannot have an assignment statement in a
return statement:

return value=0

is also a syntax error. You managed to get both of these syntax errors
in the same line of code.

# return (hello)words = 0
return (predicted_price)cols = 0

By the way, return is not a function and you don’t need parentheses
around the return value:

return predicted_price

is usually considered better than making it look like a function call:

return(predicted_price)

It is not a function call, return is a statement.

@steven.daprano
The code is from https://www.dataquest.io/blog/machine-learning-tutorial/
I try to make something like there. If I write “return predicted_price” I will have an error on the next line of code because appear “cols”
norm_test_df[cols].apply(predict_price_multivariate,feature_columns=cols,axis=1)

I see, that line:

return(predicted_price)cols = ['accommodates', 'bathrooms']

is directly copied from the tutorial. That’s a bug in their tutorial. I
don’t know what they meant it to be but I think that there should be at
least one blank line separating the return from the assignment to cols:

# inside the function should be indented
    return predicted_price

# this is outside the function and should not be indented
cols = ['accommodates', 'bathrooms']

But I don’t really know for sure. Try it and see. If you get an error,
don’t just tell us there’s an error, copy and paste the error and show
us. (Not a screen shot or a photo, copy the text and paste it into your
response.)

Good luck!

Thank you for help! I am a beginner and I still do not recognize the mistakes in the tutorials.

Somebody should report the problem to the authors of that tutorial, so it can be fixed.