Prison violence is a major safety issue for people in prison and staff. In Aotearoa New Zealand, all prison incidents are recorded on the Department of Corrections (Ara Poutama Aotearoa) COBRA database. An analysis of prison violence at the unit level is applied using machine learning to provide a prediction model of prison violence as well as identify important factors associated with violence. The analysis identifies gang affiliation and security class as important predictors of violence in prison. The study also demonstrates the importance of the social environment and spatial scale when conducting an analysis of prison data.