Monday, 5 January 2026

The list() constructor in Python

The list constructor in Python is interesting because there are evidently more obvious ways to create lists, namely via square bracket notation.  However, using the constructor directly has a number of use cases.

Here are some syntactical examples of using the list constructor.

empty_list = list()
tuple_to_list = list( (1,2,3) )
string_to_list = list("constructor") # creates a list made of individual letters as elements

Testing Prediction Models - Out of Sample Testing

When testing a prediction model, it is a good idea to do "out of sample" testing. 

This involves testing a model or strategy on data that was not used during model building or training. It thus evaluates how well the model performs on new, unseen data.

Python Internal Modules - The Underscore Convention

After debugging Python for a while you will certainly see some files with leading underscores. 

This is a Python convention to indicate the file is not part of the public interface of the module.  An example could be _mixins.py for a mixins class (this is used in pandas for example).  

When doing a "from package import *" any file with an underscore is not imported, respecting this convention. 

Sometimes an underscore can also be used to prevent name collisions e.g. implementing some JSON helpers in _json.py to avoid conflict with another json.py (pandas has this file too).

Pat yourself on the back if you have debugged into an underscore-prefixed file - you have ventured into the hidden depths of a package's implementation details. Good Job!

Python Debugger Survival Skills

There are many times you will need to use the Python debugger to understand why something is not working (oftentimes in a third-party library).

pdb - invokes the debugger
n - moves to the next line (can press carriage return - same effect)
s - steps into the code

It will certainly help you explore and understand more about how the third-party libraries work.

ARIMA in Python: Endogenous versus Exogenous Variables

The ARIMA model in statsmodels is described here.

Its constructor has the following initial arguments: ARIMA( endog, exog=None, order=(0,0,0),....).

  • endog - observed time series process, y
  • exog - array of "exogenous regressors"
  • order - (p, d, q) model for autoregressive, differences and moving average component
Exogeneous regressors are added to the ARIMA equation where external variables may have some forecasting power. For example, electricity demand could utilise temperature as an exogenous variable.

The (p, d, q) component specification can be said to be the true "spirit" of ARIMA.

ARIMA methods were created by George Box and Gwilym Jenkins and are hence sometimes called  Box-Jenkins methods.

SARIMA extends this to Seasonal Data, where seasonal differencing is used to create stationarity.

Sunday, 4 January 2026

Claude Code

Claude Code is built for developers - try it.

You can run it from a terminal (formerly only WSL).

Due to prompt injection risks, do not use it on codebases you do not trust.