How to create a tra...
 
Notifications
Clear all

How to create a train and test sample from one dataframe using pandas  

  RSS

Ganesh A
(@ganesh)
Noble Member
Joined: 4 months ago
Posts: 1170
31/03/2021 10:19 am  
I have a large dataset in the form of dataframe, which I want to split into training and testing sample of 80% and 20% respectively. How can I do it?
 

Quote
Anamika
(@anamika)
Noble Member
Joined: 4 months ago
Posts: 1179
31/03/2021 10:20 am  

The below written code can help you to split your dataset into training and testing samples:

from sklearn.model_selection import train_test_split
trainingSet, testSet = train_test_split(df, test_size=0.2)

Test size may differ depending on the percentage of data you want to put in your testing and training samples


ReplyQuote
Share: