1

Train Test Split

Unsolved
Fundamentals

Difficulty: 3 | Problem written by zeyad_omar
Problem reported in interviews at

Amazon
Apple
Facebook
Google
Netflix

In deep learning, engineers need to make sure that their model is general and gives high accuracy for unseen data. 

This can be done by splitting the data into 2 sets: one is the training set and the other is the test set.

The training set is used to train the model and optimize the weights, and the test set is used to test the model and checks if it gives high accuracy for the unseen data.

In this problem, you are required to implement a function that splits the data X and the labels Y into: 

X_train, Y_train, X_test, and Y_test by a ratio

For example, if the input is X = [0.5 ,0.1,0.2,0.3] and Y= [1 ,0 ,1 ,1] and the ratio is 0.5 then:

X_train = [0.5,0.1]

Y_train = [1,0]

X_test = [0.2 , 0.3]

Y_test = [ 1 ,1]

Please return X_train,Y_train,X_test,Y_test to match the test cases.

Sample Input:
<class 'list'>
X: [5, 9, 8, 7]
<class 'list'>
Y: [0, 1, 1, 0]
<class 'float'>
r: 0.5

Expected Output:
<class 'tuple'>
(array([5, 9]), array([0, 1]), array([8, 7]), array([1, 0]))

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Repellat quidem ipsam ut amet, voluptas adipisci facere tempore minima explicabo illum veritatis commodi impedit dicta, repellat eum a neque, culpa error facere? Quae natus quibusdam perferendis obcaecati? Reprehenderit hic laborum eveniet autem, quos commodi iusto velit hic dolores sit accusantium harum excepturi, molestiae fugit quam officiis corrupti alias reiciendis. Id vero quibusdam fugit dolorum soluta non quidem nobis, distinctio ratione placeat temporibus voluptatum asperiores qui corporis quia nam tenetur ad, dicta modi similique soluta excepturi unde, maiores ad tempora accusantium minus commodi incidunt dignissimos distinctio accusamus.

Architecto excepturi similique perferendis voluptatem fuga odio ea. Iusto tempore consectetur sapiente, distinctio ad fugit qui autem quo iusto, dicta earum beatae reprehenderit impedit numquam nisi delectus consequuntur rem corrupti eum, quis autem blanditiis quas, magnam in debitis necessitatibus?

A mollitia commodi cumque distinctio cupiditate corporis, et voluptatum nemo nostrum omnis in alias, molestiae ad quae fuga eligendi sunt iure sed neque maxime, pariatur tempora temporibus ex eaque dolores eligendi cumque minima asperiores corrupti illum, quos accusantium autem sapiente possimus cumque mollitia recusandae? Perferendis mollitia inventore, doloremque ratione repudiandae quibusdam harum cum autem, beatae atque quasi quae dolorem iure porro quo sit sequi. Dolores eius explicabo ratione ipsam provident adipisci dignissimos enim labore quod, amet voluptatibus quibusdam necessitatibus, blanditiis sit pariatur.

This is a premium feature.
To access this and other such features, click on upgrade below.

Ready.

Input Test Case

Please enter only one test case at a time
numpy has been already imported as np (import numpy as np)