Plotting & Visualization Maryam Tavakol Machine Learning Group - - PowerPoint PPT Presentation

plotting visualization
SMART_READER_LITE
LIVE PREVIEW

Plotting & Visualization Maryam Tavakol Machine Learning Group - - PowerPoint PPT Presentation

Plotting & Visualization Maryam Tavakol Machine Learning Group Winter semester 2016/17 1 Motivation Making plots and static or interactive visualizations is one of the most important tasks in data analysis Helping identify outliers


slide-1
SLIDE 1

Plotting & Visualization

Maryam Tavakol

Machine Learning Group

1

Winter semester 2016/17

slide-2
SLIDE 2

Motivation

  • Making plots and static or interactive visualizations

is one of the most important tasks in data analysis

  • Helping identify outliers
  • Needed data transformations
  • Coming up with ideas for models
  • etc.

2

slide-3
SLIDE 3

matplotlib

  • Desktop plotting package designed for creating

publication-quality plots

  • Does have interactive features like zooming and

panning

  • Supports many different GUI backends on all
  • perating systems
  • Can export graphics to all of the common vector

and raster graphics formats

3

slide-4
SLIDE 4

Figures

  • Plots in matplotlib reside within a Figure object
  • Creates a new empty window

4

slide-5
SLIDE 5

Subplots

5

slide-6
SLIDE 6

Subplot Options

6

slide-7
SLIDE 7

Plotting

7

slide-8
SLIDE 8

Formatting

  • Line style, color, and marker

8

slide-9
SLIDE 9

Formatting

9

slide-10
SLIDE 10

Titles & Labels

10

slide-11
SLIDE 11

Adding Legends

11

slide-12
SLIDE 12

Example

12

slide-13
SLIDE 13

Annotations

13

slide-14
SLIDE 14

Annotations

  • Annotations and text can be added using the text,

arrow, and annotate functions

14

slide-15
SLIDE 15

Adding Shapes

15

slide-16
SLIDE 16

Saving Options

16

slide-17
SLIDE 17

Histogram

17

slide-18
SLIDE 18

Histogram

18

slide-19
SLIDE 19

Box Plot

19

slide-20
SLIDE 20

Box Plot

20

slide-21
SLIDE 21

Profiling & Optimization

Maryam Tavakol

Machine Learning Group

21

Winter semester 2016/17

slide-22
SLIDE 22

Introduction

  • Python is generally known (a bit unfairly) as a slow

language, but it is possible to achieve very good performance with the right methods

  • Profile: To evaluate what makes a program slow
  • Optimize: To make the code more efficient

22

slide-23
SLIDE 23

%timeit

  • The %timeit allow you to quickly evaluate the time

taken by one or several Python statements in IPython

23

slide-24
SLIDE 24

%timeit

  • The %timeit command accepts several optional

parameters, e.g.:

  • Using -r or -n to set number of statement

evaluations

  • Inside your script: timeit.timeit()

24

slide-25
SLIDE 25

cProfile

  • Creates a detailed report of the execution time of
  • ur code, function by function
  • The total number of calls, total time, etc.

25

slide-26
SLIDE 26

line_profiler

  • Analyzing of code performance by a line-by-line

report

  • Need the package kernprof
  • We decorate the functions we wish to profile with

@profile


26

slide-27
SLIDE 27

Memory Usage

  • Memory is also a critical factor
  • Using memory_profiler
  • We decorate the functions we wish to profile with

@profile

27

slide-28
SLIDE 28

Optimization Tips

  • Choosing the right data structure
  • Using NumPy over native Python code
  • Avoiding unnecessary array copying
  • Using in-place operations instead of implicit copy
  • Parallel computing and much more…

28