Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
127 views

Object Oriented Programming

This document introduces object-oriented programming concepts in Python for data science. It discusses how classes represent concepts and objects are instances of classes. Key concepts like attributes, properties, methods, and inheritance of classes are covered. The benefits of OOP for data scientists are that Python libraries like pandas and scikit-learn rely heavily on OOP. OOP allows for reusable, extendable code and makes debugging easier. While there is a learning curve to OOP, the document demonstrates building a linear regression model using either the usual method or with an object-oriented approach.

Uploaded by

Ali Shana'a
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
127 views

Object Oriented Programming

This document introduces object-oriented programming concepts in Python for data science. It discusses how classes represent concepts and objects are instances of classes. Key concepts like attributes, properties, methods, and inheritance of classes are covered. The benefits of OOP for data scientists are that Python libraries like pandas and scikit-learn rely heavily on OOP. OOP allows for reusable, extendable code and makes debugging easier. While there is a learning curve to OOP, the document demonstrates building a linear regression model using either the usual method or with an object-oriented approach.

Uploaded by

Ali Shana'a
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

The image part with

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)

class Peugeot(Car): Objects

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.

In the car example


◦ Attributes/Properties : color, fuel type....
◦ Methods : break(), turn(), start(),....

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

You might also like