plotting visualization
play

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


  1. Plotting & Visualization Maryam Tavakol Machine Learning Group Winter semester 2016/17 1

  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

  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 operating systems • Can export graphics to all of the common vector and raster graphics formats 3

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

  5. Subplots 5

  6. Subplot Options 6

  7. Plotting 7

  8. Formatting • Line style, color, and marker 8

  9. Formatting 9

  10. Titles & Labels 10

  11. Adding Legends 11

  12. Example 12

  13. Annotations 13

  14. Annotations • Annotations and text can be added using the text, arrow, and annotate functions 14

  15. Adding Shapes 15

  16. Saving Options 16

  17. Histogram 17

  18. Histogram 18

  19. Box Plot 19

  20. Box Plot 20

  21. Profiling & Optimization Maryam Tavakol Machine Learning Group Winter semester 2016/17 21

  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

  23. %timeit • The %timeit allow you to quickly evaluate the time taken by one or several Python statements in IPython 23

  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

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

  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

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

  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

Recommend


More recommend