Question: In python using Numpy only. And here is a sample output def get_cv_folds (data, numfolds, selected): (5 pts) This function performs cross validation fold selection/extraction.

In python using Numpy only.

In python using Numpy only. And here is a sample output def

And here is a sample output

get_cv_folds (data, numfolds, selected): (5 pts) This function performs cross validation fold

selection/extraction. It three items (data: the data itself, numfolds: the number of

folds, selected: which fold to select as TESTING) it returns two separate

def get_cv_folds (data, numfolds, selected): (5 pts) This function performs cross validation fold selection/extraction. It three items (data: the data itself, numfolds: the number of folds, selected: which fold to select as TESTING) it returns two separate data sets (training and testing). NOTE: assume the dataset will always be evenly divided into folds (do not worry about uneven datasets and folds) Parameters: data: a 2-D numpy array that represents examples and their features (N x M) (N: examples, M: features) numfolds: a number to indicate how many folds to split the data into selected: the fold to be selected for testing (for example, if we have numfolds = 5, then it can be any number from 1 to 5). Note: when selected = 1, that means the fold starting from the beginning of the data is selected as testing and when selected = numfolds, that means the fold at the end of the data is selected for testing. Note2: no data shuffling (randomization) is assumed. So the order of the tuples should remain the same. Notice that the function returns two separate arrays. The first being the training set and the second is the testing set. return [None, None] In [17]: test = np.array([[1, 0.5], [2, -0.2], [3, 5.1], [4, -5.5], [5, 6.7], [6, 8.9], [7, -4.3], [8, 2.2], [9, 5.1], [10, -2.1]]) In [18]: print(test) [[ 1. 0.5] [ 2. -0.2] [ 3. 5.1] [ 4. -5.5] [ 5. 6.7] [ 6. 8.9] [ 7. -4.3] [ 8. 2.2] [ 9. 5.1] [10. -2.1]] selected rows for In [19]: [tr, ts] = hw3.getCvFolds (test, 5, 1) select fold I which has rows 1&2 for testing and the remaining [ 5., In [20]: tr Out[20]: array([[ 3. 5.1], [ 4. , -5.5], 6.7], [ 6. , 8.9], [ 7. , -4.3], [ 8. 2.2], [ 9. , 5.1], [10. -2.1]]) vous for training ) In [21] : ts Out[21] : array([[ 1. 0.5], [ 2. , -0.2]]) In [22]: [tr, ts] = hw3.getCvFolds (test, 5, testing = 3&4 ) In [23]: tr Out[23]: array([[ 1. 0.5], [ 2. -0.2], [ 5. , 6.7], 8.9], [ 7. , -4.3], [ 8., 2.2), [ 9., 5.1], [10. , -2.1]]). [ 6. In [24] : ts Out[24]: array([[ 3. [ 4. 5.1], -5.5]])

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!