Object Oriented Programming
Object Oriented Programming
relationship ID rId2
was not found in the
file.
Python
Introduction
MODERN DATA ANALYTICS
[G0Z39A]
PROF. DR. IR. JAN DE SPIEGELEER
Object Oriented
Programming
H T TPS://GITH UB.CO M /DESPIEGJ/GOZ39A . (M ASTER BRAN CH )
2
List of
tutorials
◦ https://bit.ly/38AE7Rj
◦ https://bit.ly/3ryOqOa
◦ https://bit.ly/3poTrHq
◦ ...
3
Without Object Oriented Programming
4
Classes and Objects
Python uses a programming pattern called object-oriented programming, which models
concepts using classes and objects
◦ classes represent concepts
◦ objects are instances of classes
5
Classes and Objects
CAR
6
Classes and Objects
Mycar = BMW(grey,diesel,series 7)
CAR
class Car: class BMW(Car):
Mycar = Peugeot(white,diesel,3008)
Inheritance of Classes
7
Methods and Attributes
The core concept of object-oriented programming comes down
to attributes and methods associated with a class:
◦ Attributes/Properties are the characteristics of a class.
◦ Methods are the functions associated to a class.
8
Why OOP for a data-scientist ?
In Python everything is a class
Key data science libraries, such as pandas, numpy, and scikit-learn all heavily rely on OOP.
In scikit-learn a regression model (for example) is as an instance of a class, and it has a fit() method to train your machine
learning model or a predict() method for forecasts.
Object oriented code allows for reusable and extendable code. You can use these functions and classes in repeated
analyses, or create new projects that utilize some of the existing code, reducing time to produce results.
It can be much easier to spot bugs if you write clean, object oriented code.
It makes it easier to test and debug code when the pieces are more modular and broken down.
Object oriented programming allows for parallel development between multiple data scientists who want to work with
the same codebase for their projects.
Cons
There can be a learning curve when starting to utilize object oriented programming and may take some time to get used
to.
9
Why OOP for a data-scientist ?
10
Let’s get
convinced with
BUILD A LIN EAR
REGRESSIO N M O DEL
(AS YO U ALWAYS DO )
a simple
O R USIN G O BJEC T
O RIEN T
PRO GRAM M IN G.
example Linear_regression.ipynb
11