Why do we split the data into two parts, and then split those segments into training and testing data? Why do we have two sets of data for each training and test data?
For any Machine Learning model, the available data is usually split into three sets:
The part of data used to train the model and learn the parameters of the network.
The data that remains after allocation of the Training Dataset, is split into the Validation and Test sets.
This sample of data is used to provide an unbiased evaluation of a model fit on the training dataset. This helps in tuning model hyperparameters to improve the model performance. Eg: Changing the number of clusters ($k$) in a K-Means algorithm, or the pooling layers in a CNN.
After training, this part of the dataset is used to used to test how well the model generalizes to unseen data and estimate its performance.
Another possibility (going by your question), is the use of Cross-Validation. This is performed when the dataset is too small. In such a case, a random split is performed on the dataset resulting in k non-overlapping subsets. The test error is then estimated by taking the average test error across k trials. [Image Source]
Usually we are splinting the data into 3 chunks for example 70% for training, 10% for validation and 20% for testing. The first two chunks are going to be used for training. The reason you need the validation dataset is to tune your hyper-parameters and see how well your model can generalize. Once you have a model that achieves a fairly good performance on the validation dataset, you're measuring its accuracy on the test dataset.