Photo by Chris Ried on Unsplash
W
hen working on data science projects or any Python programming project, you will most likely find yourself utilizing plenty of self-made functions and variables. You may have even create an entire script filled with functions you created in order to streamline the process of your project.
The purpose of these functions can be for numerous things within your code. From cleaning your DataFrame to training a machine learning model. It’s useful to create a ton of functions in order to organize your Python code but there is another way to make your code look and act more presentable — By using a Python Class!
A Python class is like an outline for creating a new object. An object is anything that you wish to manipulate or change while working through the code. Every time a class object is instantiated, which is when we declare a variable, a new object is initiated from scratch. Class objects can be used over and over again whenever needed.
In our case, in our previous articles, we have been writing a series about the creation of a dating algorithm that clusters and sorts dating profiles by using machine learning. See here:
In the article above, we go through the entire process of data preprocessing in order to have our data become AI friendly, such as transforming the dating profiles into an array of numbers. The objects, in this case, are the dating profiles that need to be manipulated in order for all of this to happen.
This data preprocessing step is achieved through the use of numerous functions. It is not organized in the best way but it gets the job done. However, we can improve the process by utilizing a Python Class.
In order to learn more about class objects and utilizing them, we will be implementing a class object for our AI Dating Algorithm. Let’s organize and clean up the code we used into a Class object.
First, we must ask ourselves — What do we want this class object to do? We want it to:
Basically, we will want it to condense the entire data preprocessing step into a Class object which we can then use for every new dating profile we wish to add. We can use this class object whenever we need to create a new dating profile.
#education #artificial-intelligence #python #programming #data-science