Back to Browse

KFold Cross Validation using Scikit Learn | Best Model | KFold from sklearn.model_selection

3.5K views
Nov 10, 2018
3:12

KFold Cross Validation using Scikit Learn | Best Model | KFold from sklearn.model_selection Python For Machine Learning - Session # 91 Topic to be covererd - KFold Cross Validation using sklearn.model_selection In k-fold cross-validation, the original sample is randomly partitioned into k equal sized subsamples. Of the k subsamples, a single subsample is retained as the validation data for testing the model, and the remaining k − 1 subsamples are used as training data. The cross-validation process is then repeated k times, with each of the k subsamples used exactly once as the validation data. The k results can then be averaged to produce a single estimation. The advantage of this method over repeated random sub-sampling (see below) is that all observations are used for both training and validation, and each observation is used for validation exactly once. 10-fold cross-validation is commonly used, but in general k remains an unfixed parameter. For example, setting k = 2 results in 2-fold cross-validation. In 2-fold cross-validation, we randomly shuffle the dataset into two sets d0 and d1, so that both sets are equal size (this is usually implemented by shuffling the data array and then splitting it in two). We then train on d0 and validate on d1, followed by training on d1 and validating on d0. When k = n (the number of observations), k-fold cross-validation is equivalent to leave-one-out cross-validation. Code Starts here ============== from sklearn.model_selection import KFold X = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14] kf1 = KFold(n_splits=3,shuffle=True) print('****************************************************************************') print('{}{:^31} {}'.format('Iterations','Training Set', 'Testing Set')) print('****************************************************************************') for train_index, test_index in kf1.split(X): print('Train :', train_index, 'Test:', test_index) All the playlist of this youtube channel ======================================== 1. Data Preprocessing in Machine Learning https://www.youtube.com/playlist?list=PLE-8p-CwnFPuOjFcbnXLFvSQaHFK3ymUW 2. Confusion Matrix in Machine Learning, ML, AI https://www.youtube.com/playlist?list=PLE-8p-CwnFPvXzvsEcgb0IZtNsw_0vUzr 3. Anaconda, Python Installation, Spyder, Jupyter Notebook, PyCharm, Graphviz https://www.youtube.com/playlist?list=PLE-8p-CwnFPsBCsWwz_BvbZZHIVQ6wSZK 4. Cross Validation, Sampling, train test split in Machine Learning https://www.youtube.com/playlist?list=PLE-8p-CwnFPsHtol5WXHhq_B3kQPggHH2 5. Drop and Delete Operations in Python Pandas https://www.youtube.com/playlist?list=PLE-8p-CwnFPtvqVVK7QVFsMvDvp2YgCnR 6. Matrices and Vectors with python https://www.youtube.com/playlist?list=PLE-8p-CwnFPsndwnZnL7nXW5mIrdRmgdg 7. Detect Outliers in Machine Learning https://www.youtube.com/playlist?list=PLE-8p-CwnFPvyCX35yES5D9W7vThiUzwk 8. TimeSeries preprocessing in Machine Learning https://www.youtube.com/playlist?list=PLE-8p-CwnFPv10bru3719xzDNIgbO6hXA 9. Handling Missing Values in Machine Learning https://www.youtube.com/playlist?list=PLE-8p-CwnFPvOec0LZ40Bt8OQcbLFa236 10. Dummy Encoding Encoding in Machine Learning https://www.youtube.com/playlist?list=PLE-8p-CwnFPvu7YriqMZsL9UDbqUUk90x 11. Data Visualisation with Python, Seaborn, Matplotlib https://www.youtube.com/playlist?list=PLE-8p-CwnFPuYBYsmbfMjROOCzKjCwyMH 12. Feature Scaling in Machine Learning https://www.youtube.com/playlist?list=PLE-8p-CwnFPtwpVV3FwzwYZYR5hT3i52G 13. Python 3 basics for Beginner https://www.youtube.com/playlist?list=PLE-8p-CwnFPu-jseUMtc4i47jQZN4PNbf 14. Statistics with Python https://www.youtube.com/playlist?list=PLE-8p-CwnFPta0COlxS6E5u14m5ouzbRU 15. Data Preprocessing in Machine Learning https://www.youtube.com/playlist?list=PLE-8p-CwnFPuOjFcbnXLFvSQaHFK3ymUW 16. Sklearn Scikit Learn Machine Learning https://www.youtube.com/playlist?list=PLE-8p-CwnFPtAGb29r8F7up9ilZUXt3l1 17. Linear Regression, Supervised Machine Learning https://www.youtube.com/playlist?list=PLE-8p-CwnFPslDi6sfFbFK4KXcVlLwaOM 18 Interiew Questions on Machine Learning, Artificial Intelligence, Python Pandas and Python Basics https://www.youtube.com/playlist?list=PLE-8p-CwnFPt7VBhcnh82y0autSzuOrZp 19. Jupyter Notebook Operations https://www.youtube.com/playlist?list=PLE-8p-CwnFPtqkFd67OZcoSv4BAI7ez5_

Download

1 formats

Video Formats

360pmp44.9 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

KFold Cross Validation using Scikit Learn | Best Model | KFold from sklearn.model_selection | NatokHD