This study suggests a machine learning-based approach for fault diagnosis and fault location in DCMGs, using state-of-the-art data-driven approaches to enhance protection performance. Current and voltage waveforms are analyzed to extract important features like as harmonics, wavelet coefficients, and statistical metrics, which are then fed into a supervised machine learning model. After being trained on a large number of fault situations, including PP and PG problems at various locations and impedance levels, the model gains the ability to accurately detect fault conditions. To provide precise fault detection, a dynamic relay threshold is set by looking at the fault classification probabilities generated by the ML model. Once this threshold has been determined centrally, the MG relays are notified. While the MG is in operation, the model continuously verifies it by comparing the relay threshold to real-time feature inputs. As soon as a flaw is detected, the system sends a trip signal to the circuit breaker. The proposed method effectively locates and detects both HIF and LIF across a resistance range of up to 50 Ω in both grid-connected and islanded modes. Comprehensive MATLAB and EMTP-RV simulations validate the scalability and dependability of the proposed machine learning-based security technique. The suggested scheme's ability to adjust to variations in MG topology is further shown by these simulations.