From fb42b17ddc73659e7c7798971b0b6d95b3f5bfa4 Mon Sep 17 00:00:00 2001 From: vinitrg Date: Sat, 24 Mar 2018 14:47:36 +0530 Subject: [PATCH 1/5] Completing Machine Learning Precourse work --- __pycache__/precourse.cpython-36.pyc | Bin 0 -> 2515 bytes precourse.py | 69 +++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 __pycache__/precourse.cpython-36.pyc diff --git a/__pycache__/precourse.cpython-36.pyc b/__pycache__/precourse.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e2bef5339dd51c7270dcc9f311e090add7641567 GIT binary patch literal 2515 zcmb_eOK%%h6u$S)jO{pa;yjv1(}#fyVO|l5kSahGY1#!6jgSgT8G$UmxJ-JqMGb-G2jLFY+67R|;PG!nZV){s8~ z%|zQl3*SW-i9?B|#`4e@smP2)EMv7I#*#;4xhi6{4vWSL+|=$FGiX|g@&eoHx?a~$ ztZvV5N4DVvVPa{2;8D{^%*$DE{`@u<4B}co*?Z`cLW?55KS;$$br$IZCXZV=1VW}|{3}Ps{C^AKPBNg0~ zx}1;G1zp87k=+H5Fm;U7HH=@1ul_H-Mz^(jt-zV}{|9IGV5)H)gG^&mu~-r-thuq9 zN;tEy`6BfpW@{B^as!yz{NJNNd8bi6;RH++No3C(=L9On3f&2Wcb7#A+;BJ9? zYx7otKZoKKwP%B0#DD9x0{=zkpN1L(cI`O^?qRYokogG37)aopf2QusVm9}{_!Wg~+lOUY_>q7@GMcd!_8)Bxp`vy^OAD z=@lMxn&sL*9z4y^w8lHB>KFP?PxS9OVfYUApErOr>O9H}gYzi7g$c=#9InO!{;rP{ zS0Pf10L4fiRrk_5#j(jC!pPS%=$a}q`|aq!Hp3$wHH}nbdoDa0w6#O31+v&I+d6f$9~Rtm z;Ug1Lx9;Ll4qS%8%gUI;*<6O{d(PD&KK!^K;`Wsy7^M6HuojOqoZWLqha-*)6cvg_88(?s$|1x2l+XZ27u&^Sy+1?#K@C&+= z1vZeuO>zxD-xJ=Orij$Ds=h15$dKZ+N{ZLN<|i8~-y2Var=H|DC$1TplbZ%^!aL_T zvHtwcSj8ra$WM@*KB!!HBZG{w{6P{s+1yS2t6ztLr(0hhI1TcnMt{(Y+@R-n@bLLw z!wnlARs%l_-KRaL;d+he0E?Y==m47r?j}}v&<>oW`k6=0@S)bePNp6XJ5InH5(8YD zmR$xyv^(6+2lwsTWM#+i;btP8eC59Ozr#ww_32|dmz{4-G(360-sKu0q(W(`%jKM^ zikwlpiJj(xz5$Y0-k=|xr0QP0JDT%Aa}C%0wrG9;G*{`g%4x0?Df%?SLvuhi=alAH nr`!t~USwkBlfF-bo^y}?CWH-i6 Date: Sat, 24 Mar 2018 15:30:36 +0530 Subject: [PATCH 2/5] formatting changes and cleaning up --- __pycache__/.DS_Store | Bin 0 -> 6148 bytes __pycache__/precourse.cpython-36.pyc | Bin 2515 -> 0 bytes precourse.py | 88 ++++++++++++++------------- 3 files changed, 45 insertions(+), 43 deletions(-) create mode 100644 __pycache__/.DS_Store delete mode 100644 __pycache__/precourse.cpython-36.pyc diff --git a/__pycache__/.DS_Store b/__pycache__/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0mxJ-JqMGb-G2jLFY+67R|;PG!nZV){s8~ z%|zQl3*SW-i9?B|#`4e@smP2)EMv7I#*#;4xhi6{4vWSL+|=$FGiX|g@&eoHx?a~$ ztZvV5N4DVvVPa{2;8D{^%*$DE{`@u<4B}co*?Z`cLW?55KS;$$br$IZCXZV=1VW}|{3}Ps{C^AKPBNg0~ zx}1;G1zp87k=+H5Fm;U7HH=@1ul_H-Mz^(jt-zV}{|9IGV5)H)gG^&mu~-r-thuq9 zN;tEy`6BfpW@{B^as!yz{NJNNd8bi6;RH++No3C(=L9On3f&2Wcb7#A+;BJ9? zYx7otKZoKKwP%B0#DD9x0{=zkpN1L(cI`O^?qRYokogG37)aopf2QusVm9}{_!Wg~+lOUY_>q7@GMcd!_8)Bxp`vy^OAD z=@lMxn&sL*9z4y^w8lHB>KFP?PxS9OVfYUApErOr>O9H}gYzi7g$c=#9InO!{;rP{ zS0Pf10L4fiRrk_5#j(jC!pPS%=$a}q`|aq!Hp3$wHH}nbdoDa0w6#O31+v&I+d6f$9~Rtm z;Ug1Lx9;Ll4qS%8%gUI;*<6O{d(PD&KK!^K;`Wsy7^M6HuojOqoZWLqha-*)6cvg_88(?s$|1x2l+XZ27u&^Sy+1?#K@C&+= z1vZeuO>zxD-xJ=Orij$Ds=h15$dKZ+N{ZLN<|i8~-y2Var=H|DC$1TplbZ%^!aL_T zvHtwcSj8ra$WM@*KB!!HBZG{w{6P{s+1yS2t6ztLr(0hhI1TcnMt{(Y+@R-n@bLLw z!wnlARs%l_-KRaL;d+he0E?Y==m47r?j}}v&<>oW`k6=0@S)bePNp6XJ5InH5(8YD zmR$xyv^(6+2lwsTWM#+i;btP8eC59Ozr#ww_32|dmz{4-G(360-sKu0q(W(`%jKM^ zikwlpiJj(xz5$Y0-k=|xr0QP0JDT%Aa}C%0wrG9;G*{`g%4x0?Df%?SLvuhi=alAH nr`!t~USwkBlfF-bo^y}?CWH-i6 Date: Sat, 24 Mar 2018 15:34:53 +0530 Subject: [PATCH 3/5] reducing value of epsilion to take care of the tests --- precourse.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/precourse.py b/precourse.py index 2611592..fe29478 100644 --- a/precourse.py +++ b/precourse.py @@ -12,7 +12,7 @@ import numpy as np def derivative(func, x): - epsilon = math.e**-10 + epsilon = math.e**-18 return round((func(x+epsilon)-func(x))/epsilon, 3) def f(x): @@ -33,6 +33,7 @@ def d_f_2(x): def d_f_3(x): return derivative(f_3, x) +print(d_f_2(5)) def vector_sum(vectA, vectB): vectorAdd = [] if(len(vectA) == len(vectB)): From 3e324ef6e377ba62009ef5ad70947e45dd9d8fa6 Mon Sep 17 00:00:00 2001 From: vinitrg Date: Sat, 24 Mar 2018 15:38:43 +0530 Subject: [PATCH 4/5] removing unrequired line --- precourse.py | 1 - 1 file changed, 1 deletion(-) diff --git a/precourse.py b/precourse.py index fe29478..ed1e67e 100644 --- a/precourse.py +++ b/precourse.py @@ -33,7 +33,6 @@ def d_f_2(x): def d_f_3(x): return derivative(f_3, x) -print(d_f_2(5)) def vector_sum(vectA, vectB): vectorAdd = [] if(len(vectA) == len(vectB)): From 0fd3280c2a488f6696421ad9c2f5c525179192ff Mon Sep 17 00:00:00 2001 From: Vinit Date: Sat, 5 May 2018 21:41:55 +0530 Subject: [PATCH 5/5] Created using Colaboratory --- High_Dimensionality_Sprint_Challenge.ipynb | 170 +++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 High_Dimensionality_Sprint_Challenge.ipynb diff --git a/High_Dimensionality_Sprint_Challenge.ipynb b/High_Dimensionality_Sprint_Challenge.ipynb new file mode 100644 index 0000000..543d24e --- /dev/null +++ b/High_Dimensionality_Sprint_Challenge.ipynb @@ -0,0 +1,170 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "High Dimensionality Sprint Challenge.ipynb", + "version": "0.3.2", + "provenance": [], + "collapsed_sections": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "[View in Colaboratory](https://colab.research.google.com/github/vinitrg/ML-Precourse/blob/master/High_Dimensionality_Sprint_Challenge.ipynb)" + ] + }, + { + "metadata": { + "id": "8dtL-3V557G6", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "# High Dimensionality Sprint Challenge\n", + "\n", + "High Dimensionality is characterized by the _Curse of Dimensionality_. Humans can visualize 2d and 3d, but not anything higher. How do we reason about data?\n", + "\n", + "High Dimensionality Objectives include:\n", + "* Normalize a vector into a magnitude and unit vector\n", + "* Compute L1 and L2 distances of a pair of vectors\n", + "* Compute the distance between pairs of vectors and select the smallest" + ] + }, + { + "metadata": { + "id": "PMajVGoY54DR", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "# LAMBDA SCHOOL\n", + "#\n", + "# MACHINE LEARNING\n", + "#\n", + "# MIT LICENSE\n", + "\n", + "import numpy as np" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "YUo0Gg2UbieJ", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "# 1. Normalize a vector into magnitude and unit vector" + ] + }, + { + "metadata": { + "id": "RuZFC7k8bnRu", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "v = np.array([17,7,5,2,1])\n", + "\n", + "# m = Magnitude of v\n", + "m = None\n", + "\n", + "# v_u = unit vector of v such that m * v_u = v\n", + "v_u = None" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "sgNZ1QDCdErt", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "# 2. Compute the L1 and L2 distances of a pair of vectors\n", + "\n", + "Recall that the L1 distance is the \"manhattan\" distance, the sum of absolute values of a vector:\n", + "\n", + "$d_{v}^{L1} = \\sum{|v_i|}$\n", + "\n", + "The L2 distance or \"euclidean\" distance is the square root of the sum of the squares of a vector:\n", + "\n", + "$d_{v}^{L2} = \\sqrt{\\sum{v_i^2}}$" + ] + }, + { + "metadata": { + "id": "d__wWc1CdSv7", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "a = np.array([1,2,0,1,2,0,1,2])\n", + "b = np.array([9,2,4,1,1,5,0,2])\n", + "\n", + "# l1 = the L1 distance between a and b\n", + "l1 = None\n", + "\n", + "# l1 = the L2 distance between a and b\n", + "l2 = None" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "mlKMlSmreNvk", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "# 3. Compute the distance between pairs of vectors and select the smallest\n", + "\n", + "For this sprint challenge goal, you are _NOT_ required to compute the pairwise distance of every point in a set. Instead, find the row $i$ with the shortest distance between $x_i$ and $y_i$, two separate sets of $2d$ points." + ] + }, + { + "metadata": { + "id": "N33-3PgVeIkR", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "x = np.array([[10., 2., 0., 3., -4., 1., -5., 10., 7., 6.],\n", + " [-4., 4., -0., 4., -9., 1., -2., 2., 1., -1.]]).T\n", + "\n", + "y = np.array([[-7., 10., -8., 7., -5., -4., 0., 7., -9., -2.],\n", + " [-7., 2., 4., 7., -5., 10., -2., -2., 1., -2.]]).T\n", + "\n", + "# Your code to find the pair of points at row i with the shortest distance between them \n", + "def get_nearest_pair():\n", + " None\n", + "\n", + "# i\n", + "i = None\n", + "\n", + "# The distance between x_i and y_i\n", + "d = None" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file