PYTHON FOR MACHINE
LEARNING(MATPLOTLIB)
Dr. Amanpreet Kaur​
Associate Professor,
Chitkara University,
Punjab
MATPLOTLIB
2
• Matplotlib is one of the most popular Python packages used for data
visualization.
• It is a cross-platform library for making 2D plots from data in arrays.
• Matplotlib is written in Python and makes use of NumPy, the numerical
mathematics extension of Python.
• It provides an object-oriented API that helps in embedding plots in
applications using Python GUI toolkits such as PyQt, WxPythonot Tkinter.
• It can be used in Python and IPython shells, Jupyter notebook and web
application servers also.
3
• Matplotlib has a procedural interface named the Pylab, which is
designed to resemble MATLAB, a proprietary programming
language developed by MathWorks.
• Matplotlib along with NumPy can be considered as the open
source equivalent of MATLAB.
• Matplotlib was originally written by John D. Hunter in 2003. The
current stable version is 2.2.0 released in January 2018.
• Below command in used to install Matplotlib
pip3 install matplotlib
MATPLOTLIB
4
# importing the necessary packages and modules
import matplotlib.pyplot as plt
import numpy as np
# Prepare the data
x = np.linspace(0, 10, 100)
# Plot the data
plt.plot(x, x, label ='linear')
# Add a legend
plt.legend()
# Show the plot
plt.show()
MATPLOTLIB - EXAMPLE
5
MATPLOTLIB - EXAMPLE
# importing the necessary packages and modules
import matplotlib.pyplot as plt
import numpy as np
plt.plot([1, 2, 3, 4], [1, 4, 9, 16], ‘ro’)
plt.axis([0, 6, 0, 20])
plt.show()
6
MATPLOTLIB - EXAMPLE
import matplotlib.pyplot as plt
import numpy as np
data =np.random.randint(400,size=25)
# Return random integers from the “discrete uniform”
distribution of the specified dtype in the “half-open”
interval [low, high). If high is None (the default), then
results are from [0, low).
label = np.array(range(1,26))
plt.plot(label,data,'.')
PYTHON PROGRAMMING
7
Online Compiler:-
https://dataplatform.cloud.ibm.com/
https://jupyter.org/
PYTHON PROGRAMMING
8
E Books-
• Peter Harrington “Machine Learning In Action”, DreamTech
Press
• Ethem Alpaydın, “Introduction to Machine Learning”, MIT Press
Video Links-
• https://www.youtube.com/watch?v=BRMS3T11Cdw&list=PL3pGy4HtqwD2a
57wl7Cl7tmfxfk7JWJ9Y
• https://www.youtube.com/watch?v=EWmCkVfPnJ8&list=PL3pGy4HtqwD2a
57wl7Cl7tmfxfk7JWJ9Y&index=3
THANK YOU
aman_preet_k@yahoo.co.in

Python for Machine Learning(MatPlotLib).pptx

  • 1.
    PYTHON FOR MACHINE LEARNING(MATPLOTLIB) Dr.Amanpreet Kaur​ Associate Professor, Chitkara University, Punjab
  • 2.
    MATPLOTLIB 2 • Matplotlib isone of the most popular Python packages used for data visualization. • It is a cross-platform library for making 2D plots from data in arrays. • Matplotlib is written in Python and makes use of NumPy, the numerical mathematics extension of Python. • It provides an object-oriented API that helps in embedding plots in applications using Python GUI toolkits such as PyQt, WxPythonot Tkinter. • It can be used in Python and IPython shells, Jupyter notebook and web application servers also.
  • 3.
    3 • Matplotlib hasa procedural interface named the Pylab, which is designed to resemble MATLAB, a proprietary programming language developed by MathWorks. • Matplotlib along with NumPy can be considered as the open source equivalent of MATLAB. • Matplotlib was originally written by John D. Hunter in 2003. The current stable version is 2.2.0 released in January 2018. • Below command in used to install Matplotlib pip3 install matplotlib MATPLOTLIB
  • 4.
    4 # importing thenecessary packages and modules import matplotlib.pyplot as plt import numpy as np # Prepare the data x = np.linspace(0, 10, 100) # Plot the data plt.plot(x, x, label ='linear') # Add a legend plt.legend() # Show the plot plt.show() MATPLOTLIB - EXAMPLE
  • 5.
    5 MATPLOTLIB - EXAMPLE #importing the necessary packages and modules import matplotlib.pyplot as plt import numpy as np plt.plot([1, 2, 3, 4], [1, 4, 9, 16], ‘ro’) plt.axis([0, 6, 0, 20]) plt.show()
  • 6.
    6 MATPLOTLIB - EXAMPLE importmatplotlib.pyplot as plt import numpy as np data =np.random.randint(400,size=25) # Return random integers from the “discrete uniform” distribution of the specified dtype in the “half-open” interval [low, high). If high is None (the default), then results are from [0, low). label = np.array(range(1,26)) plt.plot(label,data,'.')
  • 7.
  • 8.
    PYTHON PROGRAMMING 8 E Books- •Peter Harrington “Machine Learning In Action”, DreamTech Press • Ethem Alpaydın, “Introduction to Machine Learning”, MIT Press Video Links- • https://www.youtube.com/watch?v=BRMS3T11Cdw&list=PL3pGy4HtqwD2a 57wl7Cl7tmfxfk7JWJ9Y • https://www.youtube.com/watch?v=EWmCkVfPnJ8&list=PL3pGy4HtqwD2a 57wl7Cl7tmfxfk7JWJ9Y&index=3
  • 9.