{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Introduction to Machine Learning" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## What is Machine Learning?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Why use Machine Learning?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Types of Machine Learning " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* Supervised \n", "* Unsupervised \n", "* Reinforcement" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Challenges of Machine Learning" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* Insufficient training data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Python landscape for ML" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* numpy, pandas, scikit-learn\n", "* tensorflow, keras, pyTorch, theano\n", "* matplotlib, seaborn, bokeh" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Different ML problems" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* Classification problems\n", "* Regression problems" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Survey of different ML techniques" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* Linear Regression\n", "* Logistic Regression\n", "* Support Vector Machines\n", "* Decision Trees\n", "* Random Forests" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "import scipy as sp\n", "from scipy import linalg\n", "from sklearn import datasets\n", "import matplotlib.pyplot as plt\n", "import sklearn" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "''' A brief walk through numpy '''\n", "\n", "A = np.array([ [3.4, 8.7, 9.9], \n", " [1.1, -7.8, -0.7],\n", " [4.1, 12.3, 4.8]])" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[[ 3.4 8.7 9.9]\n", " [ 1.1 -7.8 -0.7]\n", " [ 4.1 12.3 4.8]]\n" ] } ], "source": [ "print(A)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2\n" ] } ], "source": [ "print(A.ndim)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(3, 3)\n" ] } ], "source": [ "print(A.shape)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-0.7\n" ] } ], "source": [ "print(A[1,2]) # Row major order! Row #1, Col #2" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "B = np.array([ [2.4, 3.1, 9.3, -6], \n", " [-2.6, -3.9, -4, -5.5],\n", " [8.0, 10.2, 4.8, -3.7]])" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[[ 2.4 3.1 9.3 -6. ]\n", " [ -2.6 -3.9 -4. -5.5]\n", " [ 8. 10.2 4.8 -3.7]]\n", "(3, 4)\n" ] } ], "source": [ "print(B)\n", "print(B.shape)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[ 1.1, -7.8],\n", " [ 4.1, 12.3]])" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "''' Slicing '''\n", "\n", "A\n", "A2 = A[1:, :2]\n", "A2" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "A2[0,0] = 1 #This IS in place" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[ 3.4, 8.7, 9.9],\n", " [ 1. , -7.8, -0.7],\n", " [ 4.1, 12.3, 4.8]])" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "''' Stacking '''\n", "\n", "A = np.zeros((180,360,24))" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "3\n" ] } ], "source": [ "print(A.ndim)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(180, 360, 24)\n" ] } ], "source": [ "print(A.shape)" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[[ 0.46206624 0.06755037 0.72720084 ..., 0.34104538 0.76289446\n", " 0.97067944]\n", " [ 0.32427144 0.24102564 0.90328949 ..., 0.61834409 0.7004352\n", " 0.69377703]\n", " [ 0.54168443 0.60957642 0.57037668 ..., 0.96382855 0.47777453\n", " 0.81250677]\n", " ..., \n", " [ 0.01695183 0.69306794 0.96613347 ..., 0.82129488 0.43480485\n", " 0.48263207]\n", " [ 0.17144527 0.11280653 0.32520081 ..., 0.39631619 0.75231207\n", " 0.03152241]\n", " [ 0.45724994 0.69790812 0.74570642 ..., 0.06345951 0.71458058\n", " 0.36054009]]\n" ] } ], "source": [ "A[:,:,0] = np.random.rand(180,360)\n", "print(A[:,:,0])" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "''' Equality '''\n", "\n", "5 == 5 #this is familiar" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "[5, 3, 9] == [5, 3, 9] #still ok" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "[[], [5, 3, 9]] == [[], [5, 3, 9]] #weird but alright" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ True, True, True], dtype=bool)" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.array([5, 3, 9]) == np.array([5, 3, 9]) # returns array of booleans" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ True, True, True], dtype=bool)" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.equal(np.array([5, 3, 9]), np.array([5, 3, 9])) # returns array of booleans" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.array_equal(np.array([5, 3, 9]), np.array([5, 3, 9])) # returns boolean" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | first | \n", "second | \n", "
---|---|---|
0 | \n", "1 | \n", "2 | \n", "
1 | \n", "3 | \n", "4 | \n", "