Python SDK Colima

70

Click here to load reader

Transcript of Python SDK Colima

Page 1: Python SDK Colima

1

Python

Mario García-Valdez Instituto Tecnológico de Tijuana Viernes 12 de Mayo

¿Otros lenguajes?

Page 2: Python SDK Colima

2

¿Y ese nombre?

Page 3: Python SDK Colima

3

Monty Python and the Holy Grail - 1975

Page 4: Python SDK Colima

4

Guido van Rossum 1991

Page 5: Python SDK Colima

5

Desarrollo a principio de los Noventa

Page 6: Python SDK Colima

6

Enterprise Cliente-Servidor

Escritorio MS-Windows

SQL Programación OO

Page 7: Python SDK Colima

7

¿Algún lenguaje para desarrollar Aplicaciones Web?

1998 - IIS Active Server Pages 2000 - AOL Server - tcl 2003 - asp.net c#

2005 - Django 2005 - Ruby on Rails

Page 8: Python SDK Colima

8

Redes Neuronales Algoritmos Genéticos

Estadística IA

Page 9: Python SDK Colima

9

Page 10: Python SDK Colima

10

Page 11: Python SDK Colima

11

Page 12: Python SDK Colima

12

Page 13: Python SDK Colima

13

Page 14: Python SDK Colima

14

x = 34 - 23 # Comentario y = “Hello” # Otro z = 3.45 if z == 3.45 or y == “Hello”: x = x + 1 y = y + “ World” # Concatenación de cadenas

print x print y

Page 15: Python SDK Colima

15

Page 16: Python SDK Colima

16Funciones de Fábrica

Page 17: Python SDK Colima

17 ¿Otras características?

Page 18: Python SDK Colima

18

Interpretado Dinámico Multi-paradigma Libre .net, Java

Page 19: Python SDK Colima

19

>lista = ['1','2','3']

>lista2 = ['Ana','Tom','Zoe']

>zip(lista,lista2) [('1', 'Ana'), ('2', 'Tom'), ('3', 'Zoe')]

>map(int,lista) [1, 2, 3]

Lectura-Evaluación-Impresión

Page 20: Python SDK Colima

20

Page 21: Python SDK Colima

21

Page 22: Python SDK Colima

22

Desarrollo Hoy

Page 23: Python SDK Colima

23

Page 24: Python SDK Colima

24

Page 25: Python SDK Colima

25

Page 26: Python SDK Colima

26

Cloud Computing

Page 27: Python SDK Colima

27Aplicaciones

Page 28: Python SDK Colima

Intercomunidades Mayo 2016

28

Python y Datos

Existen muchas herramientas en el mercado para realizar este tipo de análisis.

Page 29: Python SDK Colima

Intercomunidades Mayo 2016

29

Bibliotecas Escenciales NumPy

Hay muchas más..

Incluye un tipo de Arreglo multi-dimensional muy eficiente. ndarray

Funciones que se ejecutan para cada elemento del arreglo.

Operaciones con Matrices, Algebra lineal, estadística.

Integración con FORTRAN, C, C++

Page 30: Python SDK Colima

Intercomunidades Mayo 2016

30

Bibliotecas Escenciales pandas

Incluye un tipo de dato tipo tabla de dos dimensiones. DataFrame.

Page 31: Python SDK Colima

Intercomunidades Mayo 2016

31

Bibliotecas Escenciales

matplotlib

Hay muchas más..

Biblioteca para graficar los datos en 2D.

Page 32: Python SDK Colima

Intercomunidades Mayo 2016

32

Bibliotecas Escenciales

IPythonUn shell diseñado para acelerar la exploración interactiva de los datos. También en Web y Qt.

Page 33: Python SDK Colima

Intercomunidades Mayo 2016

33

Bibliotecas Escenciales

scikit-learn

Hay muchas más..

Page 34: Python SDK Colima

Intercomunidades Mayo 2016

34

Distribuciones de Python

Empaquetan muchas bibliotecas y herramientas.

Similar a las distribuciones de GNU/Linux.

Page 35: Python SDK Colima

Intercomunidades Mayo 2016

35

Distribuciones de Python

Empaquetan muchas bibliotecas y herramientas.

Similar a las distribuciones de GNU/Linux.

Page 36: Python SDK Colima

Intercomunidades Mayo 2016

36

Distribuciones de Python

Empaquetan muchas bibliotecas y herramientas.

Similar a las distribuciones de GNU/Linux.

Page 37: Python SDK Colima

DEMO

Page 38: Python SDK Colima

38

Ronald Fischer

Fragmento del conjunto de datos Iris ( 150 Registros)

Page 39: Python SDK Colima

39Aplicaciones

Versicolor

Virginica

Setosa

Page 40: Python SDK Colima

40Bajamos el Dataset de Iris

https://archive.ics.uci.edu/ml/machine-learning-databases/iris/

Page 41: Python SDK Colima

41Bajamos el Dataset de Iris

Page 42: Python SDK Colima

42

$ ipython --pylab

In [1]: iris = open(‘iris.data')

In [2]: for renglon in iris: ...: print renglon ...: 5.1,3.5,1.4,0.2,Iris-setosa

4.9,3.0,1.4,0.2,Iris-setosa

4.7,3.2,1.3,0.2,Iris-setosa

4.6,3.1,1.5,0.2,Iris-setosa

5.0,3.6,1.4,0.2,Iris-setosa

5.4,3.9,1.7,0.4,Iris-setosa

4.6,3.4,1.4,0.3,Iris-setosa

1. Cargamos los datos

Page 43: Python SDK Colima

43

In [3]: iris = open('iris.data')

In [4]: iris_data = [renglon for renglon in iris]

In [5]: iris_data Out[5]: ['5.1,3.5,1.4,0.2,Iris-setosa\n', '4.9,3.0,1.4,0.2,Iris-setosa\n', '4.7,3.2,1.3,0.2,Iris-setosa\n', '4.6,3.1,1.5,0.2,Iris-setosa\n', '5.0,3.6,1.4,0.2,Iris-setosa\n', '6.3,2.5,5.0,1.9,Iris-virginica\n', '6.5,3.0,5.2,2.0,Iris-virginica\n', '6.2,3.4,5.4,2.3,Iris-virginica\n', '5.9,3.0,5.1,1.8,Iris-virginica\n', '\n']

In [6]:

1. Cargamos los datos, Comprensión de Listas

Page 44: Python SDK Colima

44

In [3]: iris = open('iris.data')

In [4]: iris_data = [renglon for renglon in iris]

In [5]: iris_data Out[5]: ['5.1,3.5,1.4,0.2,Iris-setosa\n', '4.9,3.0,1.4,0.2,Iris-setosa\n', '4.7,3.2,1.3,0.2,Iris-setosa\n', '4.6,3.1,1.5,0.2,Iris-setosa\n', '5.0,3.6,1.4,0.2,Iris-setosa\n', '6.3,2.5,5.0,1.9,Iris-virginica\n', '6.5,3.0,5.2,2.0,Iris-virginica\n', '6.2,3.4,5.4,2.3,Iris-virginica\n', '5.9,3.0,5.1,1.8,Iris-virginica\n', '\n']

In [6]:

1. Cargamos los datos, Comprensión de Listas

Ocupamos una matriz, una lista de listas

Page 45: Python SDK Colima

45

In [6]: iris = open('iris.data')

In [7]: iris_data = [renglon.split(',') for renglon in iris]

In [8]: iris_data Out[8]: [['5.1', '3.5', '1.4', '0.2', 'Iris-setosa\n'], ['4.9', '3.0', '1.4', '0.2', 'Iris-setosa\n'], ['4.7', '3.2', '1.3', '0.2', 'Iris-setosa\n'], ['4.6', '3.1', '1.5', '0.2', 'Iris-setosa\n'], ['5.0', '3.6', '1.4', '0.2', 'Iris-setosa\n'], ['5.4', '3.9', '1.7', '0.4', 'Iris-setosa\n'], ['4.6', '3.4', '1.4', '0.3', ‘Iris-setosa\n'], ['6.5', '3.0', '5.2', '2.0', 'Iris-virginica\n'], ['6.2', '3.4', '5.4', '2.3', 'Iris-virginica\n'], ['5.9', '3.0', '5.1', '1.8', 'Iris-virginica\n'], ['\n']]

In [9]:

1. Cargamos los datos, Comprensión de Listas

Page 46: Python SDK Colima

46

In [6]: iris = open('iris.data')

In [7]: iris_data = [renglon.split(',') for renglon in iris]

In [8]: iris_data Out[8]: [['5.1', '3.5', '1.4', '0.2', 'Iris-setosa\n'], ['4.9', '3.0', '1.4', '0.2', 'Iris-setosa\n'], ['4.7', '3.2', '1.3', '0.2', 'Iris-setosa\n'], ['4.6', '3.1', '1.5', '0.2', 'Iris-setosa\n'], ['5.0', '3.6', '1.4', '0.2', 'Iris-setosa\n'], ['5.4', '3.9', '1.7', '0.4', 'Iris-setosa\n'], ['4.6', '3.4', '1.4', '0.3', ‘Iris-setosa\n'], ['6.5', '3.0', '5.2', '2.0', 'Iris-virginica\n'], ['6.2', '3.4', '5.4', '2.3', 'Iris-virginica\n'], ['5.9', '3.0', '5.1', '1.8', 'Iris-virginica\n'], ['\n']]

In [9]:

1. Cargamos los datos, Comprensión de Listas

Ocupamos la matriz, sin el tipo de flor.

Page 47: Python SDK Colima

47

In [9]: iris = open('iris.data')

In [10]: iris_data = [renglon.split(',')[:4] for renglon in iris]

In [11]: iris_data Out[11]: [['5.1', '3.5', '1.4', '0.2'], ['4.9', '3.0', '1.4', '0.2'], ['4.7', '3.2', '1.3', '0.2'], ['4.6', '3.1', '1.5', '0.2'], ['5.0', '3.6', '1.4', '0.2'], ['5.4', '3.9', '1.7', ‘0.4'], ['6.3', '2.5', '5.0', '1.9'], ['6.5', '3.0', '5.2', '2.0'], ['6.2', '3.4', '5.4', '2.3'], ['5.9', '3.0', '5.1', '1.8'], ['\n']]

In [12]:

1. Cargamos los datos, Comprensión de Listas

Ocupamos que la matriz sea de flotantes y eliminar el último registro.

Page 48: Python SDK Colima

48

In [12]: iris = open('iris.data')

In [13]: iris_data = [map(float, renglon.split(',')[:4]) for renglon in iris if len(renglon) > 4 ]

In [14]: iris_data Out[14]: [[5.1, 3.5, 1.4, 0.2], [4.9, 3.0, 1.4, 0.2], [4.7, 3.2, 1.3, 0.2], [4.6, 3.1, 1.5, 0.2], [5.0, 3.6, 1.4, 0.2], [6.7, 3.0, 5.2, 2.3], [6.3, 2.5, 5.0, 1.9], [6.5, 3.0, 5.2, 2.0], [6.2, 3.4, 5.4, 2.3], [5.9, 3.0, 5.1, 1.8]]

In [15]:

2. Tipo Flotante, Comprensión de Listas

Utilicemos NumPy para manejar mejor la matriz.

Page 49: Python SDK Colima

49

In [21]: iris_array = array(iris_data) In [22]: iris_array[:50,1] Out[22]: array([ 3.5, 3. , 3.2, 3.1, 3.6, 3.9, 3.4, 3.4, 2.9, 3.1, 3.7, 3.4, 3. , 3. , 4. , 4.4, 3.9, 3.5, 3.8, 3.8, 3.4, 3.7, 3.6, 3.3, 3.4, 3. , 3.4, 3.5, 3.4, 3.2, 3.1, 3.4, 4.1, 4.2, 3.1, 3.2, 3.5, 3.1, 3. , 3.4, 3.5, 2.3, 3.2, 3.5, 3.8, 3. , 3.8, 3.2, 3.7, 3.3])

2. Tipo Flotante, NumPy

Page 50: Python SDK Colima

50

In [23]: iris_array Out[23]: array([[ 5.1, 3.5, 1.4, 0.2], [ 4.9, 3. , 1.4, 0.2], [ 4.7, 3.2, 1.3, 0.2], [ 4.6, 3.1, 1.5, 0.2], [ 5. , 3.6, 1.4, 0.2], [ 5.4, 3.9, 1.7, 0.4], [ 4.9, 3.1, 1.5, 0.1], [ 5.4, 3.7, 1.5, 0.2], [ 6.7, 3.3, 5.7, 2.5], [ 6.7, 3. , 5.2, 2.3], [ 6.3, 2.5, 5. , 1.9], [ 6.5, 3. , 5.2, 2. ], [ 6.2, 3.4, 5.4, 2.3], [ 5.9, 3. , 5.1, 1.8]])

In [24]:

2. Tipo Flotante, NumPy

iris_array[<renglones>, <columna>]

Page 51: Python SDK Colima

51

In [23]: iris_array Out[23]: array([[ 5.1, 3.5, 1.4, 0.2], [ 4.9, 3. , 1.4, 0.2], [ 4.7, 3.2, 1.3, 0.2], [ 4.6, 3.1, 1.5, 0.2], [ 5. , 3.6, 1.4, 0.2], [ 5.4, 3.9, 1.7, 0.4], [ 4.9, 3.1, 1.5, 0.1], [ 5.4, 3.7, 1.5, 0.2], [ 6.7, 3.3, 5.7, 2.5], [ 6.7, 3. , 5.2, 2.3], [ 6.3, 2.5, 5. , 1.9], [ 6.5, 3. , 5.2, 2. ], [ 6.2, 3.4, 5.4, 2.3], [ 5.9, 3. , 5.1, 1.8]])

In [24]:

2. Tipo Flotante, NumPy

iris_array[0:5, 1:3]

Page 52: Python SDK Colima

52

In [23]: iris_array Out[23]: array([[ 5.1, 3.5, 1.4, 0.2], [ 4.9, 3. , 1.4, 0.2], [ 4.7, 3.2, 1.3, 0.2], [ 4.6, 3.1, 1.5, 0.2], [ 5. , 3.6, 1.4, 0.2], [ 5.4, 3.9, 1.7, 0.4], [ 4.9, 3.1, 1.5, 0.1], [ 5.4, 3.7, 1.5, 0.2], [ 6.7, 3.3, 5.7, 2.5], [ 6.7, 3. , 5.2, 2.3], [ 6.3, 2.5, 5. , 1.9], [ 6.5, 3. , 5.2, 2. ], [ 6.2, 3.4, 5.4, 2.3], [ 5.9, 3. , 5.1, 1.8]])

In [24]:

3. matplotlib

Vamos a graficar las dos variables.

Page 53: Python SDK Colima

53

In [24]: x = iris_array[0:50,0]

In [25]: y = iris_array[0:50,1]

In [26]: plot(x, y, 'b.') Out[26]: [<matplotlib.lines.Line2D at 0x10e780d10>]

3. matplotlib

Page 54: Python SDK Colima

54

In [24]: x = iris_array[0:50,0]

In [25]: y = iris_array[0:50,1]

In [26]: plot(x, y, 'b.') Out[26]: [<matplotlib.lines.Line2D at 0x10e780d10>]

3. matplotlib

Page 55: Python SDK Colima

55

In [30]: plot(iris_array[51:100,0], iris_array[51:100,1], 'r.') Out[30]: [<matplotlib.lines.Line2D at 0x11644bcd0>]

3. matplotlib

Page 56: Python SDK Colima

56

In [30]: plot(iris_array[51:100,0], iris_array[51:100,1], 'r.') Out[30]: [<matplotlib.lines.Line2D at 0x11644bcd0>]

3. matplotlib

Page 57: Python SDK Colima

57

In [31]: plot(iris_array[101:,0], iris_array[101:,1], 'g^')

3. matplotlib

Page 58: Python SDK Colima

58

Page 59: Python SDK Colima

593. pandas

In [32]: import pandas as pd

In [33]: iris_df = pd.read_csv(‘iris.data’)

In [34]: iris_df[:4] Out[34]: 5.1 3.5 1.4 0.2 Iris-setosa 0 4.9 3.0 1.4 0.2 Iris-setosa 1 4.7 3.2 1.3 0.2 Iris-setosa 2 4.6 3.1 1.5 0.2 Iris-setosa 3 5.0 3.6 1.4 0.2 Iris-setosa

In [35]:

Page 60: Python SDK Colima

603. pandas

In [39]: iris_df = pd.read_csv('iris.data',names=['sl','sw','pl','pw','type'])

In [40]: iris_df[:4] Out[40]: sl sw pl pw type 0 5.1 3.5 1.4 0.2 Iris-setosa 1 4.9 3.0 1.4 0.2 Iris-setosa 2 4.7 3.2 1.3 0.2 Iris-setosa 3 4.6 3.1 1.5 0.2 Iris-setosa

Page 61: Python SDK Colima

613. pandasIn [43]: iris_df['sl'] Out[43]: 0 5.1 1 4.9 2 4.7 3 4.6 4 5.0 5 5.4 6 4.6 7 5.0 8 4.4 9 4.9 10 5.4 11 4.8

147 6.5 148 6.2 149 5.9 Name: sl, dtype: float64

In [44]:

Page 62: Python SDK Colima

623. pandasIn [46]: iris_df[['sl','sw']] Out[46]: sl sw 0 5.1 3.5 1 4.9 3.0 2 4.7 3.2 3 4.6 3.1 4 5.0 3.6 5 5.4 3.9 6 4.6 3.4 7 5.0 3.4 8 4.4 2.9 9 4.9 3.1 10 5.4 3.7

Vamos a graficar las dos variables.

Page 63: Python SDK Colima

633. pandasIn [47]: iris_df[['sl','sw']].plot() Out[47]: <matplotlib.axes._subplots.AxesSubplot at 0x1138ded10>

In [48]:

Page 64: Python SDK Colima

643. pandasIn [47]: iris_df[['sl','sw']].plot() Out[47]: <matplotlib.axes._subplots.AxesSubplot at 0x1138ded10>

In [48]:

Page 65: Python SDK Colima

653. pandasIn [49]: iris_df[['sl','sw']].plot(x='sl',y='sw', kind='scatter') Out[49]: <matplotlib.axes._subplots.AxesSubplot at 0x11e36ca90>

Page 66: Python SDK Colima

663. pandasIn [56]: ax = iris_df[['sl','sw']][:50].plot(kind='scatter', x='sl', y='sw',color='DarkBlue', label='Iris Setosa’);

In [57]: iris_df[['sl','sw']][50:100].plot(kind='scatter', x='sl', y='sw',color='DarkGreen', label='Iris Versicolour',ax=ax);

In [58]: iris_df[['sl','sw']][50:100].plot(kind='scatter', x='sl', y='sw',color='Green', label='Iris Versicolour',ax=ax);

In [59]: iris_df[['sl','sw']][50:100].plot(kind='scatter', x='sl', y='sw',color='Yellow', label='Iris Versicolour',ax=ax);

Page 67: Python SDK Colima

673. pandas

Page 68: Python SDK Colima

Intercomunidades Mayo 2016

68

Libros Recomendados

Page 69: Python SDK Colima

Intercomunidades Mayo 2016

69

¡Sigamos en Contacto!

Mario García ValdezIns5tuto Tecnológico de Tijuana

664-123-7806

github.com/mariosky

[email protected]

@mariogarciav

mgv.mx (próximamente)

/mariogarciaface

t

m

r

vq

Page 70: Python SDK Colima

70Haskell Logo Thought up by Darrin Thompson and produced by Jeff Wheeler - Thompson-Wheeler logo on the haskell wiki

Javascript Rhino - Lisa Williams CC BY 2.0

PERL - Men and camel No known copyright restrictions

TURBO C++ https://upload.wikimedia.org/wikipedia/commons/1/16/Turbo_CPP_Compiler.jpg

CLOJURE https://commons.wikimedia.org/wiki/File:Clojure-icon.png

OCTAVE LOGO https://commons.wikimedia.org/wiki/File:Gnu-octave.png

Julia https://en.wikipedia.org/wiki/Julia_(programming_language)#/media/File:Julia_prog_language.svg

C# https://commons.wikimedia.org/wiki/File:Music_C_sharp.svg

ElePHPant https://www.flickr.com/photos/atomictaco/23708710306

Rust https://pixabay.com/en/bike-cycle-gear-rust-633208/

Node https://pixabay.com/en/node-js-logo-nodejs-javascript-736399/