Suboptimal Python translations #55
Replies: 3 comments 1 reply
-
|
Hi @Phlos, thanks so much taking such a close look at the book and raising this concern as well as the other issues you raised. Let us take a look and come with a solution. We are working under @robjhyndman guidance to make the printable version ready and it would be truly amazing, in case you can, to keep those comments and issues coming. Having an extra set of eyes looking over this first version can only be beneficial. |
Beta Was this translation helpful? Give feedback.
-
|
OK for section 7.1 the plotting examples: # Read data
us_change = pd.read_csv("fpppy_data/US_change.csv", parse_dates=["ds"])
# Plot
fig, ax = plt.subplots()
ax.plot(us_change["ds"], us_change["Income"], label="Income")
ax.plot(us_change["ds"], us_change["y"], label="Consumption")
ax.set_xlabel("Quarter [1Q]")
ax.set_ylabel("% change")
ax.legend()
plt.show()could be # Read data
us_change = pd.read_csv("fpppy_data/US_change.csv", parse_dates=["ds"])
# Plot
us_change.plot(
x='ds', y=['Income', 'y'], ylabel='% change', xlabel='Quarter [1Q]', label=['Income', 'Consumption']
)and fig, axes = plt.subplots(nrows=3, ncols=1, sharex=True)
sns.lineplot(data=us_change, x="ds", y="Production", ax=axes[0],
color="#D55F03", label="Production")
sns.lineplot(data=us_change, x="ds", y="Savings", ax=axes[1],
color="#569CC6", label="Savings")
sns.lineplot(data=us_change, x="ds", y="Unemployment", ax=axes[2],
color="#13A076", label="Unemployment")
for ax in axes:
ax.set_ylabel("")
ax.set_xlabel("")
fig.supylabel("% change")
fig.supxlabel("Quarter")
plt.show()can be shortened to us_change.plot(
x='ds', y=['Production', 'Savings', 'Unemployment'],
subplots=True, layout=(3,1), sharex=True, ylabel='% change', xlabel='Quarter'
)That is, if you allow colors to be slightly different. Personally I don't think explicitly defined colors add much, so I'd leave it out for clarity and brevity. |
Beta Was this translation helpful? Give feedback.
-
|
And by the way, from a quick look, I think that this repo has many best practice versions -- although as per its preface, not everything is up to date / cleaned up. But I think it's worth a look, to tidy up the code and use the most standard tools. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, throughout the book I notice code snippets of the Python version that do the job, but are not optimal. I think it would greatly add to the book if these could be corrected to more "proper" examples (so that new students don't learn suboptimal habits while they're learning forecasting). Two examples below:
Plotting example
To plot a series, it is not necessary to import a special
plot_seriesfunction as the one that is used in the example:Instead, one can plot the data directly using the built-in dataframe
plot()method:Data handling example
And here a data handling example from section 5.1:
would be much cleaner written like this:
or even, since
train_dfdoesn't appear to be used in what follows, like thisAs an aside: for the
.drop()method, you can use.drop(columns=['GDP', 'Population']instead of usingaxis=1to improve readability.Note: I've filed this under error report, wasn't quite sure where to place this. Apologies if it's the wrong type.
Beta Was this translation helpful? Give feedback.
All reactions