# How to Create a Training, validation and Test set in PySpark ?

## randomSplit –

Sometimes you may want to randomly split a pyspark dataframe into different parts. A common example is in Machine Learning where you want to creating a training, validation and test set. For this purpose you can use the randomSplit method in pyspark.

In this example we will split the dataframe into three parts. And because this method is designed to be randomized, we will also specify a seed. It’s important to note that if you don’t specify a proportion for each dataframe that adds up to one, they will be normalized so that they do.

from pyspark.sql import SparkSession
df.show(5)
dataframes = df.randomSplit([0.6, 0.2, 0.2], seed=26)