Skip to content

Commit

Permalink
Merge pull request #9218 from bashtage/forward-port-doc-fixes
Browse files Browse the repository at this point in the history
DOC: Fix multiple issues in notebooks
  • Loading branch information
bashtage committed Apr 18, 2024
2 parents 2329992 + 018362a commit d6466f7
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 21 deletions.
2 changes: 1 addition & 1 deletion examples/notebooks/ets.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
" 549.8338,\n",
" 542.3405,\n",
"]\n",
"oil = pd.Series(oildata, index=pd.date_range(\"1965\", \"2013\", freq=\"AS\"))\n",
"oil = pd.Series(oildata, index=pd.date_range(\"1965\", \"2013\", freq=\"YS\"))\n",
"oil.plot()\n",
"plt.ylabel(\"Annual oil production in Saudi Arabia (Mt)\")"
]
Expand Down
8 changes: 4 additions & 4 deletions examples/notebooks/exponential_smoothing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
" 514.2689,\n",
" 494.211,\n",
"]\n",
"index = pd.date_range(start=\"1996\", end=\"2008\", freq=\"A\")\n",
"index = pd.date_range(start=\"1996\", end=\"2008\", freq=\"Y\")\n",
"oildata = pd.Series(data, index)\n",
"\n",
"data = [\n",
Expand All @@ -74,7 +74,7 @@
" 41.3864,\n",
" 41.5966,\n",
"]\n",
"index = pd.date_range(start=\"1990\", end=\"2005\", freq=\"A\")\n",
"index = pd.date_range(start=\"1990\", end=\"2005\", freq=\"Y\")\n",
"air = pd.Series(data, index)\n",
"\n",
"data = [\n",
Expand Down Expand Up @@ -110,11 +110,11 @@
" 408.2705,\n",
" 414.2428,\n",
"]\n",
"index = pd.date_range(start=\"1970\", end=\"2001\", freq=\"A\")\n",
"index = pd.date_range(start=\"1970\", end=\"2001\", freq=\"Y\")\n",
"livestock2 = pd.Series(data, index)\n",
"\n",
"data = [407.9979, 403.4608, 413.8249, 428.105, 445.3387, 452.9942, 455.7402]\n",
"index = pd.date_range(start=\"2001\", end=\"2008\", freq=\"A\")\n",
"index = pd.date_range(start=\"2001\", end=\"2008\", freq=\"Y\")\n",
"livestock3 = pd.Series(data, index)\n",
"\n",
"data = [\n",
Expand Down
6 changes: 2 additions & 4 deletions examples/notebooks/glm.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
"means75.iloc[0] = lowinc_75per = stats.scoreatpercentile(data.exog.iloc[:,0], 75)\n",
"resp_25 = res.predict(means25)\n",
"resp_75 = res.predict(means75)\n",
"diff = resp_75 - resp_25"
"diff = resp_75 - resp_25\n"
]
},
{
Expand All @@ -174,9 +174,7 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(\"%2.4f%%\" % (diff*100))"
]
"source": "print(\"%2.4f%%\" % (diff.iloc[0]*100))"
},
{
"cell_type": "markdown",
Expand Down
5 changes: 3 additions & 2 deletions examples/notebooks/linear_regression_diagnostics_plots.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"import matplotlib.pyplot as plt\n",
"from typing import Type\n",
"\n",
"style_talk = 'seaborn-talk' #refer to plt.style.available\n",
"\n",
"class LinearRegDiagnostic():\n",
" \"\"\"\n",
Expand Down Expand Up @@ -155,7 +156,7 @@
" >>> df = pd.DataFrame({'x':x, 'y':y})\n",
" >>> res = smf.ols(formula= \"y ~ x\", data=df).fit()\n",
" >>> cls = Linear_Reg_Diagnostic(res)\n",
" >>> cls(plot_context=\"seaborn-v0_8\")\n",
" >>> cls(plot_context=\"seaborn-v0_8-paper\")\n",
"\n",
" In case you do not need all plots you can also independently make an individual plot/table\n",
" in following ways\n",
Expand Down Expand Up @@ -186,7 +187,7 @@
" self.nparams = len(self.results.params)\n",
" self.nresids = len(self.residual_norm)\n",
"\n",
" def __call__(self, plot_context='seaborn-v0_8', **kwargs):\n",
" def __call__(self, plot_context='seaborn-v0_8-paper', **kwargs):\n",
" # print(plt.style.available)\n",
" # GH#9157\n",
" if plot_context not in plt.style.available:\n",
Expand Down
17 changes: 15 additions & 2 deletions examples/notebooks/markov_autoregression.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,21 @@
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import shutil\n",
"\n",
"def download_file(url):\n",
" local_filename = url.split('/')[-1]\n",
" with requests.get(url, stream=True) as r:\n",
" with open(local_filename, 'wb') as f:\n",
" shutil.copyfileobj(r.raw, f)\n",
"\n",
" return local_filename\n",
"\n",
"filename = download_file(\"https://www.stata-press.com/data/r14/rgnp.dta\")\n",
"# Get the RGNP data to replicate Hamilton\n",
"dta = pd.read_stata(\"https://www.stata-press.com/data/r14/rgnp.dta\").iloc[1:]\n",
"\n",
"dta = pd.read_stata(filename).iloc[1:]\n",
"dta.index = pd.DatetimeIndex(dta.date, freq=\"QS\")\n",
"dta_hamilton = dta.rgnp\n",
"\n",
Expand Down Expand Up @@ -283,7 +296,7 @@
"std_ratio = (\n",
" dta_filardo[\"dlip\"][\"1960-01-01\":].std() / dta_filardo[\"dlip\"][:\"1959-12-01\"].std()\n",
")\n",
"dta_filardo[\"dlip\"][:\"1959-12-01\"] = dta_filardo[\"dlip\"][:\"1959-12-01\"] * std_ratio\n",
"dta_filardo.loc[:\"1959-12-01\", \"dlip\"] = dta_filardo[\"dlip\"][:\"1959-12-01\"] * std_ratio\n",
"\n",
"dta_filardo[\"dlleading\"] = np.log(dta_filardo[\"leading\"]).diff() * 100\n",
"dta_filardo[\"dmdlleading\"] = dta_filardo[\"dlleading\"] - dta_filardo[\"dlleading\"].mean()\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/notebooks/recursive_ls.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"print(sm.datasets.copper.DESCRLONG)\n",
"\n",
"dta = sm.datasets.copper.load_pandas().data\n",
"dta.index = pd.date_range(\"1951-01-01\", \"1975-01-01\", freq=\"AS\")\n",
"dta.index = pd.date_range(\"1951-01-01\", \"1975-01-01\", freq=\"YS\")\n",
"endog = dta[\"WORLDCONSUMPTION\"]\n",
"\n",
"# To the regressors in the dataset, we add a column of ones for an intercept\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/notebooks/statespace_arma_0.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
},
"outputs": [],
"source": [
"dta.index = pd.Index(pd.date_range(\"1700\", end=\"2009\", freq=\"A-DEC\"))\n",
"dta.index = pd.Index(pd.date_range(\"1700\", end=\"2009\", freq=\"YE-DEC\"))\n",
"del dta[\"YEAR\"]"
]
},
Expand Down
4 changes: 2 additions & 2 deletions examples/notebooks/statespace_forecasting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@
"outputs": [],
"source": [
"# Annual frequency, using a PeriodIndex\n",
"index = pd.period_range(start='2000', periods=4, freq='A')\n",
"index = pd.period_range(start='2000', periods=4, freq='Y')\n",
"endog1 = pd.Series([1, 2, 3, 4], index=index)\n",
"print(endog1.index)"
]
Expand All @@ -619,7 +619,7 @@
"outputs": [],
"source": [
"# Monthly frequency, using a DatetimeIndex\n",
"index = pd.date_range(start='2000', periods=4, freq='M')\n",
"index = pd.date_range(start='2000', periods=4, freq='ME')\n",
"endog3 = pd.Series([1, 2, 3, 4], index=index)\n",
"print(endog3.index)"
]
Expand Down
2 changes: 1 addition & 1 deletion examples/notebooks/statespace_local_linear_trend.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
"outputs": [],
"source": [
"# Load Dataset\n",
"df.index = pd.date_range(start='%d-01-01' % df.date[0], end='%d-01-01' % df.iloc[-1, 0], freq='AS')\n",
"df.index = pd.date_range(start='%d-01-01' % df.date[0], end='%d-01-01' % df.iloc[-1, 0], freq='YS')\n",
"\n",
"# Log transform\n",
"df['lff'] = np.log(df['ff'])\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/notebooks/statespace_news.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@
"infl.columns = ['PCE', 'CPI']\n",
"\n",
"# Remove two outliers and de-mean the series\n",
"infl['PCE'].loc['2001-09':'2001-10'] = np.nan"
"infl.loc['2001-09':'2001-10', 'PCE'] = np.nan"
]
},
{
Expand Down
15 changes: 14 additions & 1 deletion examples/notebooks/statespace_varmax.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,20 @@
},
"outputs": [],
"source": [
"dta = sm.datasets.webuse('lutkepohl2', 'https://www.stata-press.com/data/r12/')\n",
"import requests\n",
"import shutil \n",
"\n",
"def download_file(url):\n",
" local_filename = url.split('/')[-1]\n",
" with requests.get(url, stream=True) as r:\n",
" with open(local_filename, 'wb') as f:\n",
" shutil.copyfileobj(r.raw, f)\n",
"\n",
" return local_filename\n",
"\n",
"filename = download_file(\"https://www.stata-press.com/data/r12/lutkepohl2.dta\")\n",
"\n",
"dta = pd.read_stata(filename)\n",
"dta.index = dta.qtr\n",
"dta.index.freq = dta.index.inferred_freq\n",
"endog = dta.loc['1960-04-01':'1978-10-01', ['dln_inv', 'dln_inc', 'dln_consump']]"
Expand Down
2 changes: 1 addition & 1 deletion examples/notebooks/tsa_dates.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"source": [
"from datetime import datetime\n",
"\n",
"dates = pd.date_range(\"1700-1-1\", periods=len(data.endog), freq=\"A-DEC\")"
"dates = pd.date_range(\"1700-1-1\", periods=len(data.endog), freq=\"YE-DEC\")"
]
},
{
Expand Down

0 comments on commit d6466f7

Please sign in to comment.