Analysing track geometry defects is critical for safe and effective railway transportation. Rectifying the appropriate number, types and combinations of geo-defects can effectively reduce the probability of derailments. In this paper, we propose an analytical framework to assist geo-defect rectification decision making. Our major contributions lie in formulating and integrating the following three data-driven models: (1) A track deterioration model to capture the degradation process of different types of geo-defects; (2) A survival model to assess the dynamic derailment risk as a function of track defect and traffic conditions; (3) An optimization model to plan track rectification activities with two different objectives: a cost-based formulation (CF) and a risk-based formulation (RF). We apply these approaches to solve the optimal rectification planning problem for a real-world railway application. We show that the proposed formulations are efficient as well as effective, as compared with existing strategies currently in practice.