def get_train_test(reviews=None, random_state=None):
 import numpy as np
 import random
 r = random.Random(random_state)
 if (reviews is None):
  reviews = load()
 (U, M) = np.where(reviews)
 test_idxs = np.array(r.sample(range(len(U)), (len(U) // 10)))
 train = reviews.copy()
 train[(U[test_idxs], M[test_idxs])] = 0
 test = np.zeros_like(reviews)
 test[(U[test_idxs], M[test_idxs])] = reviews[(U[test_idxs], M[test_idxs])]
 return (train, test)

def get_train_test ( reviews = None , random_state = None ) : import numpy as np import random r = random . Random ( random_state ) if ( reviews is None ) : reviews = load ( ) ( U , M ) = np . where ( reviews ) test_idxs = np . array ( r . sample ( range ( len ( U ) ) , ( len ( U ) // 10 ) ) ) train = reviews . copy ( ) train [ ( U [ test_idxs ] , M [ test_idxs ] ) ] = 0 test = np . zeros_like ( reviews ) test [ ( U [ test_idxs ] , M [ test_idxs ] ) ] = reviews [ ( U [ test_idxs ] , M [ test_idxs ] ) ] return ( train , test )
split data into training & testing parameters reviews : ndarray .