{ "metadata": { "name": "", "signature": "sha256:8ae5115d15090ffb2d912946b2ed9818045b942775e35b7e9492baf167afeb35" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Earlier in my blog, I said that Data Wrangling is not skill that statistician has. Take a lot of process to clean this data. If there's outliers, two thing comes in mind. First is if this an error in the input. If it was input by human, there's maybe human error. Or sensor error if have sensor, or network error. Second, the outliers that really mean outliers. It's just kind of noise that usually the data has. It's up to us to treat the outliers, or ignore it as we want to focus on the data.\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To avoid such outliers, one way is that we can remove directly the outliers. Or we could we some CDF(Cumulative Distribution Function) to automatically remove outliers. The alternative way is plotting which you will see some historgram that show bowl-curve like." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![jpeg](http://upload.wikimedia.org/math/7/3/a/73ad15f79b11af99bd2477ff3ffc5a35.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "One final alternative way is to try to use the Gaussian Distribution, or called Normal Distribution. This function takes 3 things, the data itself, the mean, and the standard deviation of these numbers. Most of the data will split its distribution nicely if we just have these three things.This comes in condition that the distribution of the data follows Normal Distribution. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " std_unit = (data-mean)/std_deviation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can take standard units that take mean and standard deviation as an input, and we can predict the probability of certain number in the dataset.The resulted probability often match the exact result of the data.The best plot to visualize the normal distribution is quantile-quantile plot, or qqplot in R. This would take us to see each percentage deviation of the data. What are the data that are less than 1,2,3 percent deviation from the data. Below are the scipy function which states how many data that are less than 2 standard deviation from the mean." ] }, { "cell_type": "code", "collapsed": false, "input": [ "import scipy.stats\n", "\n", "scipy.stats.norm.cdf(3)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 1, "text": [ "0.9986501019683699" ] } ], "prompt_number": 1 }, { "cell_type": "markdown", "metadata": {}, "source": [ "For two variable, five numbers have to be defined to summarize the distribution. Imagine that we have normal distribution consist of two variables. You can see that all data regress towards the mean. You want to make a prediction on one variable based on another variable. So here's what we should do." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " correlation = (Y-mean(Y))/std_dev(Y) / (X-mean(X))/std_dev(X)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This would give us the correlation of two variables. This correlation range from -1/1 to 0. approach one if approximately matched betweeen two variables, or zero otherwise. This correlation could be performed under one condition, if the 2D data projected to american football-like shape. Statistical overview alone can't described the data. You need to see how are the data distribution in visualization. Below are the famous Anscombe's quartet. You see that the top left graph perform football-shape, but not for the rest." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![png](http://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Anscombe%27s_quartet_3.svg/425px-Anscombe%27s_quartet_3.svg.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Always remember that this assume the data is normally distributed. You might see often that newspapers or published paper make this kind of mistake. And it's really misleading, and potentially dangerous if someone might read your article and doing research based on that." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "> **RESOURCES** :\n", "\n", "> * http://cs109.github.io/2014/pages/lectures/02-distributions.html#/\n", "> * http://en.wikipedia.org/wiki/Normal_distribution\n", "> * http://en.wikipedia.org/wiki/Anscombe%27s_quartet" ] } ], "metadata": {} } ] }