{ "cells": [ { "cell_type": "markdown", "metadata": { "collapsed": true, "deletable": true, "editable": true }, "source": [ "#
Automatic Feature Selection
\n", "\n", "- to reduce dimensionality\n", "- common methods: univariate statistics, model-based selection, iterative selection" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1. Univariate Statistics\n", "\n", "- determines the relationship between each feature and output (target)\n", "- only the features with highest confidence are selected\n", "- SelectKBest - selecting K number of features\n", "- SelectPercentile - selection is made based on a percentage of the original features" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "X_train.shape is: (284, 80)\n", "X_train_selected.shape is: (284, 40)\n" ] } ], "source": [ "import numpy as np\n", "from sklearn.datasets import load_breast_cancer\n", "from sklearn.model_selection import train_test_split\n", "from sklearn.feature_selection import SelectPercentile\n", "\n", "cancer = load_breast_cancer()\n", "\n", "rng = np.random.RandomState(42)\n", "noise = rng.normal(size=(len(cancer.data), 50))\n", "\n", "X_w_noise = np.hstack([cancer.data, noise])\n", "X_train, X_test, y_train, y_test = train_test_split(X_w_noise, cancer.target, random_state=0, test_size=.5)\n", "\n", "select = SelectPercentile(percentile=50)\n", "select.fit(X_train, y_train)\n", "X_train_selected = select.transform(X_train)\n", "\n", "print('X_train.shape is: {}'.format(X_train.shape))\n", "print('X_train_selected.shape is: {}'.format(X_train_selected.shape))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.0" } }, "nbformat": 4, "nbformat_minor": 2 }