Difference between revisions of "Python for Data Science"

From Sinfronteras
Jump to: navigation, search
(NumPy)
(NumPy Arrays)
Line 14: Line 14:
 
<br />
 
<br />
 
===Anaconda comes with a few IDE===
 
===Anaconda comes with a few IDE===
* Jupyter Lab
+
 
* Jupyter Notebook
+
*Jupyter Lab
* Spyder
+
*Jupyter Notebook
* Qtconsole
+
*Spyder
* and others
+
*Qtconsole
 +
*and others
  
  
Line 33: Line 34:
 
Jupyter comes with Anaconda.
 
Jupyter comes with Anaconda.
  
* It is a development environment (IDE) where we can write codes; but it also allows us to display images, and write down markdown notes.
+
*It is a development environment (IDE) where we can write codes; but it also allows us to display images, and write down markdown notes.
  
* It is the most popular IDE in data science for exploring and analyzing data.
+
*It is the most popular IDE in data science for exploring and analyzing data.
  
* Other famoues IDE for Python are Sublime Text and PyCharm.
+
*Other famoues IDE for Python are Sublime Text and PyCharm.
  
* There is '''Jupyter Lab''' and '''Jupyter Notebook'''
+
*There is '''Jupyter Lab''' and '''Jupyter Notebook'''
  
  
Line 47: Line 48:
  
 
I have tried:
 
I have tried:
* https://cocalc.com/app
 
:: https://cocalc.com/projects/595bf475-61a7-47fa-af69-ba804c3f23f9/files/?session=default
 
:: Parece bueno, pero tiene opciones que no son gratis
 
  
 +
*https://cocalc.com/app
 +
 +
::https://cocalc.com/projects/595bf475-61a7-47fa-af69-ba804c3f23f9/files/?session=default
 +
::Parece bueno, pero tiene opciones que no son gratis
 +
 +
 +
*https://www.kaggle.com/
  
* https://www.kaggle.com/
+
::https://www.kaggle.com/adeloaleman/kernel1917a91630/edit
:: https://www.kaggle.com/adeloaleman/kernel1917a91630/edit
+
::Parece bueno pero no encontré la forma adicionar una TOC
:: Parece bueno pero no encontré la forma adicionar una TOC
 
  
  
* https://drive.google.com
+
*https://drive.google.com
:* https://colab.research.google.com
+
 
:: Es el que estoy utilizando ahora
+
:*https://colab.research.google.com
 +
::Es el que estoy utilizando ahora
  
  
Line 69: Line 74:
 
<br />
 
<br />
 
===Most popular Python Data Science Libraries===
 
===Most popular Python Data Science Libraries===
* NumPy
+
 
* SciPy
+
*NumPy
* Pandas
+
*SciPy
* Seaborn
+
*Pandas
* SciKit'Learn
+
*Seaborn
* MatplotLib
+
*SciKit'Learn
* Plotly
+
*MatplotLib
* PySpartk
+
*Plotly
 +
*PySpartk
  
  
 
<br />
 
<br />
 
===NumPy===
 
===NumPy===
* NumPy (or Numpy) is a Linear Algebra Library for Python, the reason it is so important for Data Science with Python is that almost all of the libraries in the PyData Ecosystem rely on NumPy as one of their main building blocks.
 
  
* Numpy is also incredibly fast, as it has bindings to C libraries. For more info on why you would want to use Arrays instead of lists, check out this great [StackOverflow post](http://stackoverflow.com/questions/993984/why-numpy-instead-of-python-lists).
+
*NumPy (or Numpy) is a Linear Algebra Library for Python, the reason it is so important for Data Science with Python is that almost all of the libraries in the PyData Ecosystem rely on NumPy as one of their main building blocks.
 +
 
 +
*Numpy is also incredibly fast, as it has bindings to C libraries. For more info on why you would want to use Arrays instead of lists, check out this great [StackOverflow post](http://stackoverflow.com/questions/993984/why-numpy-instead-of-python-lists).
  
  
Line 90: Line 97:
 
It is highly recommended you install Python using the Anaconda distribution to make sure all underlying dependencies (such as Linear Algebra libraries) all sync up with the use of a conda install.
 
It is highly recommended you install Python using the Anaconda distribution to make sure all underlying dependencies (such as Linear Algebra libraries) all sync up with the use of a conda install.
  
* If you have Anaconda, install NumPy by:
+
*If you have Anaconda, install NumPy by:
 +
 
 
  conda install numpy
 
  conda install numpy
  
* If you are not using Anaconda distribution:  
+
*If you are not using Anaconda distribution:
 +
 
 
  pip install numpy
 
  pip install numpy
 +
{| class="wikitable"
 +
|+
 +
! colspan="2" |
 +
! colspan="2" |Method
 +
!Description
 +
!Example
 +
|-
 +
| rowspan="9" |'''Creating NumPy Arrays'''
 +
|From a Python List
 +
| colspan="2" |'''''array'''''
 +
|We can create an array by directly converting a list or list of lists.
 +
|my_list = [1,2,3]
 +
np.array(my_list)
  
  
<br />
+
my_matrix = [[1,2,3],[4,5,6],[7,8,9]]
====NumPy Arrays====
 
* NumPy arrays are the main way we will use NumPy throughout the course.
 
 
 
* NumPy arrays essentially come in two flavors: vectors and matrices.
 
 
 
* Vectors are strictly 1-d arrays and matrices are 2-d (but you should note a matrix can still have only one row or one column).
 
 
 
  
<br />
 
=====Creating NumPy Arrays=====
 
 
 
<br />
 
======From a Python List======
 
We can create an array by directly converting a list or list of lists:
 
my_list = [1,2,3]
 
np.array(my_list)
 
 
my_matrix = [[1,2,3],[4,5,6],[7,8,9]]
 
 
np.array(my_matrix)
 
np.array(my_matrix)
 
+
|-
 
+
| rowspan="8" |From Built-in Methods
<br />
+
| colspan="2" |'''''arange'''''
======From NumPy Built-in Methods======
+
|Return evenly spaced values within a given interval.
Return evenly spaced values within a given interval.
+
|np.arange(0,10)
 
 
'''arange'''
 
np.arange(0,10)
 
 
np.arange(0,11,2)
 
np.arange(0,11,2)
 
+
|-
 
+
| colspan="2" |'''''zeros'''''
'''zeros and ones''''
+
|Generate arrays of zeros
 
+
|np.zeros(3)
zeros and ones
 
 
 
 
np.zeros((5,5))
 
np.zeros((5,5))
 
+
|-
np.ones(3)
+
| colspan="2" |'''''ones'''''
 +
|Generate arrays of ones
 +
|np.ones(3)
 
np.ones((3,3))
 
np.ones((3,3))
 
+
|-
 
+
| colspan="2" |'''''linspace'''''
'''linspace'''
+
|Return evenly spaced numbers over a specified interval.
 
+
|np.linspace(0,10,3)
Return evenly spaced numbers over a specified interval.
 
 
 
np.linspace(0,10,3)
 
 
 
 
np.linspace(0,10,50)
 
np.linspace(0,10,50)
 
+
|-
 
+
| colspan="2" |'''''eye'''''
'''eye'''
+
|Creates an identity matrix
Creates an identity matrix
+
|np.eye(4)
 
+
|-
np.eye(4)
+
| rowspan="3" |'''''random'''''
 
+
|'''''rand'''''
 
+
|Create an array of the given shape and populate it with random samples from a uniform distribution over <code>[0, 1)</code>.
'''Random'''
+
|np.random.rand(2)
Numpy also has lots of ways to create random number arrays:
+
np.random.rand(5,5)
 
+
|-
rand
+
|'''''randn'''''
 
+
|Return a sample (or samples) from the "standard normal" distribution. Unlike rand which is uniform:
Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1).
+
|np.random.randn(2)
 +
np.random.randn(5,5)
 +
|-
 +
|'''''randint'''''
 +
|Return random integers from <code>low</code> (inclusive) to <code>high</code> (exclusive).
 +
|np.random.randint(1,100)
 +
np.random.randint(1,100,10)
 +
|-
 +
| rowspan="4" |'''Array Attributes and Methods'''
 +
| colspan="3" |''reshape''
 +
|Returns an array containing the same data with a new shape.
 +
|arr.reshape(5,5)
 +
|-
 +
| colspan="3" |''max, min, argmax, argmin''
 +
|Finding max or min values. Or to find their index locations using argmin or argmax
 +
|arr.max()
 +
arr.argmax()
 +
|-
 +
| colspan="3" |''Shape''
 +
|Shape is an attribute that arrays have (not a method):
 +
|NO LO ENTENDI.. REVISAR!
 +
|-
 +
| colspan="3" |''dtype''
 +
|You can also grab the data type of the object in the array:
 +
|arr.dtype
 +
|}

Revision as of 00:00, 16 October 2019

Anaconda

Anaconda is a free and open source distribution of the Python and R programming languages for data science and machine learning related applications (large-scale data processing, predictive analytics, scientific computing), that aims to simplify package management and deployment. Package versions are managed by the package management system conda. https://en.wikipedia.org/wiki/Anaconda_(Python_distribution)

En otras palabras, Anaconda puede ser visto como un paquete (a distribution) que incluye no solo Python (or R) but many libraries that are used in Data Science, as well as its own virtual environment system. It's an "all-in-one" install that is extremely popular in data science and Machine Learning.



Installation

https://linuxize.com/post/how-to-install-anaconda-on-ubuntu-18-04/

https://www.digitalocean.com/community/tutorials/how-to-install-the-anaconda-python-distribution-on-ubuntu-18-04



Anaconda comes with a few IDE

  • Jupyter Lab
  • Jupyter Notebook
  • Spyder
  • Qtconsole
  • and others



Anaconda Navigator

Anaconda Navigator is a GUI that helps you to easily start important applications and manage the packages in your local Anaconda installation

You can open the Anaconda Navigator from the Terminal:

anaconda-navigator



Jupyter

Jupyter comes with Anaconda.

  • It is a development environment (IDE) where we can write codes; but it also allows us to display images, and write down markdown notes.
  • It is the most popular IDE in data science for exploring and analyzing data.
  • Other famoues IDE for Python are Sublime Text and PyCharm.
  • There is Jupyter Lab and Jupyter Notebook



Online Jupyter

There are many sites that provides solutions to run your Jupyter Notebook in the cloud: https://www.dataschool.io/cloud-services-for-jupyter-notebook/

I have tried:

https://cocalc.com/projects/595bf475-61a7-47fa-af69-ba804c3f23f9/files/?session=default
Parece bueno, pero tiene opciones que no son gratis


https://www.kaggle.com/adeloaleman/kernel1917a91630/edit
Parece bueno pero no encontré la forma adicionar una TOC


Es el que estoy utilizando ahora



Udemy - Python for Data Science and Machine Learning Bootcamp

https://www.udemy.com/course/python-for-data-science-and-machine-learning-bootcamp/



Most popular Python Data Science Libraries

  • NumPy
  • SciPy
  • Pandas
  • Seaborn
  • SciKit'Learn
  • MatplotLib
  • Plotly
  • PySpartk



NumPy

  • NumPy (or Numpy) is a Linear Algebra Library for Python, the reason it is so important for Data Science with Python is that almost all of the libraries in the PyData Ecosystem rely on NumPy as one of their main building blocks.



Installation

It is highly recommended you install Python using the Anaconda distribution to make sure all underlying dependencies (such as Linear Algebra libraries) all sync up with the use of a conda install.

  • If you have Anaconda, install NumPy by:
conda install numpy
  • If you are not using Anaconda distribution:
pip install numpy
Method Description Example
Creating NumPy Arrays From a Python List array We can create an array by directly converting a list or list of lists. my_list = [1,2,3]

np.array(my_list)


my_matrix = [[1,2,3],[4,5,6],[7,8,9]]

np.array(my_matrix)

From Built-in Methods arange Return evenly spaced values within a given interval. np.arange(0,10)

np.arange(0,11,2)

zeros Generate arrays of zeros np.zeros(3)

np.zeros((5,5))

ones Generate arrays of ones np.ones(3)

np.ones((3,3))

linspace Return evenly spaced numbers over a specified interval. np.linspace(0,10,3)

np.linspace(0,10,50)

eye Creates an identity matrix np.eye(4)
random rand Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1). np.random.rand(2)

np.random.rand(5,5)

randn Return a sample (or samples) from the "standard normal" distribution. Unlike rand which is uniform: np.random.randn(2)

np.random.randn(5,5)

randint Return random integers from low (inclusive) to high (exclusive). np.random.randint(1,100)

np.random.randint(1,100,10)

Array Attributes and Methods reshape Returns an array containing the same data with a new shape. arr.reshape(5,5)
max, min, argmax, argmin Finding max or min values. Or to find their index locations using argmin or argmax arr.max()

arr.argmax()

Shape Shape is an attribute that arrays have (not a method): NO LO ENTENDI.. REVISAR!
dtype You can also grab the data type of the object in the array: arr.dtype