SlideShare a Scribd company logo
Python Numpy/Pandas Libraries
Machine Learning
Portland Data Science Group
Created by Andrew Ferlitsch
Community Outreach Officer
July, 2017
Libraries - Numpy
• A popular math library in Python for Machine Learning
is ‘numpy’.
import numpy as np
Keyword to import a library Keyword to refer to library by an alias (shortcut) name
Numpy.org : NumPy is the fundamental package for scientific computing with Python.
• a powerful N-dimensional array object
• sophisticated (broadcasting) functions
• tools for integrating C/C++ and Fortran code
• useful linear algebra, Fourier transform, and random number capabilities
Libraries - Numpy
The most import data structure for scientific computing in Python
is the NumPy array. NumPy arrays are used to store lists of numerical
data and to represent vectors, matrices, and even tensors.
NumPy arrays are designed to handle large data sets efficiently and
with a minimum of fuss. The NumPy library has a large set of routines
for creating, manipulating, and transforming NumPy arrays.
Core Python has an array data structure, but it’s not nearly as versatile,
efficient, or useful as the NumPy array.
http://www.physics.nyu.edu/pine/pymanual/html/chap3/chap3_arrays.html
Numpy – Multidimensional Arrays
• Numpy’s main object is a multi-dimensional array.
• Creating a Numpy Array as a Vector:
data = np.array( [ 1, 2, 3 ] )
Numpy function to create a numpy array
Value is: array( [ 1, 2, 3 ] )
• Creating a Numpy Array as a Matrix:
data = np.array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] )
Outer Dimension Inner Dimension (rows)
Value is: array( [ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ] )
Numpy – Multidimensional Arrays
• Creating an array of Zeros:
data = np.zeros( ( 2, 3 ), dtype=np.int )
Numpy function to create an array of zeros
Value is: array( [ 0, 0, 0 ],
[ 0, 0, 0 ] )
• Creating an array of Ones:
data = np.ones( (2, 3), dtype=np.int )
rows
columns
data type (default is float)
Numpy function to create an array of onesValue is: array( [ 1, 1, 1 ],
[ 1, 1, 1 ] )
And many more functions: size, ndim, reshape, arange, …
Libraries - Pandas
• A popular library for importing and managing datasets in Python
for Machine Learning is ‘pandas’.
import pandas as pd
Keyword to import a library Keyword to refer to library by an alias (shortcut) name
PyData.org : high-performance, easy-to-use data structures and data analysis tools for the
Python programming language.
Used for:
• Data Analysis
• Data Manipulation
• Data Visualization
Pandas – Indexed Arrays
• Pandas are used to build indexed arrays (1D) and matrices (2D),
where columns and rows are labeled (named) and can be accessed
via the labels (names).
1 2 3 4
4 5 6 7
8 9 10 11
1 2 3 4
4 5 6 7
8 9 10 11
one
two
three
x1 x2 x3 x4
raw data
Row (samples)
index
Columns (features)
index
Panda Indexed Matrix
Pandas – Series and Data Frames
• Pandas Indexed Arrays are referred to as Series (1D) and
Data Frames (2D).
• Series is a 1D labeled (indexed) array and can hold any data type,
and mix of data types.
s = pd.Series( data, index=[ ‘x1’, ‘x2’, ‘x3’, ‘x4’ ] )
Series Raw data Column Index Labels
• Data Frame is a 2D labeled (indexed) matrix and can hold any
data type, and mix of data types.
df = pd.DataFrame( data, index=[‘one’, ‘two’], columns=[ ‘x1’, ‘x2’, ‘x3’, ‘x4’ ] )
Data Frame Row Index Labels Column Index Labels
Pandas – Selecting
• Selecting One Column
x1 = df[ ‘x1’ ]
Selects column labeled x1 for all rows
1
4
8
• Selecting Multiple Columns
x1 = df[ [ ‘x1’, ‘x3’ ] ]
Selects columns labeled x1 and x3 for all rows
1 3
4 6
8 10
x1 = df.ix[ :, ‘x1’:’x3’ ]
Selects columns labeled x1 through x3 for all rows
1 2 3
4 5 6
8 9 10
Note: df[‘x1’:’x3’ ] this python syntax does not work!
rows (all) columns
Slicing function
And many more functions: merge, concat, stack, …
Libraries - Matplotlib
• A popular library for plotting and visualizing data in Python
import matplotlib.pyplot as plt
Keyword to import a library Keyword to refer to library by an alias (shortcut) name
matplotlib.org: Matplotlib is a Python 2D plotting library which produces publication quality
figures in a variety of hardcopy formats and interactive environments across platforms.
Used for:
• Plots
• Histograms
• Bar Charts
• Scatter Plots
• etc
Matplotlib - Plot
• The function plot plots a 2D graph.
plt.plot( x, y )
Function to plot
X values to plot
Y values to plot
• Example:
plt.plot( [ 1, 2, 3 ], [ 4, 6, 8 ] ) # Draws plot in the background
plt.show() # Displays the plot
X Y
1
2
4
6
8
2 3
Matplotlib – Plot Labels
• Add Labels for X and Y Axis and Plot Title (caption)
plt.plot( [ 1, 2, 3 ], [ 4, 6, 8 ] )
plt.xlabel( “X Numbers” ) # Label on the X-axis
plt.ylabel( “Y Numbers” ) # Label on the Y-axis
plt.title( “My Plot of X and Y”) # Title for the Plot
plt.show()
1
2
4
6
8
2 3
X Numbers
YNumbers
My Plot of X and Y
Matplotlib – Multiple Plots and Legend
• You can add multiple plots in a Graph
plt.plot( [ 1, 2, 3 ], [ 4, 6, 8 ], label=‘ 1st Line’ ) # Plot for 1st Line
plt.plot( [ 1, 2, 3 ], [ 2, 4, 6 ], label=‘2nd Line’ ) # Plot for 2nd Line
plt.xlabel( “X Numbers” )
plt.ylabel( “Y Numbers” )
plt.title( “My Plot of X and Y”)
plt.legend() # Show Legend for the plots
plt.show()
1
2
4
6
8
2 3
X Numbers
YNumbers
My Plot of X and Y
---- 1st Line
---- 2nd Line
Matplotlib – Bar Chart
• The function bar plots a bar graph.
plt.plot( [ 1, 2, 3 ], [ 4, 6, 8 ] ) # Plot for 1st Line
plt.bar() # Draw a bar chart
plt.show()
1
2
4
6
8
2 3
And many more functions: hist, scatter, …
Ad

More Related Content

What's hot (20)

Python Scipy Numpy
Python Scipy NumpyPython Scipy Numpy
Python Scipy Numpy
Girish Khanzode
 
Python Seaborn Data Visualization
Python Seaborn Data Visualization Python Seaborn Data Visualization
Python Seaborn Data Visualization
Sourabh Sahu
 
Data visualization in Python
Data visualization in PythonData visualization in Python
Data visualization in Python
Marc Garcia
 
pandas - Python Data Analysis
pandas - Python Data Analysispandas - Python Data Analysis
pandas - Python Data Analysis
Andrew Henshaw
 
Pandas
PandasPandas
Pandas
maikroeder
 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)
PyData
 
Introduction to numpy Session 1
Introduction to numpy Session 1Introduction to numpy Session 1
Introduction to numpy Session 1
Jatin Miglani
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
Matt Harrison
 
Python : Data Types
Python : Data TypesPython : Data Types
Python : Data Types
Emertxe Information Technologies Pvt Ltd
 
Introduction to pandas
Introduction to pandasIntroduction to pandas
Introduction to pandas
Piyush rai
 
Python For Data Science Cheat Sheet
Python For Data Science Cheat SheetPython For Data Science Cheat Sheet
Python For Data Science Cheat Sheet
Karlijn Willems
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
Pedro Rodrigues
 
Data Visualization in Python
Data Visualization in PythonData Visualization in Python
Data Visualization in Python
Jagriti Goswami
 
8 python data structure-1
8 python data structure-18 python data structure-1
8 python data structure-1
Prof. Dr. K. Adisesha
 
Arrays
ArraysArrays
Arrays
Trupti Agrawal
 
Function in Python
Function in PythonFunction in Python
Function in Python
Yashdev Hada
 
PPT on Data Science Using Python
PPT on Data Science Using PythonPPT on Data Science Using Python
PPT on Data Science Using Python
NishantKumar1179
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)
Paige Bailey
 
Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming Language
Tahani Al-Manie
 
Visualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptxVisualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptx
SharmilaMore5
 
Python Seaborn Data Visualization
Python Seaborn Data Visualization Python Seaborn Data Visualization
Python Seaborn Data Visualization
Sourabh Sahu
 
Data visualization in Python
Data visualization in PythonData visualization in Python
Data visualization in Python
Marc Garcia
 
pandas - Python Data Analysis
pandas - Python Data Analysispandas - Python Data Analysis
pandas - Python Data Analysis
Andrew Henshaw
 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)
PyData
 
Introduction to numpy Session 1
Introduction to numpy Session 1Introduction to numpy Session 1
Introduction to numpy Session 1
Jatin Miglani
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
Matt Harrison
 
Introduction to pandas
Introduction to pandasIntroduction to pandas
Introduction to pandas
Piyush rai
 
Python For Data Science Cheat Sheet
Python For Data Science Cheat SheetPython For Data Science Cheat Sheet
Python For Data Science Cheat Sheet
Karlijn Willems
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
Pedro Rodrigues
 
Data Visualization in Python
Data Visualization in PythonData Visualization in Python
Data Visualization in Python
Jagriti Goswami
 
Function in Python
Function in PythonFunction in Python
Function in Python
Yashdev Hada
 
PPT on Data Science Using Python
PPT on Data Science Using PythonPPT on Data Science Using Python
PPT on Data Science Using Python
NishantKumar1179
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)
Paige Bailey
 
Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming Language
Tahani Al-Manie
 
Visualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptxVisualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptx
SharmilaMore5
 

Similar to Python - Numpy/Pandas/Matplot Machine Learning Libraries (20)

python-numpyandpandas-170922144956 (1).pptx
python-numpyandpandas-170922144956 (1).pptxpython-numpyandpandas-170922144956 (1).pptx
python-numpyandpandas-170922144956 (1).pptx
Akashgupta517936
 
Numpy.pdf
Numpy.pdfNumpy.pdf
Numpy.pdf
Arvind Pathak
 
Chapter 5-Numpy-Pandas.pptx python programming
Chapter 5-Numpy-Pandas.pptx python programmingChapter 5-Numpy-Pandas.pptx python programming
Chapter 5-Numpy-Pandas.pptx python programming
ssuser77162c
 
NumPy.pptx
NumPy.pptxNumPy.pptx
NumPy.pptx
DrJasmineBeulahG
 
Introduction to a Python Libraries and python frameworks
Introduction to a Python Libraries and python frameworksIntroduction to a Python Libraries and python frameworks
Introduction to a Python Libraries and python frameworks
yokeshmca
 
Python crash course libraries numpy-1, panda.ppt
Python crash course libraries numpy-1, panda.pptPython crash course libraries numpy-1, panda.ppt
Python crash course libraries numpy-1, panda.ppt
janaki raman
 
Python Interview Questions PDF By ScholarHat
Python Interview Questions PDF By ScholarHatPython Interview Questions PDF By ScholarHat
Python Interview Questions PDF By ScholarHat
Scholarhat
 
getting started with numpy and pandas.pptx
getting started with numpy and pandas.pptxgetting started with numpy and pandas.pptx
getting started with numpy and pandas.pptx
workvishalkumarmahat
 
Unit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptxUnit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptx
prakashvs7
 
Unit 3_Numpy_VP.pptx
Unit 3_Numpy_VP.pptxUnit 3_Numpy_VP.pptx
Unit 3_Numpy_VP.pptx
vishnupriyapm4
 
object oriented programing in python and pip
object oriented programing in python and pipobject oriented programing in python and pip
object oriented programing in python and pip
LakshmiMarineni
 
Lecture 2 _Foundions foundions NumPyI.pptx
Lecture 2 _Foundions foundions NumPyI.pptxLecture 2 _Foundions foundions NumPyI.pptx
Lecture 2 _Foundions foundions NumPyI.pptx
disserdekabrcha
 
Unit 3_Numpy_VP.pptx
Unit 3_Numpy_VP.pptxUnit 3_Numpy_VP.pptx
Unit 3_Numpy_VP.pptx
vishnupriyapm4
 
NUMPY-2.pptx
NUMPY-2.pptxNUMPY-2.pptx
NUMPY-2.pptx
MahendraVusa
 
Language R
Language RLanguage R
Language R
Girish Khanzode
 
numpy code and examples with attributes.pptx
numpy code and examples with attributes.pptxnumpy code and examples with attributes.pptx
numpy code and examples with attributes.pptx
swathis752031
 
Migrating from matlab to python
Migrating from matlab to pythonMigrating from matlab to python
Migrating from matlab to python
ActiveState
 
numpy.pdf
numpy.pdfnumpy.pdf
numpy.pdf
DrSudheerHanumanthak
 
Advance Programming Slides lect.pptx.pdf
Advance Programming Slides lect.pptx.pdfAdvance Programming Slides lect.pptx.pdf
Advance Programming Slides lect.pptx.pdf
mohsinfareed780
 
R programming & Machine Learning
R programming & Machine LearningR programming & Machine Learning
R programming & Machine Learning
AmanBhalla14
 
python-numpyandpandas-170922144956 (1).pptx
python-numpyandpandas-170922144956 (1).pptxpython-numpyandpandas-170922144956 (1).pptx
python-numpyandpandas-170922144956 (1).pptx
Akashgupta517936
 
Chapter 5-Numpy-Pandas.pptx python programming
Chapter 5-Numpy-Pandas.pptx python programmingChapter 5-Numpy-Pandas.pptx python programming
Chapter 5-Numpy-Pandas.pptx python programming
ssuser77162c
 
Introduction to a Python Libraries and python frameworks
Introduction to a Python Libraries and python frameworksIntroduction to a Python Libraries and python frameworks
Introduction to a Python Libraries and python frameworks
yokeshmca
 
Python crash course libraries numpy-1, panda.ppt
Python crash course libraries numpy-1, panda.pptPython crash course libraries numpy-1, panda.ppt
Python crash course libraries numpy-1, panda.ppt
janaki raman
 
Python Interview Questions PDF By ScholarHat
Python Interview Questions PDF By ScholarHatPython Interview Questions PDF By ScholarHat
Python Interview Questions PDF By ScholarHat
Scholarhat
 
getting started with numpy and pandas.pptx
getting started with numpy and pandas.pptxgetting started with numpy and pandas.pptx
getting started with numpy and pandas.pptx
workvishalkumarmahat
 
Unit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptxUnit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptx
prakashvs7
 
object oriented programing in python and pip
object oriented programing in python and pipobject oriented programing in python and pip
object oriented programing in python and pip
LakshmiMarineni
 
Lecture 2 _Foundions foundions NumPyI.pptx
Lecture 2 _Foundions foundions NumPyI.pptxLecture 2 _Foundions foundions NumPyI.pptx
Lecture 2 _Foundions foundions NumPyI.pptx
disserdekabrcha
 
numpy code and examples with attributes.pptx
numpy code and examples with attributes.pptxnumpy code and examples with attributes.pptx
numpy code and examples with attributes.pptx
swathis752031
 
Migrating from matlab to python
Migrating from matlab to pythonMigrating from matlab to python
Migrating from matlab to python
ActiveState
 
Advance Programming Slides lect.pptx.pdf
Advance Programming Slides lect.pptx.pdfAdvance Programming Slides lect.pptx.pdf
Advance Programming Slides lect.pptx.pdf
mohsinfareed780
 
R programming & Machine Learning
R programming & Machine LearningR programming & Machine Learning
R programming & Machine Learning
AmanBhalla14
 
Ad

More from Andrew Ferlitsch (20)

AI - Intelligent Agents
AI - Intelligent AgentsAI - Intelligent Agents
AI - Intelligent Agents
Andrew Ferlitsch
 
Pareto Principle Applied to QA
Pareto Principle Applied to QAPareto Principle Applied to QA
Pareto Principle Applied to QA
Andrew Ferlitsch
 
Whiteboarding Coding Challenges in Python
Whiteboarding Coding Challenges in PythonWhiteboarding Coding Challenges in Python
Whiteboarding Coding Challenges in Python
Andrew Ferlitsch
 
Object Oriented Programming Principles
Object Oriented Programming PrinciplesObject Oriented Programming Principles
Object Oriented Programming Principles
Andrew Ferlitsch
 
Python - OOP Programming
Python - OOP ProgrammingPython - OOP Programming
Python - OOP Programming
Andrew Ferlitsch
 
Python - Installing and Using Python and Jupyter Notepad
Python - Installing and Using Python and Jupyter NotepadPython - Installing and Using Python and Jupyter Notepad
Python - Installing and Using Python and Jupyter Notepad
Andrew Ferlitsch
 
Natural Language Processing - Groupings (Associations) Generation
Natural Language Processing - Groupings (Associations) GenerationNatural Language Processing - Groupings (Associations) Generation
Natural Language Processing - Groupings (Associations) Generation
Andrew Ferlitsch
 
Natural Language Provessing - Handling Narrarive Fields in Datasets for Class...
Natural Language Provessing - Handling Narrarive Fields in Datasets for Class...Natural Language Provessing - Handling Narrarive Fields in Datasets for Class...
Natural Language Provessing - Handling Narrarive Fields in Datasets for Class...
Andrew Ferlitsch
 
Machine Learning - Introduction to Recurrent Neural Networks
Machine Learning - Introduction to Recurrent Neural NetworksMachine Learning - Introduction to Recurrent Neural Networks
Machine Learning - Introduction to Recurrent Neural Networks
Andrew Ferlitsch
 
Machine Learning - Introduction to Convolutional Neural Networks
Machine Learning - Introduction to Convolutional Neural NetworksMachine Learning - Introduction to Convolutional Neural Networks
Machine Learning - Introduction to Convolutional Neural Networks
Andrew Ferlitsch
 
Machine Learning - Introduction to Neural Networks
Machine Learning - Introduction to Neural NetworksMachine Learning - Introduction to Neural Networks
Machine Learning - Introduction to Neural Networks
Andrew Ferlitsch
 
Machine Learning - Accuracy and Confusion Matrix
Machine Learning - Accuracy and Confusion MatrixMachine Learning - Accuracy and Confusion Matrix
Machine Learning - Accuracy and Confusion Matrix
Andrew Ferlitsch
 
Machine Learning - Ensemble Methods
Machine Learning - Ensemble MethodsMachine Learning - Ensemble Methods
Machine Learning - Ensemble Methods
Andrew Ferlitsch
 
ML - Multiple Linear Regression
ML - Multiple Linear RegressionML - Multiple Linear Regression
ML - Multiple Linear Regression
Andrew Ferlitsch
 
ML - Simple Linear Regression
ML - Simple Linear RegressionML - Simple Linear Regression
ML - Simple Linear Regression
Andrew Ferlitsch
 
Machine Learning - Dummy Variable Conversion
Machine Learning - Dummy Variable ConversionMachine Learning - Dummy Variable Conversion
Machine Learning - Dummy Variable Conversion
Andrew Ferlitsch
 
Machine Learning - Splitting Datasets
Machine Learning - Splitting DatasetsMachine Learning - Splitting Datasets
Machine Learning - Splitting Datasets
Andrew Ferlitsch
 
Machine Learning - Dataset Preparation
Machine Learning - Dataset PreparationMachine Learning - Dataset Preparation
Machine Learning - Dataset Preparation
Andrew Ferlitsch
 
Machine Learning - Introduction to Tensorflow
Machine Learning - Introduction to TensorflowMachine Learning - Introduction to Tensorflow
Machine Learning - Introduction to Tensorflow
Andrew Ferlitsch
 
Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine Learning
Andrew Ferlitsch
 
Pareto Principle Applied to QA
Pareto Principle Applied to QAPareto Principle Applied to QA
Pareto Principle Applied to QA
Andrew Ferlitsch
 
Whiteboarding Coding Challenges in Python
Whiteboarding Coding Challenges in PythonWhiteboarding Coding Challenges in Python
Whiteboarding Coding Challenges in Python
Andrew Ferlitsch
 
Object Oriented Programming Principles
Object Oriented Programming PrinciplesObject Oriented Programming Principles
Object Oriented Programming Principles
Andrew Ferlitsch
 
Python - Installing and Using Python and Jupyter Notepad
Python - Installing and Using Python and Jupyter NotepadPython - Installing and Using Python and Jupyter Notepad
Python - Installing and Using Python and Jupyter Notepad
Andrew Ferlitsch
 
Natural Language Processing - Groupings (Associations) Generation
Natural Language Processing - Groupings (Associations) GenerationNatural Language Processing - Groupings (Associations) Generation
Natural Language Processing - Groupings (Associations) Generation
Andrew Ferlitsch
 
Natural Language Provessing - Handling Narrarive Fields in Datasets for Class...
Natural Language Provessing - Handling Narrarive Fields in Datasets for Class...Natural Language Provessing - Handling Narrarive Fields in Datasets for Class...
Natural Language Provessing - Handling Narrarive Fields in Datasets for Class...
Andrew Ferlitsch
 
Machine Learning - Introduction to Recurrent Neural Networks
Machine Learning - Introduction to Recurrent Neural NetworksMachine Learning - Introduction to Recurrent Neural Networks
Machine Learning - Introduction to Recurrent Neural Networks
Andrew Ferlitsch
 
Machine Learning - Introduction to Convolutional Neural Networks
Machine Learning - Introduction to Convolutional Neural NetworksMachine Learning - Introduction to Convolutional Neural Networks
Machine Learning - Introduction to Convolutional Neural Networks
Andrew Ferlitsch
 
Machine Learning - Introduction to Neural Networks
Machine Learning - Introduction to Neural NetworksMachine Learning - Introduction to Neural Networks
Machine Learning - Introduction to Neural Networks
Andrew Ferlitsch
 
Machine Learning - Accuracy and Confusion Matrix
Machine Learning - Accuracy and Confusion MatrixMachine Learning - Accuracy and Confusion Matrix
Machine Learning - Accuracy and Confusion Matrix
Andrew Ferlitsch
 
Machine Learning - Ensemble Methods
Machine Learning - Ensemble MethodsMachine Learning - Ensemble Methods
Machine Learning - Ensemble Methods
Andrew Ferlitsch
 
ML - Multiple Linear Regression
ML - Multiple Linear RegressionML - Multiple Linear Regression
ML - Multiple Linear Regression
Andrew Ferlitsch
 
ML - Simple Linear Regression
ML - Simple Linear RegressionML - Simple Linear Regression
ML - Simple Linear Regression
Andrew Ferlitsch
 
Machine Learning - Dummy Variable Conversion
Machine Learning - Dummy Variable ConversionMachine Learning - Dummy Variable Conversion
Machine Learning - Dummy Variable Conversion
Andrew Ferlitsch
 
Machine Learning - Splitting Datasets
Machine Learning - Splitting DatasetsMachine Learning - Splitting Datasets
Machine Learning - Splitting Datasets
Andrew Ferlitsch
 
Machine Learning - Dataset Preparation
Machine Learning - Dataset PreparationMachine Learning - Dataset Preparation
Machine Learning - Dataset Preparation
Andrew Ferlitsch
 
Machine Learning - Introduction to Tensorflow
Machine Learning - Introduction to TensorflowMachine Learning - Introduction to Tensorflow
Machine Learning - Introduction to Tensorflow
Andrew Ferlitsch
 
Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine Learning
Andrew Ferlitsch
 
Ad

Recently uploaded (20)

Unlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web AppsUnlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web Apps
Maximiliano Firtman
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...
BookNet Canada
 
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdfKit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Wonjun Hwang
 
Jignesh Shah - The Innovator and Czar of Exchanges
Jignesh Shah - The Innovator and Czar of ExchangesJignesh Shah - The Innovator and Czar of Exchanges
Jignesh Shah - The Innovator and Czar of Exchanges
Jignesh Shah Innovator
 
AsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API DesignAsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API Design
leonid54
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
Agentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community MeetupAgentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community Meetup
Manoj Batra (1600 + Connections)
 
machines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdfmachines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdf
AmirStern2
 
UiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer OpportunitiesUiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer Opportunities
DianaGray10
 
AI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of DocumentsAI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of Documents
UiPathCommunity
 
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Wonjun Hwang
 
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à GenèveUiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPathCommunity
 
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent LasterAI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
 
AI You Can Trust: The Critical Role of Governance and Quality.pdf
AI You Can Trust: The Critical Role of Governance and Quality.pdfAI You Can Trust: The Critical Role of Governance and Quality.pdf
AI You Can Trust: The Critical Role of Governance and Quality.pdf
Precisely
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
The Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI IntegrationThe Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI Integration
Re-solution Data Ltd
 
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz
 
Does Pornify Allow NSFW? Everything You Should Know
Does Pornify Allow NSFW? Everything You Should KnowDoes Pornify Allow NSFW? Everything You Should Know
Does Pornify Allow NSFW? Everything You Should Know
Pornify CC
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 
Unlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web AppsUnlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web Apps
Maximiliano Firtman
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...
BookNet Canada
 
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdfKit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Wonjun Hwang
 
Jignesh Shah - The Innovator and Czar of Exchanges
Jignesh Shah - The Innovator and Czar of ExchangesJignesh Shah - The Innovator and Czar of Exchanges
Jignesh Shah - The Innovator and Czar of Exchanges
Jignesh Shah Innovator
 
AsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API DesignAsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API Design
leonid54
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
machines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdfmachines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdf
AmirStern2
 
UiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer OpportunitiesUiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer Opportunities
DianaGray10
 
AI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of DocumentsAI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of Documents
UiPathCommunity
 
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Wonjun Hwang
 
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à GenèveUiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPathCommunity
 
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent LasterAI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
 
AI You Can Trust: The Critical Role of Governance and Quality.pdf
AI You Can Trust: The Critical Role of Governance and Quality.pdfAI You Can Trust: The Critical Role of Governance and Quality.pdf
AI You Can Trust: The Critical Role of Governance and Quality.pdf
Precisely
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
The Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI IntegrationThe Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI Integration
Re-solution Data Ltd
 
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz
 
Does Pornify Allow NSFW? Everything You Should Know
Does Pornify Allow NSFW? Everything You Should KnowDoes Pornify Allow NSFW? Everything You Should Know
Does Pornify Allow NSFW? Everything You Should Know
Pornify CC
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 

Python - Numpy/Pandas/Matplot Machine Learning Libraries

  • 1. Python Numpy/Pandas Libraries Machine Learning Portland Data Science Group Created by Andrew Ferlitsch Community Outreach Officer July, 2017
  • 2. Libraries - Numpy • A popular math library in Python for Machine Learning is ‘numpy’. import numpy as np Keyword to import a library Keyword to refer to library by an alias (shortcut) name Numpy.org : NumPy is the fundamental package for scientific computing with Python. • a powerful N-dimensional array object • sophisticated (broadcasting) functions • tools for integrating C/C++ and Fortran code • useful linear algebra, Fourier transform, and random number capabilities
  • 3. Libraries - Numpy The most import data structure for scientific computing in Python is the NumPy array. NumPy arrays are used to store lists of numerical data and to represent vectors, matrices, and even tensors. NumPy arrays are designed to handle large data sets efficiently and with a minimum of fuss. The NumPy library has a large set of routines for creating, manipulating, and transforming NumPy arrays. Core Python has an array data structure, but it’s not nearly as versatile, efficient, or useful as the NumPy array. http://www.physics.nyu.edu/pine/pymanual/html/chap3/chap3_arrays.html
  • 4. Numpy – Multidimensional Arrays • Numpy’s main object is a multi-dimensional array. • Creating a Numpy Array as a Vector: data = np.array( [ 1, 2, 3 ] ) Numpy function to create a numpy array Value is: array( [ 1, 2, 3 ] ) • Creating a Numpy Array as a Matrix: data = np.array( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ) Outer Dimension Inner Dimension (rows) Value is: array( [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] )
  • 5. Numpy – Multidimensional Arrays • Creating an array of Zeros: data = np.zeros( ( 2, 3 ), dtype=np.int ) Numpy function to create an array of zeros Value is: array( [ 0, 0, 0 ], [ 0, 0, 0 ] ) • Creating an array of Ones: data = np.ones( (2, 3), dtype=np.int ) rows columns data type (default is float) Numpy function to create an array of onesValue is: array( [ 1, 1, 1 ], [ 1, 1, 1 ] ) And many more functions: size, ndim, reshape, arange, …
  • 6. Libraries - Pandas • A popular library for importing and managing datasets in Python for Machine Learning is ‘pandas’. import pandas as pd Keyword to import a library Keyword to refer to library by an alias (shortcut) name PyData.org : high-performance, easy-to-use data structures and data analysis tools for the Python programming language. Used for: • Data Analysis • Data Manipulation • Data Visualization
  • 7. Pandas – Indexed Arrays • Pandas are used to build indexed arrays (1D) and matrices (2D), where columns and rows are labeled (named) and can be accessed via the labels (names). 1 2 3 4 4 5 6 7 8 9 10 11 1 2 3 4 4 5 6 7 8 9 10 11 one two three x1 x2 x3 x4 raw data Row (samples) index Columns (features) index Panda Indexed Matrix
  • 8. Pandas – Series and Data Frames • Pandas Indexed Arrays are referred to as Series (1D) and Data Frames (2D). • Series is a 1D labeled (indexed) array and can hold any data type, and mix of data types. s = pd.Series( data, index=[ ‘x1’, ‘x2’, ‘x3’, ‘x4’ ] ) Series Raw data Column Index Labels • Data Frame is a 2D labeled (indexed) matrix and can hold any data type, and mix of data types. df = pd.DataFrame( data, index=[‘one’, ‘two’], columns=[ ‘x1’, ‘x2’, ‘x3’, ‘x4’ ] ) Data Frame Row Index Labels Column Index Labels
  • 9. Pandas – Selecting • Selecting One Column x1 = df[ ‘x1’ ] Selects column labeled x1 for all rows 1 4 8 • Selecting Multiple Columns x1 = df[ [ ‘x1’, ‘x3’ ] ] Selects columns labeled x1 and x3 for all rows 1 3 4 6 8 10 x1 = df.ix[ :, ‘x1’:’x3’ ] Selects columns labeled x1 through x3 for all rows 1 2 3 4 5 6 8 9 10 Note: df[‘x1’:’x3’ ] this python syntax does not work! rows (all) columns Slicing function And many more functions: merge, concat, stack, …
  • 10. Libraries - Matplotlib • A popular library for plotting and visualizing data in Python import matplotlib.pyplot as plt Keyword to import a library Keyword to refer to library by an alias (shortcut) name matplotlib.org: Matplotlib is a Python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms. Used for: • Plots • Histograms • Bar Charts • Scatter Plots • etc
  • 11. Matplotlib - Plot • The function plot plots a 2D graph. plt.plot( x, y ) Function to plot X values to plot Y values to plot • Example: plt.plot( [ 1, 2, 3 ], [ 4, 6, 8 ] ) # Draws plot in the background plt.show() # Displays the plot X Y 1 2 4 6 8 2 3
  • 12. Matplotlib – Plot Labels • Add Labels for X and Y Axis and Plot Title (caption) plt.plot( [ 1, 2, 3 ], [ 4, 6, 8 ] ) plt.xlabel( “X Numbers” ) # Label on the X-axis plt.ylabel( “Y Numbers” ) # Label on the Y-axis plt.title( “My Plot of X and Y”) # Title for the Plot plt.show() 1 2 4 6 8 2 3 X Numbers YNumbers My Plot of X and Y
  • 13. Matplotlib – Multiple Plots and Legend • You can add multiple plots in a Graph plt.plot( [ 1, 2, 3 ], [ 4, 6, 8 ], label=‘ 1st Line’ ) # Plot for 1st Line plt.plot( [ 1, 2, 3 ], [ 2, 4, 6 ], label=‘2nd Line’ ) # Plot for 2nd Line plt.xlabel( “X Numbers” ) plt.ylabel( “Y Numbers” ) plt.title( “My Plot of X and Y”) plt.legend() # Show Legend for the plots plt.show() 1 2 4 6 8 2 3 X Numbers YNumbers My Plot of X and Y ---- 1st Line ---- 2nd Line
  • 14. Matplotlib – Bar Chart • The function bar plots a bar graph. plt.plot( [ 1, 2, 3 ], [ 4, 6, 8 ] ) # Plot for 1st Line plt.bar() # Draw a bar chart plt.show() 1 2 4 6 8 2 3 And many more functions: hist, scatter, …
  翻译: