Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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.
And here is a sample output
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started