Python for Data Science, Essential Training Part 1


Course sections: Filter-Group-Sort | Data Visualization | Math Statistics | Web Scraping


5. Basic math and statistics


I. Simple arithmetic 6m 53s
  • array - one-dim container for elements of same data type.

  • matrix - two-dim container for elements stored in an array.


II. Basic linear algebra 6m 17s
  • dot product

    • how much of the force vector is applied in the direction of the motion vector.

    • measure the angle formed by a pair of vectors

    • the position of a vector relative to the coordinate axes

    • simple test to determine whether two vectors meet at a right angle

              | 2 |
  | 1 2 3 | . | 3 | = 1*2 + 2*3 + 3*4 = 20 
              | 4 |
              
  • matrix multiplication

  | a b | . | e f | = | ae + bg af + bh |
  | c d |   | g h |   | ce + dg cf + dh |
  
  | 1 2 | . | 1 2 | = | 1*1 + 1*2 | 2*1 + 2*2 | = | 3  6 |
  | 3 4 |   | 1 2 |   | 1*3 + 1*4 | 2*3 + 2*4 |   | 7 14 |

III. Generating summary statistics 9m 46s

   Two categories of descriptive statistics

  • Statistics that describe the values of observations in a variable.

    • Mean, median, sum, max, min
  • Statistics that describe a variable’s spread

    • Standard deviation, variance, counts, quartiles

   Uses of descriptive statistics

  • Identify outliers

  • Planning data for machine learning

  • Selecting features for machine learning


IV. Summarizing categorical data 12m 25s
  • Involves limited and fixed set of values.

  • Easily grouped data.

  • Described with counts, variable descriptions, groupings.

  • Crosstab - Cross tabulation of 2 or more features, by default shows frequency counts for features.


V. Parametric correlation analysis 15m 15s
  • A method to find correlation between linearly related, continuous, numeric variables.

  • Correlation does not imply causation.

  • Pearson correlation coefficient R:

    • 1=strong positive
    • 0=not correlated
    • -1=strong negative
  • Pearson correlation assumes:

    • Data is normally distributed
    • Continuous numeric variables (not categorical)
    • Variables are linearly related
  • Binomial (assumes 1 of 2 values) or multinomial variables (gear=3,4,5) will not work. These are categorical variables.

    • binomial = ‘. . .’ on graph
    • multinomial =
      • ‘. . .’
      • ‘. . .’ on graph
  • Use Pearson Correlation to uncover linear relationships between variables.

  • Can not use Pearson Correlation to rule out non-linear relationships between variables.


VI. Non-parametric correlation analysis 13m 25s
  • Find correlation between categorical, non-linear, non-normal, distributed variables.

  • Spearman’s rank correlation

    • Works on ordinal variables (numeric vars that can be categorized)
    • Finds R correlation between variable-pairs of ordinals
    • Variable pairs are ranked by strength of correlation
    • R correlation measure -1 to 1 same as Pearson R values
    • Assumes data is not normally distributed
  • Chi-squared tables

    • See if non-linear variables are independent
    • p < 0.05 = reject null hypothesis; variables are correlated
    • p > 0.05 = accept null hypthesis; variables are independent
    • Variables should be categorical or numeric
    • Numeric values are binned

VII. Transforming dataset distributions 9m 54s
  • Scaling and transforming variables.

  • Avoids erroneous or misleading results.

  • Scale it to prepare for machine learning.

  • Two ways to scale data:

    • Normalize it to put obs on a relative scale: value of obs / sum of all obs.
    • Standardize it with zero mean and unit variance
  • Use scikit-learn pre-processor to scale, center, normalize, bin, or impute data.


VIII. Extreme value analysis for outliers 11m 5s
  • Most machine learning methods assume data has been treated for outliers.

  • Detecting outliers can be a data processing task or analytic method.

  • Use it to uncover anomolies in data.

  • Use it in fraud analysis, cyber security, even detection

  • Univariate Method: Tukey boxplots

    • Boxplot whiskers
    • Inter-quartile (IQR) range: difference from upper to lower quartile.
    • Anything above or below 1.5 of inter-quartile range are outliers.
  • Tukey Outlier Method: Tukey Outlier Labeling

    • Determine outliers mathematically
    • a = Q1 - 1.5(IQR)
    • b = Q3 + 1.5(IQR)
    • min value < a = suspected outliers
    • max value > b = suspected outliers

IX. Multivariate analysis for outliers 5m 53s
  • Outliers that appear within combinations of observations of two or more variables

  • Using scatter plot matrices to find outliers