{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "### METHOD - 1\n", "##### Train/Test Split\n", "\n", "# We train our model on the Train set and Evaluate on the Test set. \n", "# Typical fractions are 7:3 for train and test respectively.\n", "# Sklearn provides a method: train_test_split(X, Y, test_size=0.3, random_state=10) for this purpose\n", "# random_state is required to reproducing the results.\n", "# Very Fast" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "### METHOD - 2\n", "##### K-Fold Cross Validation\n", "\n", "# We split our dataset into K folds (typical values are 3, 5, 10)\n", "# Algorithm is trained on K-1 folds, where 1 fold is held back and testing happens on that held back fold.\n", "# After running cross-validation you end up with k different performance scores that you can summarize\n", "# using a mean and a standard deviation.\n", "# Sklean provides KFold(n_splits=5, random_state=10) method for this purpose" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "### METHOD - 3\n", "##### Leave One Out Cross Validation\n", "\n", "# We make 1 Fold of our dataset containing all the N datapoints.\n", "# We train our algorithm on N-1 points and predicts tha left out point.\n", "# N different performance scores that you can summarize\n", "# Sklearn provides LeaveOneOut() method for this purpose\n", "# Computationaly intensive" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": true }, "outputs": [], "source": [ "### METHOD - 4\n", "##### Repeated Random Train-Test Splits\n", "\n", "# Inspired by K-fold.\n", "# It's simply METHOD - 1 that is run N number of times with different random seed split of data.\n", "# Sklearn provides ShuffleSplit(n_splits=5, test_size=0.3, random_state=10) for this purpose" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.12" } }, "nbformat": 4, "nbformat_minor": 1 }