1

I am creating a system in order to predict earthquakes. There's this code in which there is a line %config InlineBackend.figure_format = 'retina'. Whenever I run my python code it gives the error as ("% invalid syntax").

Earlier I had the problem of %matplotlib statement which I figured out through google. But, this problem is sucking me.

https://www.kaggle.com/pablocastilla/predict-earthquakes-with-lstm ("The source from where the code has been taken")

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
from subprocess import check_output
from keras.layers.core import Dense, Activation, Dropout
from keras.layers.recurrent import LSTM
from keras.models import Sequential
from sklearn.cross_validation import  train_test_split
import time #helper libraries
from sklearn.preprocessing import MinMaxScaler
import matplotlib.pyplot as plt
from numpy import newaxis
from geopy.geocoders import Nominatim
from IPython import get_ipython

get_ipython().run_line_magic('matplotlib', 'inline')

import warnings
warnings.filterwarnings('ignore')

%config InlineBackend.figure_format = 'retina'

# Any results you write to the current directory are saved as output.
from subprocess import check_output
print(check_output(["ls", "../input"]).decode("utf8"))

So it is showing "error invalid syntax " and the % sign before the word config has been highlighted.

The expected output is that I should not recieve an error and any results that are written to the directory are given out.

Matthias
  • 12,873
  • 6
  • 42
  • 48

2 Answers2

1

That % syntax is defining a IPython Magic Command. Read: Magic commands

Give this a try

from IPython.display import set_matplotlib_formats
set_matplotlib_formats('retina')

Taken from Configure the backend of Ipython to use retina display mode with code

You need to install Ipython library in order to do this. Also if you get "No module named ipykernel" then install ipykernel.

    pip install ipython
    pip install ipykernel

Edit: but I highly recommend using jupyter notebooks for example give google colab a try : https://colab.research.google.com/notebooks/welcome.ipynb

eemilk
  • 1,375
  • 13
  • 17
0

Commands starting with % are not valid python commands, they are only supported by ipython/jupyter interpreter, not by the official python interpreter.

Dr. Snoopy
  • 55,122
  • 7
  • 121
  • 140