<abstract><p>Maritime transport plays an important role in global supply chain. To guarantee maritime safety, protect the marine environment, and enhance the living and working conditions of the seafarers, international codes and conventions are developed and implemented. Port state control (PSC) is a critical maritime policy to ensure that ships comply with the related regulations by selecting and inspecting foreign visiting ships visiting a national port. As the major inspection result, ship detention, which is an intervention action taken by the port state, is dependent on both deficiency/deficiencies (i.e., noncompliance) detected and the judgement of the inspector. This study aims to predict ship detention based on the number of deficiencies identified under each deficiency code and explore how each of them influences the detention decision. We innovatively view ship detention as a type of anomaly, which refers to data points that are few and different from the majority, and develop an isolation forest (iForest) model, which is an unsupervised anomaly detection model, for detention prediction. Then, techniques in explainable artificial intelligence are used to present the contribution of each deficiency code on detention. Numerical experiments using inspection records at the Hong Kong port are conducted to validate model performance and generate policy insights.</p></abstract>