I have a 5000 x 3027 matrix training dataset (CIFAR-10 dataset). Using array_split in numpy, I split it into 5 different parts, and I want to select only one of the parts as a cross validation cross. However, my problem arises when I use something like XTrain [[Indexes]], where the indices are an array, such as [0,1,2,3], because it gives me a 3D tensor of dimensions 4 x 1000 x 3027 , not a matrix. How to collapse "4 x 1000" into 4000 lines to get a 4000 x 3027 matrix?
for fold in range(len(X_train_folds)): indexes = np.delete(np.arange(len(X_train_folds)), fold) XTrain = X_train_folds[indexes] X_cv = X_train_folds[fold] yTrain = y_train_folds[indexes] y_cv = y_train_folds[fold] classifier.train(XTrain, yTrain) dists = classifier.compute_distances_no_loops(X_cv) y_test_pred = classifier.predict_labels(dists, k) num_correct = np.sum(y_test_pred == y_test) accuracy = float(num_correct/num_test) k_to_accuracy[k] = accuracy
source share