1

I'm having the following error whilst using Jupyter Notebook to create code to forecast some data:

File "<ipython-input-104-f41838a4a887>", line 240 else: ^ SyntaxError: invalid syntax 

I have checked for indentation and formatting errors but no luck solving yet.

if dfoutput[1] <= 0.05: # Auto Correlation plot to select p term for the ARIMA model. auto_corr(df) set_p_value() # Partial Auto Correlation plot to select q term for the ARIMA model. plot_pacf(df) set_q_value() # d value == 0 as no differencing took place. print('\nd value set as 0 as no differencing took place.') d_value = 0 # Select length of time to forecast over. future_dates(forecast_length) # Create the ARIMA model (Use the values of the dataframe to avoid ValueError): model = ARIMA(df.values, order=(p_value, d_value, q_value)) results = model.fit() # Option to show summary of the model: model_summary(results) # Option to show the residuals: show_residuals(results) # FORECASTING THE DATA final_df['forecast'] = results.predict(start=0, end=len(final_df) - 1) # Plotting the forecasted values plt.figure(figsize=(12,7)) plt.plot(final_df[column_to_assess], label='real', color='blue') plt.plot(final_df['forecast'].iloc[len(df)-1:], label='forecast', color='red') plt.xlabel('Date') plt.ylabel('Median House Value') plt.title('Median House Prices for ' + column_to_assess + ' (1995 - 2018) & Forecasted Prices (2018 - ' + str(final_df.index[-1].year) + ")") plt.grid() plt.legend() '''THIS IS WHERE THE ERROR ARISES:''' else: # Perform Error, Trend, Seasonality (ETS) decomposition to check for seasonality: ets_result = seasonal_decompose(df.astype(int), model='multiplicative') # Plot the ETS decomposition fig = result.plot() fig.set_size_inches(12,7) 
2
  • Welcome to stack overflow! Please include the full traceback of the error in your question so that we can better help you Commented Aug 29, 2019 at 21:57
  • Check around that line in your code for invalid syntax, like indentations, bad operands, misspelled keywords. Remember that it may not necessarily be that line with an invalid syntax. Commented Aug 29, 2019 at 21:58

1 Answer 1

5

Ironically, the only reason for the error is your marker text: '''THIS IS WHERE THE ERROR ARISES:'''. That's not a comment but rather a triple-quoted string literal, which disconnects the else from the if. Remove that and the syntax error goes away.

Sign up to request clarification or add additional context in comments.

2 Comments

but then why did he put the literal in there in the first place :-/ odd!
@MikeVella I'm guessing that it was some other multiline "comment" in the original, that he changed to that to point out the line to us.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.