Project Overview: Differentiating Through Implementation
This end-to-end machine learning course focuses on building a house price prediction model, but with a crucial difference: it emphasizes implementation quality over novelty of the idea. The core message is that even a basic project like house price prediction can become a top 1% portfolio piece by focusing on two key areas:
- Core ML Mastery: Deep understanding of data, rigorous analysis, and assumption testing.
- MLOps Integration: Using tools like ZenML and MLflow for experiment tracking, CICD, and deployment.
- Professional-Grade Code: Applying design patterns (Factory, Strategy, Template) for scalability and readability.
Core ML: The Data-Driven Approach
1. Deep Data Understanding
The project stresses spending significant time on data, moving beyond simple EDA. The instructor advocates for:
- Creating a narrative from your analysis, not just plotting standard graphs.
- Making informed decisions about feature engineering and algorithm selection based on data insights.
- Testing algorithm assumptions to ensure data fits the chosen model.
2. Exploratory Data Analysis (EDA) Process
The EDA phase is implemented using the Strategy design pattern for scalability and maintainability. For a comprehensive foundation in ML fundamentals, consider the Complete Machine Learning Course: 60-Hour Hands-On Tutorial with Python Projects.
- Data Inspection: A base
DataInspectionStrategyinterface is created with subclasses like:DataTypesInspectionStrategy: Checks column data types and non-null counts.SummaryStatisticsInspectionStrategy: Provides summary statistics for numerical and categorical columns.
- Missing Value Analysis: A dedicated analysis to understand null value patterns.
- Univariate & Multivariate Analysis: Deeper analysis to uncover relationships.
MLOps Integration: Production-Ready Pipeline
Key Tools and Techniques
- ZenML: Used as the MLOps orchestrator to manage and automate machine learning workflows, creating a pipeline of steps and stacks.
- MLflow: Integrated for:
- Experiment Tracking: Logging parameters, metrics, and artifacts across different model runs.
- Model Deployment: Deploying the trained model for inference.
- CICD Pipelines: Automating the testing and deployment of the model to production.
Pipeline Steps (Planned)
- Data Ingestion: Loading data from a source (e.g., Kaggle zip file).
- EDA & Data Validation: Understanding and validating the data.
- Data Processing: Cleaning and feature engineering.
- Model Training: Training the chosen algorithm.
- Model Evaluation: Testing and validating performance.
- Model Deployment: Deploying via MLflow.
Design Patterns in Practice
1. Factory Pattern (Data Ingestion)
Used to create different data ingestors based on file format without hardcoding logic.
# Simplified example of the Factory pattern
class DataIngestor:
@staticmethod
def get_data_ingestor(file_extension):
if file_extension == ".zip":
return ZipDataIngestor()
elif file_extension == ".csv":
return CsvDataIngestor()
# ... other formats
else:
raise ValueError(f"No ingestor for {file_extension}")
class ZipDataIngestor(DataIngestor):
def ingest(self, file_path):
# Logic to handle zip files
pass
2. Strategy Pattern (EDA)
Allows switching between different data analysis methods (e.g., data type inspection vs. summary statistics) at runtime.
# Simplified example of the Strategy pattern
class DataInspector:
def __init__(self, strategy):
self._strategy = strategy
def set_strategy(self, strategy):
self._strategy = strategy
def execute_inspection(self, df):
self._strategy.inspect(df)
Key Differentiators from Typical Projects
- Error Handling: Adding input validation (e.g., checking if a file is actually a zip file before extracting).
- Type Checking: Using type hints and docstrings to improve code readability and maintainability.
- Structured Code: Moving logic from Jupyter notebooks to Python modules (e.g.,
analyze_source) to promote reproducibility. For a structured beginner-to-intermediate path, explore 100 Days of Machine Learning: Comprehensive Beginner to Intermediate Guide. - Scalable Design: Using design patterns so that adding a new file format (e.g., JSON) or analysis method doesn't break existing code.
Tools & Resources Mentioned
- Julius AI: Recommended for rapid data exploration and visualization. It offers workflows for common tasks like correlation matrices and data cleaning to speed up analysis.
- Community Support: Encourages participation in ZenML and MLflow Slack/Discord communities, acknowledging that MLOps tooling is still evolving.
Project Structure Overview
The course is structured into a series of lectures covering:
- Project Introduction and Motivation
- Design Patterns (Factory, Strategy, Template)
- Data Ingestion
- Exploratory Data Analysis
- Data Preprocessing
- Model Building with Assumption Testing
- MLOps Integration (ZenML, MLflow, CICD)
- Deployment and Monitoring
Note: This summary captures the core concepts and structure of the introductory lecture. The actual implementation will involve detailed code walkthroughs and hands-on assignments.
this into toin machine learning course will help you with Core Concepts and advanced mlops integration IU sing will
guide you through creating a project to help you learn data analysis feature engineering and model implementation
with rigorous testing while also teaching you how to write scalable and readable code finally you'll learn how
to integrate ml Ops using tools like Zen ML and ml flow for seamless experiment tracking and employment what if I tell
you that you can build a house price prediction model and still be in the top 1% of the data science community and
back a classy data science job I mean that sounds too good to be true right but it's actually true most of the
people say that go with a better idea everybody builds house price prediction model but in this video I'll show you
that how you can take a simplest Pro idea but with the implementation you can make it better than even the one which
has the best idea out there will build an entire end to end machine learning pipeline all the way starting from core
ml to integrating mlops principles like cicd experiment tracking monitoring and much more but Frankly Speaking the 99%
of the people what do they do they simply go ahead take the data it import it and then probably do some Eda just by
sake of doing it and once they have some sort of nice sexy graphics and all those things they simply go ahead and then do
some processing which is written by so-called gurus on YouTube and then they simply create the project by calling fit
and then they call predict and that's where the end of the project means so even if you take the sexiest idea of
your time you cannot really have that in your portfolio or be in the top 1% despite having the nice idea it's all
about the implementation so what we will do differently into this process there are two aspects of it one is core ML and
another one is mlops principle in core ml will entirely focus on first of all understanding data because when I was
working in one of my company one of my manager told me that there there's no point in doing data science if you do
not spend your most of your time in working on the data so we'll spend the most amount of time in working on the
data understanding the data I'll guide you through my thinking and decision process of why we are making such
decisions or analysis and based on those analysis we will interpret those things in order to know what can be issues what
can be things to be done what sort of algorithm to choose and if we choose those algorithm how do we verify whether
that data fits for the algorithm which is known as assumptions testing and violation and much more into the core ml
part into the mlops principle we'll integrate cicd pipelines deployment using ml flow for experiment tracking
using zml for orchestration and all those things and this one important factor which we'll also focus on is
writing better code because nowadays all the people right now in the community they do not follow the right coding
standards or the principles or the architectures out there we'll make use of design patterns to write code and to
actually use the right set of patterns in order to implement such scenarios and all of this which is core ml mlops
principles and using the right design patterns into the project and writing better code would make this the project
the top 1% and to be honest our several students just got their first job by just doing this so this is the project
which is a testament of implementing it right no matter what the idea is so let's get started with the project hi
everyone so we are finally going to start our uh series on building end to end prediction systems models using
mlops and core ml things so the first prodject which we are going to start with is an amazing project and which you
all are aware of is basic house price prediction but the whole point of this project is to differentiate you so how
can a simple project like house price prediction which most of the instructors on YouTube and stuff like that are
teaching on Jupiter and stuff like that how can we make it a top differentiator and get you in the top 1% just by
working onto this simple project idea the whole motto for this project is to make you believe what matters is the
implementation of the project not the idea but of course idea matters at some extent but even the simplest idea can be
imple implemented in such a way that will even defeat the top guys so let's let's go ahead and tell you a little bit
more about the project I don't need to explain about the idea too much so I'll just skim through it as much as I can
and possibly I will tell you a little bit more about uh the plans the how are we going to structure this project so
the first thing is I'm not going to code it entirely so it's like that I'll make sure that I get you each and everything
implemented however there will be some parts of it will be working as kind of that you should experiment by your own
and you should do it by your own which in which will involve as part of an assignment system also so uh around two
to three kind of code code lines or code blocks will be left for you guys to do and experiment it out by yourself apart
from it we'll be also not um doing live coding because live coding into this I wanted it to more explaining things
rather than writing and reading the code so my most of the time we go into explaining the code we'll explain the
concept behind it explaining the theory behind the code and so that you easily understand why there's the matter of the
fact over there is so the first thing is which I want to tell you that what this project is focused on so this project is
focused on building an endtoend machine learning pipeline for a house price prediction system so um house price is
that we will be given set of features we'll be give giving set of information about a particular house we need to
predict what will be the possibly price of the house so that is the system which we want to build but in a differentiated
way so we will uh I hope that you are already aware about Pipelines Stacks because we have already learned a lot
about this into our mlops fundamental thing so I'm not going to go deep into it but because we have already done
something with ziml we'll be utilizing ziml which is an orchestrator mlops framework the reason why I love ZL is
not because of uh me being any relation or past relation with ZL as a team but also it because it is very easy to use
tool and it seamlessly integrates several other mlops toool in order to build the full stack of it that's why I
love using it and it is relatively easy to understand and very easy simple code sort of in Python to write also so it's
an mlops framework that will help us to manage our machine learning workflows that okay after this step we'll be
implementing this step so you learn a lot about the steps and stacks pipelines stuff like that in zml when we actually
go ahead in a coding stuff and then we'll be using ml flow so mlflow is one of the Integrations of Zen ml2 so where
will be using that in order to track our experiments because we'll be doing several experiments by doing this or
doing that so we'll be using that to track our experiments and also we will use that to deploy our model so if you
have already seen our fundamentals project over there we have we we having the customer satisfaction thing in the
customer satisfaction we also used MLF flow to deploy the model so this will be recreating of that same scene but
possibly in a different code and sort of thing so that you know that how to use MLF flow in different projects too so so
that is the primary goal also so what is this it is basically predicting house prices based on several features but now
if you see the machine learning Paradigm if you see data science Paradigm there a lot of people actually doing this
project there are a lot of people who is working onto this project so what differentiates you what will
differentiate you into this particular system now I'm going to stress out on two matters on what currently people are
doing so there is very limited exploration so what most people do is they go ahead they start with the basic
exploratory data analysis using standard Frameworks so the utmost what they can do they will follow the Frameworks which
is listed on YouTube where they'll try to copy and paste those Frameworks and they do not make story out of it they do
not do anything they just plot images and stuff like that that's it and then they simply quick on they they simply do
not even look at those things and then simply go ahead and call fit on model without thoroughly understanding the
data data science is where data is an integral part if you do not spend your most of the time into it that means
you're not a data scientist and one of my manager when I was working in one of my company and she he was also director
of uh mlet M IBM uh he told me that there's no point in learning data science or machine
learning if you do not know how to work with data or how to understand data so we'll be spending a good amount of time
time into it now another another people most of most of the people do they simply split the data train a model call
predict evaluate the model and they often tends to achieve the high accuracy and or minimizing any sort of error that
is their whole Moto but they don't understand the fact that in an organization looks for an overall robust
model and for sure that okay even if you have 60% 70% accuracy that accuracy is being maintained over the period of
samples so that is another problem which I see another problem is once the if the student has completed the project and
the model is trained that they rarely revisit or improve based on deeper insights from the data they do not spend
their time in validating assumptions or handling uh uh violations stuff of of the algorithm and stuff like that so
this is a major major problem which I feel that do not take I mean if uh if a lion eats a fresh
meat if you give grass to it he will die right he will not eat so that is what uh into the same example that if uh an
algorithm expect some sort of data you should only give that data because that is the assumption that if you give me
this data then only I'll work otherwise I won't so that is another effort they do not put an effort and we have also
done a lot on validating assumption our course stuff so I want you to go ahead and look at it so uh we'll be doing all
of this but what we'll be doing is again what I told that tooro data research we'll spend a very bit of time into
understanding our data and we'll try to uh see if you can possibly use that to make a storyline and based on the
storyline how do we make decisions to go ahead and build our models on top of it apart from it we'll not just be training
a model we'll not just you know uh training a set of do predict do fair and stuff like that we'll be also doing that
but also we'll ensure that we are not going ahead in uh just core ml thing we are also ensuring the assumptions so
refining it iteratively and also implementing robust pipeline which is reproducible and Deployable so which is
an mlops integration to it and that will make the project the top 1% project ever created and I feel this house fres
prediction will be ever uh being created on for students to actually see how it can be done
differently and what I told we'll differentiate our project integrating mlops practices using zml and mlflow
we'll Implement cicd pipelines to automate testing deployment of the model in the production so U there will be
several tasks like that you have to take the API you have to integrate with this streamlit you have to also test other
assumptions because I've not tested all assumptions few assumptions were tested to make sure that it works but there are
several other assumptions to test several other models to try but one thing I want you to know for this
project is that will be only utilizing only one algorithm for this project we do not we'll be not switching the
algorithms out there however they will be tasks for you to implement other algorithms and then intelligently switch
between algorithms and then use that it is pretty easy so uh we be utilizing because our main focus is that I want
you to know that how can the project be implemented with a single algorithm with a core Basics and also being even the
simplest but even the powerful project of your whole um project sorry portfolio so I want you to take a look at this in
Greater detail and I if there there will be lot of Errors for sure because mlops is still has not matured enough to have
an have its own community so I want you to be available in mlflow communities ziml communities slack Community you can
also use pza to answer to to ask a question if you're enrolling into the course and try to see if you can
possibly uh get the answers of it but envelops as I say is not matured enough what does it really mean is that you do
not have the support systems ready you do not have the support prote practitioners ready into it so over here
you need to put in a lot of your mind but eventually it works out you just have to stick to it and make sure that
you do not go away or you know feel depressed from it so that is it about the project now
our next thing would be that we I will tell you about a plan what exactly I'm looking at the plan of this project how
I'm going to take how I'm going to take this project from um Eda ingestion how what are the source which which we're
going to have how are we going to deploy the model so I'll tell you a little bit about the plan and then we move it
further so let's meet in the next lecture so now we will go ahead and then I'll let you explore a little bit about
the project what exactly the project folder looks like and how are we going to move ahead and then I'll teach you
before we start anything will teach you three design patterns which we will be using a lot into this project because as
I say that I want to make it a very big differentiated project and for that I need to have this specific and proper uh
set of modules listed out here proper set of documentation being done so all those things will will be uh doing it so
first of all we will go ahead learned a little bit about the design patterns like strategy template Factory and then
uh we'll we start with our project coding step by step however there there will be some of the stances where I'll
State you that you should do this by your own or you should try this by your own so please make sure that you note
all of these things down because as I say that I'll be focusing more onto the explanation part of it um and making
sure that you understand each and every line of code in detail and my mindset and The Thinking Beyond it so that is
the whole goal and I I I I also like live coding but live coding into this will not make sense to me so probably my
main focus into this project will be to explain you each and every details about the project and let you explore things
by your own too so let's go ahead and then study a little bit about our first thing what exactly we are we we are
going to do so first of all we will always focus on loading the data so any project you
should start with you should always think about once you have the data because I've
taken it from kaggle because as I said it is a very simple project which is house price prediction project so the
first step is that we how do we ingest the data so most the people what do they do you get the data in zip file and then
they go simply go ahead write a function or probably in a jupyter notebook they use pd. read CS first unzip it and then
they do the PD do I mean read CSV and then that's it we'll use the different we'll do it very different and that's
where very small small things attract the recruiters or interviewers to make you think okay this guy has done
something really interesting while I don't want to go in detail about what design patterns helps how it helps and
all those things but in nutshell it's more about making your code reproducible scalable understandable and very easy to
maintain so that is why we use design pattern and we'll be using one of the factory design pattern to implement the
ingestion function or probably imp implement the ingest data pipeline so before that before we go into the code I
want you to know a little bit about Factory design pattern so what is Factory design pattern Factory design
pattern is let's say you have an coffee shop so you have a coffee shop and customers can order different types of
coffees into it it may be espresso it may be latte cappuccino Frappuccino whatever it might be but the process of
making a coffee follows a similar pattern that you want to put it you want to put it of course let's say milk or
skimmed milk or whatever you put it I mean maybe some some some sort of coffee powder so the process of making those
coffee follows a something similar pattern except some of the coffees so now you have a general coffee making
machine you don't have several other coffee machines like lates coffee machine cappuccina coffee machine or
frappucino coffee machine you just have one simple General coffee making machine that's what we call as a factory and
then into that factory you make different types of products or different type of coffees which we Nam as espresso
latte or capucino so what we do let's say that we want to code our thing that we want to make a coffee machine and in
that coffee machine will be having several other coffees out there so I'm going to show you uh you can simply go
to the folder and click on explanations and click on Factory design pattern so over here I really hope you're able to
see this screen if if not I'm just going to zoom in yep so over here you will um I want you to if you want to know more
about the design pattern I can come up with that course too but it's just that you can just go on YouTube there are a
lot of courses available on explaining about abstract method op Concepts and all but in a nut shet we first of all
create a factory which we call as a product interface or the general machine so General machine would be coffee and
that coffee will have one of the implementation which is to prepare the coffee so a coffee machine will have one
of this function is to prepare it right so any coffee let's say latte or espresso needs to go through that
preparation stage and then only the coffee will be built uh so in the same way a factory like a coffee into this
the name of the factory is coffee will have its own um will will contain the preparation stange tool now once you
have Factory you can extend that factory to multip product and use that factory to create concrete products create
several products out there so that is what class espresso and then espresso will be built from what Factory coffee
factory because espresso is um kind of a product which will be built in the coffee factory and then we just imp we
just in implement the prepare of course it does not have any logic it says preparing rich and strong espresso so
you simply uh on top of it you use the prepare prepare method you can also add multiple methods over here too if there
is any specificity needs to be maintained same goes with latte uh which inh heads from coffee the prepare method
and then same goes with the capuccino prepare now over here you make a actual Factory class so actual coffee machine
so the coffee machine is like coffee machine and the make coffee and what is the coffee type the coffee type is
espresso you just call espresso. prepare espresso. prepare if if the coffee type of course you see that we are um using
the coffee type so I'll show you the usage too so it's more like that we prepare the factory with different
different products so if the coffee type is espresso you prepare the espresso if the coffee type is latte you prepare the
latte and stuff like that and then now here's what the usage of the factory to create products so it it is our Factory
of course now you might be confused it is our Factory or this is our Factory in most of the cases this is the practice
practices practitioners follow this is the interface which they create but also I have seen people using it directly
from here but to create the extensibility and readability they actually create another Factory where
where this acts just like an interface there's nothing else it's just an interface that this is how it should
look like and then you implement those interfaces for example into the design you first of all have that uh design
thing ready and then the developer goes and Implement by seeing the interface the same way it happens over here that
you create an interface first and then you probably go ahead and create the concrete products or actually develop it
but yeah it totally depends on you on how you want to extend it further but the general practi is to having these
Factory sort of uh pattern so the factory pattern will look like this that you create a class now that factory will
have one of its preparation stage two the preparation stage will look like I want to make an coffee what is the
coffee type it it it expects the coffee type in an you know input and then whatever coffee type if there's no
coffee type then it returns an error so if we in instantiate our uh class and fact Factory class and then we start to
make coffees so we create a coffee and then machine. make coffee which is espresso we want to make espresso so
espresso is the type so it calls the espresso uh concrete product one of one one of one of the product and then it
calls dot prepare so if you see that we are also calling do prepare method from it so and then outputs are preparing a
rich and strong coffee same goes with the lat you just need to put in your coffee type and then you get your
factory design pattern out here so I hope that it helps to understand a little bit about what exactly Factory
design pattern means now what I'll do I'll simply go ahead and teach you a little bit about how we use this uh
Factory design pattern into ingesting our data so I don't want you to look at any of this I just want you to look at
few folders and uh of course you have to do it again by your own so by the end of this we'll I'll you you don't have to
write it by my from what I'm teaching it's not on the way I want you to first of all see understand and then do this
project from scratch by your own so I want to look at the data folder and the data folder is is having archive. Z IP
we'll be giving all these files and folders into our source code so if you're a paid paid guy then you must be
having these things already available to you if not please feel free to Ping On pza or tell to our course instructor
course coordinator he or she will be able to help you out now into this archive. ZIP is where
you have the uh you know data available now most of the people what do they do they simply create a function to unzip
the file and then probably go ahead now let's understand the case where there is CSV file then what you need to do you
need to create another sort of folder and then the different type of data comes in to create another function in
the same file and then try to do it and then what if if this Json things comes into play on to create another function
into the data injest now that is the readability and probably very a messy and not you know extendable code if you
have 1 million um formats of the data are you going to create 1 million stuff of course you have to create functions
for every you'll be not doing it because it is if you think about in terms of time complexity and stuff like that it's
not good so what do we do so I want to look at ingest data. pi and the way we work into in just data Pi
is is we going to implement the factory design pattern into this so what happens I'm going to be very honest so what
happens that you you will be having the data coming in and then that factory will have one work identify the format
of the data and then ingested the pattern is very similar to it but the factory Remains the Same Factory can Pro
produce several formats Factory can ingest several formats right so this is why we are going to use um abstract
class into it so sorry uh Factory uh pattern into it so as usual we we have created our own data ingestor interface
or interface for the data ingestor of what it will look like so the interface would more like that we want to ingest
so every every implementation of this interface will have every implementation of any format of data will have ingest
method so ingest method will take file path that what is the path of the file and will return the data frame because
we all always work in a data frame of course there are several other formats but in into into this project will be
working on data frame so over here um that will take file path and the file path type would be string and that would
return the data frame now why I am highlighting these that what is the type what is the uh returning and adding the
dock string and stuff like that the reason why we are doing it because if anybody comes and sees this they know
that if I want to run this class this will return a data frame that what it is going to be returning and then this is
this is what we call as type checkins so um over here you are telling any developer which is coming so that
maintains the readability of the code and that is what most of the organization look out for your in your
code so now as you move forward we want to implement one of because our data is in Z zip file we want to ensure that we
have the uh method sorry class which takes in the zip file and then possibly unzip it and and then converts into CSV
file and then Returns the data frame now zip data ingestor will take an interface that data ingestor is an interface that
you should have ingest method now uh that is that is an abstract method abstract is what something which is an
imaginary thing right so that is what imaginary thing now you have to convert those imagination to implementation so
inest data we'll expect a file path and return the pedi data frame which is extension of this ingest and then now we
go ahead and ensure that that thingss the file which is coming in is a ZIP file this is another important aspect of
it that we want to ensure whatever coming in so even if we have given it we want to ensure the file is a z file if
the file is not zip file we want to handle that error and raise the value error saying that the provided file is
not zip file now most the people what do will what they will do they'll simply go ahead and extracting the zip file but
they will not verify that things which is coming into me is really a zip file then only it will work so this is a
trait of a professional development or a data scientist or Machining engineer that they know to that they make sure
that whatever coming in is perfect for it to work now we are going to use zip file Library so zip file is a library
which helps you to extract so on zip file we give file path we give access to read it and then we say extract all the
data from it so it simply extracts the zip file and then once the zip file is uh extracted now there is the CSV file
which is in into the uh ZIP file out there so now if the CSV file is not there that's where so
this is the CSV file so we want to ensure that there are CSV files so when you list the directory so OS is where
you can list the directories of extract data so there will be another folder created extracted data and the extracted
data will have so it's like zip file you give the zip zip file path as a zip reference and then you extract all into
the new folder which is extracted data so it will extract whatever content is inside it the content is M msh housing.
CSV now that is the content into that particular zip file now you just go ahead and then look at the files which
is present inside the extracted data and then what you do you see that if there's you have this uh kind of a oneliner
thing for f in the extracted files if there is the files available which ends with CSV if that is then uh then you
simply go ahead it's like we handle another error so we say if length of CSV files whatever length if there is zero
which means no CSV files are found so we cannot go ahead and help you out into this but if this but also we also handle
another another case which says that if the length of the file is greater than one which means that are multiple CSV
files found please specify which one to use so they if they're multiple files you handle it differently so we we we
look at both of these things and then we go ahead and then we join the uh the the extracted data so we create that path so
that the path look like this that it goes extracted data slash your CSV files so I wanted to this is the basic things
which everyone should know so it's as simple as that and then once you have the path ready you just call c. CSV that
is the power of doing things very differently so over here we have learned several things right now and the the
main motor for you is to figure out when you work on new project these things should be key element of your project is
type checkin readability handling errors making sure that we are handling errors and fifth Rule Do not forget all
four rules out there okay perfect so now what we do because we have created because we have the zip extens we have
zip product ready we simply go ahead and create the factory it is a static method and of course I expect you that you
already know static method abstract method because it is the basics of python to be learned so you say get data
ingestor and what is the file extension and then it will return the data in justest a uh class which is this class
which is the abstract class that that is the type which you which we want to have so EV this this also this is a kind of
uh type which is being returned so data inor it expects the file extension and then it goes ahead and then ingests the
data now if the file extension is equal equals to do zip then one run the zip data in ingestor otherwise do not run so
it say no ingestor available for file extensions CS let's say Json so now let's say if somebody who needs to
create the Json they can just extend this abstract class to Json following or writing the ex implementation of the
ingest so this this ensures your readability and ensures your scalability aspect
too now the usage is I'm not going to run it because I'm going to show it you in jupyter Notebook as soon as soon as
you go it's more like this is our file path we take out the extension by looking at what exactly the extension is
by following this Deb determining the filing extension and then over here you are seeing we not hardcoding it we are
actually using that to figure out using the coding and then that CSV thing and then we getting the appropriate data
ingestor so if it was CSV so now that's another learning for you the learning is that if by chance if it is J you have
millions of formats and over here you have J Jason so every time you to change this file extension so you just what you
do you automate this process by looking at automatically over here and you just pass in this variable into this so it
automatically gets the extensions just by giving the file path you know you don't need to change file extension
every time you go so ingesting the data and loading into the data frame which is ingest which is the data ingestor it
ingests the file parts and then we print the data DF do head I want you to run it by your own I'll be also running it in
jop Notebook right now but this is what the inest data looks like I hope I was able to explain you very clearly about
how do we ingest the data into this and uh several learnings from it and now what we will do we'll go ahead and spend
an hour or so or probably less than that 40 50 minutes into the Eda which is exploratory data analysis and we try to
understand our data in a very detailed way before we get started towards doing more analyzing and stuff like that what
I want to introduce you to it's something known as Julius so Julius is something which I use use a lot because
it helps me to analyze my data better and they're doing very well and very good Community work and something which
I'm particularly very used to in my projects and uh helps you to give a overview when work towards uh creating
more better and understanding your data better right so uh I want you to first of all go to Julius AI because julus AI
is something you can go here it's it's more sort of uh analyzing your data so it helps you to analyze your data gets
insights do Advanced analysis you can also help ask it to do problem solving stuff like that and more interestingly
you can develop reports so something like this which is which creates a very big differentiator so we have not
utilize this whole into the course but I want you to utilize this by your own and possibly see what you can do with it
like you can do visualizations you can ask data questions you can do some quick experiments you want to do you can try
set several setup models by one liner of course it is not replacing it but it is helping you to make your task easier
that's what employers wants to see they wants to see you whether you are able to uh use kind of a quick things to
understand and save time in your original work so this is the Julius and I want to show you some of his
interesting feature because I use it very regularly is what you can do you can either go ahead and create a new
thread you can upload your data the house price data you can upload simply over here and then you can start asking
it more formal questions but at the same time what I want is I want you to see uh something known as threats which is you
can just go ahead upload your data or Google Sheets or or maybe some stuff like that you can start with data
visualization or probably they have they have lot of workflows so I wanted to go to the my workflows and then they have a
lot of workflows if I could show you um just give me a second I need to log in
it yeah explore workflows if you go to explore workflows there are a lot of
workflows which is available out here for example data processing data visualizations data cleaning statistic
bar chart education so I let's say that that you want to explore some visualization you go over here and there
are lot of workflows already available for you so so you don't have to create by your own but already available for
you like correlation Matrix grouped bar are probably simple in creating correlation principal component analysis
Freedman tests and much more so let's say that I want to go ahead with the cor correlation Matrix I click on the
correlation Matrix so what is the steps so it asks you to upload the data and then it will give you the uh correlation
Matrix shot so let's say if I visualize it so it's more like uh you run the workflow and then
you have to upload your data first of all because that's what it asked for is please upload the data so you upload the
data and then you ask any sort of task and then you execute this that it will automatically create a correlation so
there just like this there are a lot of uh into the data visualization same goes if you want to do data processing they
have workflows over here which is combined to csvs and they they're coming with a lot of workflows to make your
experiments quicker so you can start with all the core things over here itself and get things done so this was
this is what I use very often and they have a very nice Community forum and probably model lab and you can explore
the community forum is too good that you can get a lot of suggestions on your projects which I personally use so I
would suggest you to utilize it as much as you can and then probably see it's completely free tool there's no you know
I'm not doing any paid promotions and stuff like that it's completely free tool I use it personally I want you to
use it uh so yeah let me know u i want you to utilize this but of course let's get started with our original thing
which we have started to do so hi everyone we finally going to start with analysis one of my favorite part and
possibly I could say that one of the most important part into any project and we will not just follow a particular
framework we'll not just follow a set of that we should do this do that I'll show you that what was my decision thinking
involved what was my mindset before applying any sort of visualization or sort of plots or any as such so I'll
show you those decision or mindset think thinking so you develop a practicality of what Eda is about Eda is not about uh
following a standard Frameworks and then looking at it that's it for the for the sake of doing it but actually it is
important because it helps you to understand what sort of decision which I should make when I go into processing
stage feature engineering stage because you'll be noticing that I'll be taking several several insights from Eda in
order to decide which which algorithm I should use use decide the feature engineering decide what sort of
processing techniques needs to be applied and much more it also tells me a little bit hint about whether my model
fits the assumptions for the algorithm which I'm going to use or not so uh we'll spend a bit of time into analysis
and make sure that you fully understand it and again I want you to open up the documents and everything materials so
that you also follow me along now over here imagine your before going into our uh Eda stage I wanted to
first of all teach a little bit about strategy pattern and probably I'll teach you why it helps where it helps and
stuff like that so strategy pattern is an another design pattern so let's say that you're developing an e-commerce
application so e-commerce application is where you create some sort of payment gateways and all so customers can choose
different payment G methods like credit card PayPal Bitcoin Google pay UPI stuff like that so each payment method has a
different implementation but the overall process is the same that the customer has to pay so the process or the context
Remains the Same that they have to pay but the strategies differs but the strategy differs because some sometimes
they use credit card sometimes they use payal or Bitcoin so over here the we we create an strategy which is the payment
method which is an interface just like we were creating into our Factory that we create an interface that it that it
it it should look like this and then we create several strategies or implementations of those pay strategies
that credit card payment payal you develop a logic of it and then you have the context that every everyone needs to
pay that they they need to put in into a context that will be used to pay um so the context is that everyone needs to
pay the process remains the same but the implementations differs so I'm going to exactly code this out into one of the
explanations so I want you to go ahead and click on explanations and click on strategy design
pattern so strategy design pattern is probably same as what you have been doing in a factory design pattern but it
again has its own advantages and Powerful stuff which eventually you can use it into a project and which will'll
be using into the Eda part two now the strategy design pattern will have it first of all a strategy interface which
is which which we call it as a payment method so strategy interface will have its own method abstract method the
imaginary method that every strategy should implement this method which is pay now pay is where it is abstract
method you takes in the amount you can also go ahead and type set it's like string or integer or whatever now you
take that as an interface and Implement strategies it might be credit card payment or it might be you inherit that
uh abstract class and then you into the con concrete strategies so payment method payal Bitcoin UPI you can create
multiples and then you create the context the context is the shopping cart that everyone needs to pay so what sort
of payment method and then the checkout method so which is do pay which is everyone needs to pay into the context
into a particular shopping cart so you go ahead and create the shopping cart the strategy what sort of payment it
expects and then you pay card. checkout whatever the number is C checkout 200 for any sort of payment methods so this
is a simple explanation about strategy design pattern and we'll be using this into our
Eda or analysis because see the Eda is over here I I don't want to look anywhere I just want to look at this
analysis folder so analysis folder has ed. ipnb which is Jupiter notebook file you can use Jupiter notebook into this
case I use Visual Studio code because from starting from four years have been using using this one so I particularly
like this using into the V Visual Studio code itself but what you can do you can also do it on a jupyter notbook whatever
you have uh now before getting into this I want you to be very comfortable with uh what
this folder indicates so analyze source is the implementation so we'll be doing several plottings visualizations several
other things we have like data inspection missing value analysis Pate analysis univariate analysis
multivariate analysis so if you do this this will be very cluttered I want it to also be scalable so that anyone at any
point of time can use this so for that I have created analyze Source where the all the implementations and the logic
present in the source file and then Ed uses those source file in order to create visualization so that it remains
very small right kind of a jupter note because I'm not a big fan of implementing Logics because jupyter
notebook implementing logic in a Jupiter notebook does not makes you a big differentiator so over here we'll be
having the analyze source and all the implementations are done into the analyze Source
itself now if you go ahead and uh look at Eda so Eda I want you to first of all ignore all of this whatever the Imports
we are doing just remember import pandas as PD import napai as NP and then because we have already extracted the
data because I actually ran that inest data we all you also have the CSV file so we don't want to use that directly
over here we just can use the CSV file which has been extracted and then p. read CSV the so it assumes that you have
already extracted the data into the extracted data folder from the zip file okay so now once you have loaded
the data you also set the display options that you want to display maximum of 100 rows to make sure that it looks
very beautiful into the joper notebook that's why we just have the display options for the data frames and
stuff so the first step is any project that I want to know about the data I want to know how many number of a rows
how many number of columns what is the basic numerical things what is the mean median the number of accounts standard
deviation variance and all those details I want to know each and every aspect of that so I've created a basic data
inspection dopy and the basic data inspection. piy what it does that it does the basics of whatever inspecting
of the data is you can also copy the same code into several the projects because I've done a very very spent a
very very good time into documenting it out very nicely so that each even if you just go ahead you know each and
everything just by looking at the project itself so when you move ahead you have the abstract based class for so
as usual you'll create an interface that a data inspection strategy and the work of it would be to just inspect and how
it will inspect is by taking the data frame into it so the the general format so I this this is another learning for
you the general format for writing any doc string is as far follows that you write a oneliner description about what
exactly this method does what are the input parameters it takes into this it takes it is taking a DF which is a data
frame on which the inspection has to be performed and what is the type you mentioned over here and what a returns
it returns nothing because it is an abstract class right and then you just pass it out so that you don't have to
imple you you're not implementing it it is just an abstract based class for your uh inspection so I've also written this
class defines a common interface for data inspection subclasses must implement the inspect method so if you
implement another data inspection strategy but by following this interface they should imple implement this inspect
that is where your uh strategies come because as I say the implementations might be different but what finally what
do what they what do they have to do they have to just inspect it right so now as you go ahead we
create a simple one which is the data inspection strategies so we first of all explore the data
types of each column and count non-null values into it which is basically D DF doino which you which you guys do so
again you're seeing even the simple DF do info could have been done over there it has been elaborated nicely which
shows your readability for anyone comes coming over here right so it shows data types and non-null counts for every
column and then another strategy which again summar statistic inspiration in inspection strategy which inher which is
one of the subclasses of your abstract class which is data inspection strategy and then over here you create an inspect
and then takes the data frame what it does it prints the summary of it it prints the summary statistic of it of
the numerical columns and then it's it inspects for the categorical columns so both of it we have printed out so a
simple thing has been has been converted into a very nice set of classes sub classes which again make sure that you
we are not complicating it we are not complicating it this is what is being done by most of the people out there
good people so now because as as I say in into the payment case the shopping cart
was the context into this the data inspector was the context so what it does it helps you to allow to switch
between different data inspection strategies because one waye data types and inspection strategy another one is
summary inspection strategy right so it helps you to switch between separate just like in a shopping cart is able to
switch between credit card PayPal Bitcoin over here is it happens the same so it expects you to tell me what
strategy I'm going to use and then it just takes in the parameters of strategy strategy to be used for the data
ingestion and then it sets the strategy what sort of strategy needs to implement it and then it executes the strategy so
we create a uh self. strategy and then we set the strategy by the strategy G given into into our input and then we
execute that by calling the strategy do inspect because one of the method is do inspect from this so we just call do
inspect and then we give into the data frame into it very simple you just go ahead and that is what the whole thing
is so now if we go ahead to eta. ipnb you simply go ahead you in you import the CSV file the first step is
data inspector so you put in your data data types first of all you want to understand about the data types and then
you click on execute inspection which is a call execute inspection so when you call execute inspection what it does the
execute inspection will simply go ahead and then call this strategy do inspect so strategy which has been set it will
just simply go here and then call this method which is the subass method and then that will be run right so over here
when you run that you'll be having what is the entries what is the columns out there what is the nonn count what is the
data type of it so uh all of this you have 81 features out there of course you cannot see it everywhere but yeah that
is what you can see now we will come back to this once again because they are 89 we need to find a way that because we
cannot just keep on looking at non null nonl we need to find the specific ways to see where we have a missing value so
that's why we have missing value analysis systems ready too but now we also want to switch our strategy to
summary statistics so instead of instantiating the same method we just change that data inspector to set
strategy to the different strategy which is summary statistic inspection strategy so we do not have to reinstantiate it
right so data inspector again execute inspection it just goes back to summary statistics it's C inspect method and
then prints out for you for the numerical and categorical columns right so so this is what you get
in the inspection now um what we do we buil a story line out of it we I now what you can do you can simply go ahead
and click on open into view as a scrollable so now what you can do you can explore all these
uh columns out here and same you can just go and click on scrollable element you can go ahead and look out for the
detail summary statistics for the categorical summary statistics for the numerical now I want you to understand a
storyline behind it I want you to know about the story line behind it so let's let let me tell you what is the Insight
which I gathered of course you can take a brief look at the data and then come to these insights because I've already
taken a look I've written that out into the markdown so the data set contains 2,930 entries and 82 columns which is
very simple to understand and there are 11 columns with this 28 columns with this and this this is a very basic basic
uh you know whatever insights which which we could get now this is the major Insight from the summary that it tells
you lot of stuff out there now the first one is numerical feature so in numerical feature the
target variable the sale price which you want to predict that is the target variable which we are targeting because
there's several features and you finally want to predict the sale price has a mean of
8,796 with a standard deviation of $79,800 86 which is in indicating a spreading
significant spread in house prices like there is sign if you if you know about standard deviation that's I hope that
you're able to get it that they e spread throughout it the it now you'll see when when now over here they saw another
decision that how it is spread that is the another question are are is it too low or is it too high is it positively
skewed or negatively skewed so all these things you have to figure out that's one decision which I made is I want to go
ahead see what the distribution of sale prices because I want to know because it is showing a significant spread into the
house prices because mean that is and a Str deviation Serv 79,000 which is huge for the significant
thing another one is overall quality which is the quality of the house which ranges from 1 to 10 with a mean of 6.09
which is showing a relatively high quality and average and then what is the year built which is 1872 to 2010
indicating that the data sets includes both very old houses and relatively new houses into the data set lot area which
is the kind of area which is there has a wide range which means that it says that there is a maximum of 21
15,245 ft which might indicate very large properties but there's also concerning because if you're using
linear regression or any such algorithms there's several regression algorithms which is very effective by outliers and
they can potentially overfit and they can potentially ignore these kind value so first of all it indicates that they
are large properties but it also says that they are extreme outliers too the because it is because the mean is
180,000 it is getting lot I mean lot area is 215,000 which is huge which is a good big houses but also
at the same time extreme outlines we need to look at this aspect too another aspect in the numerical feature the
distribution of gr live area Ave ground living area which shows a mean of 40 99 squ ft with a wide range which could
significantly impact the sale price again we have to see the distribution of these numerical features very in detail
in order to get any resulting outcomes but what I really understood from you know going ahead and then
possibly uh roaming around and see what exactly it helps and all I feel that we need to look at the distribution of the
sale price and also I need to look at the distributions of of other numerical features and I need to handle outliers
at some point so these are decisions which has been made that is what my mindset is that it tells you something
then then you explore it further for the categorical neighborhood has 28 unique values with names being the most common
supporting some neighborhood might dominate the data sets so over here we are ensuring if there's an imbalanced
class data set problem Ms zoning is mostly RL residential low density with seven uni zoning types and Al has a high
frequency of missing values that's where I will come back to missing value analysis but Ali has high frequency of
missing values which we need to look at now there are other C category variable which is good good enough but we need to
ensure that those will be crucial in predicting the sale price so we also want to look at these those aspects too
so this is it about the data inspection the basic data inspection we have understood that we there is a problem of
outliers there is a problem of missing values we because there is a problem of skewness we want to ensure because the
algorithm which we're going to use is very prone to does not perform so the data is highly skewed or has a good set
of outlier so we to ensure that we also make sure that it fits the best to the algorithm so next what we want to do is
we want to go ahead and see the missing values see where it helps see the see the impact of the missing values and
then possibly we will see that how we could handle that once once we see the missing values we'll also go ahead and
then do the understand the single variation single analysis like well the distribution of the sale price
distribution of several numerical features where this qess is high and then we'll see that how those how two
two features relate with each other are they really affecting or are they following some sort of distribution
right so all those things we will do it so let's catch up in the next one hi welcome back so we'll continue
our analysis uh work and uh before analysis work I want you to again learn about one last
design pattern which we will frequently use into our sessions is template design patterns and then we will I'll teach you
a little bit about uh missing values and we'll try to decode with the missing value analysis so what is template
pattern so template pattern is another design pattern so the analogy is the best way to understand any design
pattern is try to think from a real world analogy so analogy so what happens that let's say you run a restaurant with
a set of menu for different Cuisines each Cuisine like Italian Chinese Indian Pakistani whatever so each Cuisine will
have its own sequence of courses start with the appetizers then main course then desert and then beverages so the
sequence is specifics to each and every cuisine so but the dishes Chinese different
might be Chinese dishes might might be different Pakistani dishes might be different Indian decision might be
different for example in India we have stars Beverages and stuff but the but in starus you might have some else but in
China but in Chinese dish your startus might be different or Korean so it depends heavily so the sequence for
serving the course is the same but the dishes served at each step vary depending on the cuisine which you're
having if you're going to a Korean restaurant the dishes will be different if you're going to Indian the dishes
will be different right so depends on the cuisine which you're targeting so the the let's say there's
an Italian meal the appetizer might be brussa the main course would be pasta desert would be tasu and beverage would
be glass of Vine in Chinese the appetizer could be string rolls main course would be noodles desert would be
cookies and the beverage would be tea right so if you see notice that there a particular overall dining sequence is
the same that is the template that is the same but the things which is customizable steps are the specific
dishes served at each stage which changes based on the cuisine which is which which you have so it's more like
the template pattern which you use is more like your changing five having the overall
sequence but having different set of uh steps so I'm going to show you which is the template design pattern so template
design pattern over here the interface will be a little different so interface would be Des dining experience and then
dining experience we'll have to serve a dinner serve dinner is first serve appetizer then serve main course then
serve desert then serve average beverages so the template method defines the skeleton of the dining experience
the what the skeleton should be now then you abstract method for each surf course because appetizer might be different you
might be giving another appetize you might be giving another main course depending on the cuisine out there so
then based on the abstract class you have you create concrete class that implements the Italian so for the
Italian if somebody chooses Italian so you actually this is a subass of your dining experience your s appetizer
serving this serving that serving this this is for Chinese and then you can simply go ahead Italian dinner so this
is Italian dinner. serve dinner so it follows a specific course right same goes with the Chinese dinner
out here so this is known as the template design pattern which we going to use some sort of into our missing
value analysis so we in the last one we have actually seen those things now what we're going to do is going to see if
there's any missing values into it if there is then how we could possibly uh look at it so we first create so anywh
you should always have a plan right so the abstract class is more like a plan or kind of a template so into this
missing value analysis template this class defines a template for missing values and the subass will have to
implement the methods to identify and visualize the missing values so that is what the plan for missing value
analysis I want you to also look at these dog strings in great great detail once you finish this lecture because
there a lot of things written in order just to understand okay so the analyze will
follow two steps identifying the missing values and identify the um visualizing the missing values so they will call two
methods the method would be you have to make identify the missing values and visualize those by taking the data frame
in so we'll create a simple subass which is the concrete class for missing value identification and then uh over there he
will also visualize it so it is it is a subass of this uh Missing value analysis template and then it has to make the
identify missing values and then visualize missing values so into this it takes in the data frame in and then it
says that okay I will missing values count by column so it's it DF do is null. sum I hope you know it it simply
it creates a column and then it for every column it has the number of if it is zero then it does not print if it is
more than zero it prints out over here another one is visualizing the missing values so I'll explain you what exactly
it does so the first step is that we want to make a figure so we want to we take a page right so it creates a figure
of 12 um the the figure will be 12 in wide and 8 in tall that is the size of the plot should be you can also play it
around if you need a little bit more and then you're going to use Seaborn Library so we implode caborn as SNS and uh I use
that to create a heat map heat map is a library where we can look at the you know correlations missing value analysis
lot of things we can look at from here so the heat map will contain DF do is n so it creates a data frame of the same
shape as DF so it will have the you know shame SAE so it will be more like let's say the DAT data frame is a
I'm just going to write it a 1 2 3 4 then you have B column name again you have
1 2 three four right so now over here uh this is the data frame now let's see if
this has a n non value this as a nonv value so it will the DF do is n will create a data frame something like this
so in Nan values if so it will create a I'll just copy and paste it directly it will create this data frame but it
there will be slight difference it will create it will with the Boolean value so if the missing value is present then
it's then it will write true but if the missing value is not present it will write
false so it will return something like this it it will return some something like this data frame so your heat map
will be built on top of this data frame right so you given this um DF do is no it will be a data frame where it will
indicate stuff now c bar is equals to false so c bar is in kind of uh uh disables the color bar of on the side of
the heat map you can try true and see how it works but cbar is is more used when you have the um binary data sort of
thing but it is not but it will not add any sort of in information what is the color map the color map of this cmap
should be verdis so what does verdis means it will be like a which it is like a color gradient which starts from the
purple to Yellow so if if you have the in in in a particular column if that is looking purple then then there's no
missing values but if it is looking but if it is yellow then there's some missing values so I want you to go ahead
and see it so now what I'm going to do I'm going to Simply simple value analysis so over here we are also
importing it if you truly see from Analyze source. basic data inspection we are importing this data inspector class
data type inspection summary statistic from value analysis we are importing simple missing value
analysis so we import that then we give the we call analyze and the we then it gives this particular column before we
because we printed out to identify those and then it gives this heat map too so the heat Maps over here you can see the
purple is where there is no no value of no missing values but whenever there is yellow there are missing values
available so you see there lot of columns which has a lot of missing values available out
there so there are a lot of insights I have written so over here yellow represents the missing values the more
yellow the column is the more the missing data into that and then purple or dark color represents the non-missing
values that uh that that indicate the most of data is present if there's purely purple out there right so there
are a lot of columns which like lot Frontage mass vener mass vener area Garage pool area they all have the
substantial yellow kind of so they have the sort of missing values another one is that if the yellow so there is two I
want you to know about the randomly distributed because nobody knows about it because I I was also into the initial
stages when I actually know no knew about this that there are two types of distribution of missing data which is
randomly distributed and structured missingness so if the yellow marks are scattered without any noticeable patter
PN it suggests that missing data might be randomly distributed that there's no correlation between any of it but if by
chance it is structured missingness if the yellow is stru clustered in a certain rows or columns it might
indicate a nonrandom pattern of missingness which is very kind of good thing or also bad thing at some sense
for example entire rows or columns might missing could suggest a data collection issue or that these features are not
applicable in those cases so you might not want to remove it right so these all are the very crucial decision which you
have to tell so now we have also written I've also written these have this number of a
column single missing values and all so from all of this Insight what do We Gather what sort of issues to be
addressed the first one is we need to address the missing values there are moderate missing values there are
significant missing values or there are single missing values so how do we address this maybe sign significant we
go ahead and drop these columns entirely as they we don't have the data they don't add a significant value or we
Implement with some missing values moderate in which we we can put it in with some zeros for numerical ones or
maybe missing values could be filled with no basement or no garage for categorical depends on how we going to
handle it I hope you have seen feuture enging lectures then it will only start making sense and then we have single
missing values these can be fill buil with mode or mean for categorical so we can just take mode and then put it over
there now we have also seen there are a lot of issues of outlier detection like there are lot of uh features which has a
huge outliers and uh we also need to categorically encode it because we
machines can never expect English you need to categorically in encoded I hope you know what is categorical encoding
and then feature engineering based on the inside certain features needs to be engineered like combining related
features creating International terms or because there are qess we need to also figure out how do we transform his qess
to normal distribution because regression works on the normal distribution because it is one it is it
should be normally distributed then only it will work and then as as as I say the correlation should be good so we need to
also see the multicolinearity because this is one of the assumptions of regression so we need to look at all of
this which we're going to look at in univariate multivariate and bivariate analysis so let's go ahead and look at
that aspect too until then bye-bye so now what we will do we will go ahead and uh
possibly uh do univariate analysis so the reason why we are doing univariate analysis because we have found that from
the whatever insights which we had that sale price is somewhat distributed standard deviation is 74,000 that means
it has it is somewhat uh distributed and it's kind of significantly distributed it is not normally distributed that is
one I want to know because because for working of algorithm uh linear regression which we're going to use you
need to make sure that it is following normal distribution so we to look at the distributions of our Target variable and
then possibly go ahead and see if there's some something can be done so we look at our distribution of our one
target variable and then we look at for categorical variables and stuff like that so what I'm going to do again it is
going to be probably the same design pattern which we going to use and over here uh what we going to do is we're
going to create first of all an simple abstract class simple abstract class or strategy which is univariate analysis
strategy and it will have a simple method the which is the analyze so every strategy will follow this analyze method
it will take the data frame in because it is a univariate which means it will do the single analysis one column for
only single feature right that's why it's a univariate analysis so it takes a DF and then the feature which is what
feature to analyze so it will ask these two information from the user then we create strategies the first strategy
which we're going to create is numerical univariate analysis because we want to first of all analyze the numerical
features it is a subass of unit variate analysis strategy and this is one of the strategy of that strategy abstract
strategy class now here we'll analyze it the an analyze will take a data frame in and the features in so data frame will
be more like a pandas data frame and the features would be more like a string and then it plots the distribution of how it
is distributed is normally distributed positive distributed negatively distributed and stuff like that so it
eventually has this parameter and then the feature and then we you we plot that so we again figure 10x 6 in and then you
you plot a histogram because you want to see the histogram I hope you already know what these histogram are we want to
plot for the this feature we want to KDE is equal to 2 I'll explain you what this KDE means and the bins equals to 30
which means I'll also explain you what these two three means so we go ahead and uh plot that particular thing so we
import first of all univariate an analyzer which is this particular class and then we give numerical univariate
analysis because we want to do the numerical stuff and then we click on execute analysis giving the data frame
and the particular column name so when we do that we get something like this visualizations for our Target variable
now kte means that it gives it's it is a kernel density estimate it is a line it is it it it adds a line to the histogram
which represents a smooth version of a histogram because if you see that the this this line which is going it is a
smooth version of a histogram which better estimates the distribution of the data you can better see it from here
right and the b equals to 30 means that it specifies the number of bins or the intervals for the histogram because
you're having several intervals out here so what should be the proper intervals so which is which have set to 30 so now
I'll so now let's say if you increase the more number for bins which means that it will provide a more finer
granular granularity for the distribution but if you have fewer bins it will show more coarser view corser
overview sort of things so if you want to look very in detail then you increase the number of bins but if you don't do
not want to then it's a corser uh overview you will get right so uh but com coming back to this we create an
abstract method that abstract is a strategy pattern which which has this analyze and the numerical feature
numerical analysis is a subclass of this strategy which is one of one of the strategy and then you potentially plot
an histogram giving the title The X label and the Y Lael for the same and then you click on PLT do show which
means it eventually shows the image we create another strategy for categorical features so that this strategy is for
categorical features indeed and what it does so it it analyzes the categorical feature by plotting their frequency
distribution so over here for categorical we going to plot this particular count plot so count plot is
kind of a more specified version so if I could show you this is how it looks like so we set the strategy instead of
reinstantiate that class we just set a strategy to categorical univarate analysis and then we execute the
analysis on this data frame for this particular column which is neighborhood and this is where you have uh several
like names Gilbert Stone be names stommer badel and all these so you get the count plot for this two same happens
what is the X what is the data and what is the pallet VI we want to have what is the title X label y label and then at
last show so this this is the um we this is what we use for analyzing the
categorical feature now if if I if I go ahead and show you what is insites which we get from the univariate analysis it's
more about that the sale price distribution so the distribution for the sales price is positively skewed because
that's what I was telling because most of the majority of the houses were falling between 100,000
250,000 which means that if you see over here it is$ 100,000 to 20000 50,000 most of the prices right so that's where most
of the things lies in and the peak frequency is around the 200,000 Mark which is the most number of uh houses
are around 200,000 Mark right $20,000 so what does it mean that skis suggests that most homes in the data sets are
relatively affordable of course it's 200,000 for the real estate is very affordable with fewer highend properties
there are very few right so it also suggests that the long tail on the right side which you see that's where your uh
expensive items SC comes into the plate and which may need a special consideration during modeling right so
that your model looks at the highend prices too so for that if you have seen my future engineering lecture you must
be knowing that we can possibly apply or use log normalization log transformation to normalize this this distribution to
follow the normal distribution uh Assumption of linear aggression right so that's where another learning for you
that if based on the implications that okay TW is because there are a lot of there are there are some uh high-end
properties we could apply log transformation in order to normalize this in order to follow make make this
follow one of the assumptions of linear regression now as we move forward there is another one which is the neighborhood
distribution which is the categorical feature so what does it mean this shows a VAR distributions being the most
neighborhood followed by college CR old town and all so the higher frequency of now what is the implication of this this
is another uh understanding is for the certain neighborhoods suggest that there are areas who could significantly
influence overall pricing value so if it is names then it can overly influence overall so it is the problem of
imbalance class problem because there are several areas which is lower but you need to handle it very carefully
otherwise what will happen if there is problems of over fitting will start to happen problem of uh uh you know not
model being not able to intelligent recognize overfitting will start to happen because there are very few
observations because for the certain uh categories there are very few observations so your model M completely
focus on few observations which has the highest number of U rows right so you need to make sure that overfitting does
not happens that's where you apply regularization techniques or probably frequency encoding and all those things
comes and comes into the play however we'll be not focusing too much on improving it because there are lot of
things which will be given to you for sure by the end of it to to improve it by your own also so that this is
something which you which which you learn on the go so um this is what the univariant where we understood our
categorical one of the one of the target variable and one of the categorical most important variables you can do the same
for other numerical features other categorical features along the way because for me it was more like that I
wanted to show you that how your decision process thinking should be you can go ahead figure out tweak tweak it
around find more numerical variables see what exactly build a story line on top of it so what what you can do you can
say that okay if the price is this much then the then the you could possibly predict by taking the mean or the distri
looking at the distribution of other numerical features right so there are a lot of things which you can do into it I
want you to experiment it out by your own and see how it helps you now into this now now into the next one I'm going
to show you how you can compare two variables which is by variate analysis and then see what it
yields go ahead and learn a little bit about comparing two variables and probably seeing the relationships
between them comparing two features and seeing the relationships between them that's what we call as a by variate
analysis we'll try to follow the same strategy is the strategy pattern so we'll create an interface which is by
variate analysis strategy which takes the data frame in is an input feature one and the what kind of second feature
to be analyzed so these these two features will be analyzed and the method will visualize the relationship between
these two particular features so now we'll start implementing it the first we'll Implement is numerical values
numerical analysis which is numerical versus numerical analysis which means um we'll
put on y AIS numerical X numerical and then we'll try to relationship between two of it so it takes in as an input of
a data frame and then it pulls out a feature one and the feature two and uh We've set up the size scatter plot I
hope you know the scatter plot X should be feature one y should be feature two and the data where it should take the
these features is the data frame which we ask for and then we show so the third step as I told you that we want to do
the Y variate analysis so we want to analyze the relationship between two numerical features with is ground living
area and a sale price so we instantiate byw analyzer giving them the numerical versus numerical analysis and also we
have already imported numerical versus numerical um from that file I hope you know that how to import all of this you
can look at the file that we have imported it and uh then possibly we just click on execute analysis we give the
data we give the first we give the second so the Y exis so you just must know that sale price should be on y and
ground living area on X so now if you see that this is the scatter plot so what do we infer from the scatter plot
how do we interpret it so that's what it is written over here that there's a strong positive correlation between the
Ave ground living area and the sale price that larger homes generally sell for higher prices which also indicates
that the data is correct because larger homes will obviously sell for higher prices right and over here it appears to
be very linear that's what the model expects if you see the the the thing is very linear but there is one issue that
there are a lot of outliers to there is some outliers to which needs to be looked at so it it validates the
linearity Assumption considering that there are some values which is out of the L linearity line so we need to look
at that aspect too so the linear relation confirms that there is a strong relationship between the ground living
area of ground living area and the strong predictor of sale price so which means that if you give me the so the
model says that if you give me the above ground living area I will tell you sale price with higher confidence which means
that it is a very important feature but there is a presence of outliers uh which require a further
investigation or maybe treated or has to be removed from the data in order to avoid any potential concerns or issues
into our model so so I want you to try out with more features I want you to look at whether they are a strong
predictor or Not by looking at it by looking at the sales um scatter plot so it helps you to better understand these
paradigms um apart from it I wanted to try that out but we can also um try out categorical versus numerical analysis
which means that we can have another strategy which can analyze the relationship between the categorical and
numerical feature so what does it mean that we will first of all analyze it and then we'll have a box
plot so what it does it plots the relationship between a categorical and numerical feature I I'll further explain
You by taking taking one example so if you go here by the way this is the context class which sets the strategy I
I have already explained and executes the analysis by calling that do analyze feature by by the strategy which was set
so uh if we if I show you this is what we trying to do we are trying to analyze the relationship between the two categor
a categorical feature and a numerical feature so categorical feature is the overall quality of the house which
ranges from 1 to 10 and the sale price which is our Target variable now if I could explain you what this this box
plot means and of course I'm I expect you that you already know some of the technical details of it that xais into
this represents the overall quality variable which is likely categorical variable indicating the quality rating
of houses which ranges from 1 to 10 and the y axis over here represents the sale price which is the T Target variable
which is a numerical variable showing the price at which houses were sold so what does these boxes indicates each box
represents the inter quartile range IQR so-called IQR I hope you already know it of the data for a particular quality
rating so for for a one there is intercord range for the two there's intertile range there's three for 10
there is a intertile range right so the IQ spans from 25th percentile to 75th percentile of the sales price and the
line inside it so the line inside it indicates the 50th percentile over here so that's what the box plot is I hope
you know the difference how do how can we interpret the 25th 75th or not the the viskus the the line which
you call it is known as the viscus it shows the range of the sales price that not considered outliers so if the value
Lies over here then it is not but these blue these circles are the outliers these because these are outside of the
viskus that's or which is uh which is the outliers into this case so that's why we use box PL to analyze the out
outliers too so the dot outside the viscus represents outliers which are sale price that are unusually high or
unusually low compared to the rest of the data just mark my statement the dots outside the viscus which are seeing the
circles represents the outliers because the sales price that are in unusually high or unusually low into this case
compared to the rest of the data which is available out here so what do we observe from this so we see that overall
quality rating increases from 1 to 10 the sale price also tends to increase which means we also seeing a linear
relationship because if it truly increase the number of U in rating the S price also tends to SC that makes sense
if the quality of the house is good then the sale price will also be very nice but if the quality of house is bad then
the sales price would be very less so it suggests a positive correlation between the quality rating of the house and its
sale price so you can say that it is a very general statement to say that if the if the house quality is good it's
going to definitely you're going to sell it for a better price and then you can tell to the stakeholders that this is
the price which you can sell it that's where you use data science to make thorough data
decisions now higher quality ratings show a wider range of sales price which indicates more variability in the sales
price of higher quality homes so which you can see that there are higher variability into the high ratings house
too so I hope that you understood how can we analyze you can take more learn about correlations how you can look at
it how you can build a story line out of it how you can help this to make the guys to make better decisions and all
sort of things can be inferred from it so I've written the same over here that you can look at
the Quality out here and the answer the answers out here right so what do we whatever we have done univariate by
variate missing basic what do we conclude we conclude that both are strong ground living area overall
quality as very strong price predictors these features should be emphasized on the predictive models however this is my
inference you must go ahead and try out because there a lot of features I want you to go ahead and try out that what
features might be possibly the strong predictors of sale price right and then the data distribution the positive skew
of the sales price and the wide range values of ground living area and overall indicate the need of careful data
processing which means that it does not follows the proper normal distribution which is needed for the regression
algorithm right so we need to do the very nice transformation or normalization of our data another one is
outliers so outliers in this relationship between ground living area and sale price needs to be examined
closely because again uh we do not want our model to not address this luxury home so we want to also make sure that
this has taken inside the data and model is learning from it so I hope that this makes sense now
we go into the last part of our uh analysis which is multivariate analysis so let's catch up that up in the next
one we'll get started with multivariate analysis which is the last part of our analysis program and uh so let's quickly
go to multivariate analysis and it is pretty simple again it is it follows the same strategy pattern or sorry template
pattern into this so it defines the template for performing multivariate analysis out here and sub classes we can
override specific steps like correlation and stuff like that in order to increase it so multiv analysis will involve two
things which which we'll be doing we'll be doing generate correlation and generate pair plot because it is not
technically possible to do you by variate by looking at so it pairplot generates the overall summary of
whatever happens with the features how they engage with them what is the correlation between them and all those
things which is needed so that's why I love this uh pair plot and heat Maps will tell me everything which is needed
what is the correlation involved with each of these features with all the combinations out there
there so I'll create an interface the interface will look like this that this will have an method called analyze and
then analyze will simply perform a comprehensive multivariate analysis by generating a correlation heat map and
pair plot so it takes in the data frame whatever needs to be analyzed and returns nothing
because why it's because maybe it me the method Orest because the it's more about orchestrating the correlation and then
that's it there's no returning out here now we create the generate correlation by giving so generate correlation is
another abstract method and the generate PID is another abstract method which we have to overwrite so we create first of
all we do the simple multivariate analysis there's nothing we we'll do very very complex we'll start with the
heat map first of all we'll generate a correlation heat map by giving the data the size will be 12 x 10 and you just
take out the correlation of it by core an annotation 2 cmap equals to cool warm all of this you can get to know as SNS
do heat map you'll you'll be knowing each and everything what does it mean what does each parameters mean and what
do they expect in return so I want you to look at the document too if you want to know more about in detail and what
sort of things can be involved into this as a parameter the title correlation heat map and then PLT do show so it
generates so now on on another pair plot we could say that okay we need to generate the pair plot so SNS do
pairplot we just give the data frame it will automatically generate the pair plot for the selected features whatever
which is mostly the numerical featur which will be selected so this is what the multiv we import the multivit
analysis and then we go ahead into doing this so we simple multivariate analysis which we import if you truly see in the
top we have imported it is from multivariate analysis analyze. Source multivariate we should import the simple
mered Val multi analysis and then what what we do we simply uh select the features because we just want to get the
for these seel selected features which numerical features and then we analyze those selected features because that
will select the selected features out there so this is what to make it more simpler and understand you can also
change the selected features to make sure that you truly understand other features too now over here if you truly
see if I could explain you what this really mean all these um uh scatter plot and all so the pair plot shows five
variables into this which is the sales price ground living area overall quality total basement square footage and ear
built and each row and column each row and column let's say this one represents the relationship between one of these
variables which is relationship between the variables of sale price and the sale price right so it will be possibly same
for for the sale price with the ground living area is 0.71 right so that's what it means the diagonal which you're
seeing everyone one it shows the distri which is like more sort of a 100% correlated because sale price is exactly
sale price ground living area is exactly ground area so the the com the correlation between them is 100% but the
correlation between sales price and uh uh ground living area is 0.71 right so um all these things out here you get the
correlations and stuff like that so say the scanter plot between sales price and ground living area shows
a positive relationships which we have seen and the living area ground living area what is positive relation if that
increases If X increases then y also increases this suggests that larger houses tend to sell for more prices same
goes with sales price versus overall quality so scatter plot between sorry um the heat map which which which which is
over here suggests that you know uh more the better the quality is better the sales more the sales sales price are so
just to come to this uh blue colors represents the negative or low correlations meaning that variables are
not highly correlated which also means that inversely related and red color means that there is a highly positive
correlations meaning that variables are highly correlated with each other so what does it mean one indicates the
perfect positive correlation that they perfect positive correlation which means that as one variable increases the other
also increases at the same time so sale price increases the sales prices also increases mostly they are same
right minus one indicate the perfect negative correlation which means that if one increases then other decreases but
they these are all the the detailss which you have already had a talk but coming to the how do we interpret this
so let's say that um uh sales price so how do we interpret this sales sales price correlation of the sales price
sales price has the highest correlation with overall quality which is 0.80 right now so if you see overall quality with
the sales price is 0.8 which means that overall quality tend to have a higher sales so houses with better overall
quality tend to have higher sale prices now if you go to the Modera positive correlation which is the ground living
area or total basement Square fet which is if you truly see total basement Square F feet with a sales price 0.63
and then ground living area which is 0 0.71 which means that larger houses and houses with larger basements tend to
sell for more but uh the one uh sales price has a moderate correlation with ear built for example 0.56 that's what
we call is a moderate correlation not moderate positive correlation but it is moderate correlation which means that
houses that suggest new houses tend to sell for more that that builds a good story right for that will also help your
uh stakeholders to better understand same goes with like let's say ground living area so ground living area
suggest a moderated positive correlation with sale price as we see 0.71 it also has a moderate correlation
with overall quality indicates that larger living areas tend to be associated with higher quality homes
again be very careful when I say this so what I say this that ground living area if you compare that with overall quality
which suggest which is 0.57 into this case which says that which ISS a very interesting Insight that larger living
areas tend to be associated with higher quality homes that's one of the Insight now if you say that there's a low
moderate correlation with total basement square feet and a low correlation with ear build which means it does not
affects the sales price and all those things so just like this you can interpret for other um uh correlations
and make sure you build a story line out of it I've already built a very nice story line I want to look at the pair
plot scatter plot story which I written out here you can write it in more detail now this is what we this is the scatter
plot which we have I want you to understand it so pair plot shows for again the selected features and uh the
diagonal plot the diagonal plot shows the distributions of each variable whatever the variable which which we are
having now let's try to interpret one one by one I'll I'll not do everyone but I'll try to interpret one one by one so
let's say sales price to ground living area right so scatter plot between the sale price and the ground living area
looks something like this which shows a linear relationship so it says that it increases then the sales price also
increases same goes with the overall quality so now if you go to the overall quality and the sales price this scatter
upla shows overall a positive correlation positive correlation which means that houses with higher quality
tends to be more expensive now if you truly see this total be a basement square fet footage which says that the
scatter plot shows again a poster relationships but it is less strong compared to ground living area and
overal qu so these two are more important than this so if there is a data issue then you remove this instead
of removing this so all of this is uh helping you out ear built so shows that uh newer houses tend to have a better
housing price right um same goes with other if you truly see that's how you can interpret other relationship and
stuff like that over here Itself by choosing right you know what is the correlation if it is positive negative
um I mean inversely directly whatever you just need to figure it out by your own it is very easy to understand so I
took you some example you can look at the pair plot which is listed out here answers to it the the the nice stuff
which you can see over here now what needs to be addressed multicolinearity feature engineering and
outliers so for example over quality is an ordinal which might benefit from it so we just need to encode those overall
we do not want to treat overall quality because it just ranges from 1 to 10 values so to ensure that this is more
sort of a ordinal value rather than the continuous value another one is lock transformation because sales price is
positive schedu and regression accepts that uh accept some normalization so we need to work on that there are a lot of
outliers too so we need to work on that to multicolinearity as I said that lineation expects that you need to have
a uh normal distributed I mean variable so these three are the issues which we will
address into our next set of lectures so now we have analyzing done we'll go towards this
particular Ines um feature engineering we'll work towards handling missing values and then data splitter model
building outl detection evaluator and then we convert those things into zml pipeline because we'll be once once we
complete the understanding of these you have done core ML and then we'll go ahead and try to integrate mlops into it
so I hope that it makes sense we'll catch up in the next one hi so finally we are going to get
started with making pipelines making steps actually model building and lot of things after whatever we have concluded
from our insights because as I told that we'll take another hour to finish this project but our 1 hour just got spent
onto analytics which will make super easy for us to take decisions on what sort of methods we need to use what sort
of plan we should have so that help us to plan our future thing together so that is why I love working on to uh
analysis a lot because as a data scientist it is your work to spend a good good set of time into working on it
so before going to that I want you to first of all go into the uh zml document and zml document is a very nice document
and now they have made it simply because when I was back in zml I think things were little uh I mean messy and they
were still at developing stage in the core stage but now they have developed a lot and have explained the amops
Paradigm in a way that nobody could ever even touch so that's why I always refer to whatever I can and that's where we we
going to use ziml and I hope that you have followed our PDF document because please ensure it will not work if you
have not followed our installation video so I hope that you have your installation video ready and that in
installation video should have your zml installed your stack set up with ML flow experiment tracker and MLF flow
deployment and everything should be ready into that so that I do not so so that you don't get error because once
you start getting error you'll start scratching your head and you won't get anywhere so let's get let's let's go get
going ahead and over here I want you to first of all um if if you don't know about ziml come here learn whatever you
can about what is the concept of pipeline what is the concept of Step but I'm going to touch this in a very
briefly basis and what I could do is I could possibly may help you understand what is pipelines and what his steps are
so pipelines is like a pipelines um so kind of a series of steps so uh you should first of all start with ingesting
the data then you should process the data then you should handle the missing values then then you should handle the
outliers then you should hand so it's kind of a step St by-step orchestration so that's what pipeline means pipelines
means you make a pipeline in that you have stepbystep procedure to follow right so into this right right in case
of my front you have input then profiling and then train and then go and evaluate and all that happens under the
ziml pipeline so so I I don't I don't want to go on artifacts models parameters and all
because I want you to look at it but the concept known as local stack so local stack what does it mean that over here
Will using ml flow I'll also tell you I'll come back to this stack once again but over here we'll be using ml flow for
tracking our experiments and ml flow for deployment and you want to tell ZL that I'm going to use that right so local
stack will have or Python orchestrator and artifact store but also experiment tracker to be ml for you want to
indicate those into your stack so all of this is very important so we'll I'll come back to Stacks once again so that
you understand it but I before I want you to look at it and be very comfortable with what this Pipeline and
steps are you can continue with this lecture but I want you to be very comfortable with what these pipelines
and stacks all these things are okay so now let's go ahead uh what I what I want to do is uh uh go ahead and
then start off with the planning now of the pipeline so I want you to go to the training pipeline so create a pip
pipeline folder and go to the training Pipeline and the training pipeline forget all the Imports we go back go one
one by one okay into this you create at theate pipeline using a pipeline decorator and then over here you want to
import model so model is which means that we're going to create a model into this into into this pipeline whose name
will be prizes predictor model right so we create a unique model so that anyone anyone can access the whole pipeline we
are just we are just just prizes predictor um name so that's what I want you to first of all write it out over
here of course it is that you import from zml the model Pipeline and step and then you use that model and then name
that as a prices predictor so if you could go and check it out it's kind of the model which so that you in a
pipeline you have you're having a model known as prices predictor so we'll create a pipeline definable Pipeline and
this is an end to-end machine learning pipeline so any pipeline will have its first step as I what I talked it's about
data ingestion step so we have already looked at the data ingestion step if you go to the source file and then go to
ingest data. Pi we have already completed this ingest data in detail now we need to convert this ingest data into
a ziml step so how do we do this we just go ahead and say that from source. inest data we want to import the ingest data
Factory because Factory is where um you can switch your extensions and then say file extension whatever file extension
right now we are dealing with zip file so we say dotzip and then we say get data ingest which is and give the file
ingestion and then it inest so we just did this will act as a function which will take a file path as an input and
then we'll give the file path for to ingest and then it Returns the data frame so you can see file path is string
Panda's data frame is an output now we see the pipeline we raw data is equals to data We call we just import from
steps this this is a step folder we import data inje step from the data inje step file so you give the file path and
it takes the dotzip because it is an extension and it calls do ingest and then it inest and then it gets raw data
into it now the next step which we want to have is H how do we handle missing values into it how do we handle missing
values because we have seen there a lot of missing values in 2 hours so we need to also handle the missing values so we
have done with the injest data we'll go to the handle missing values do PI which is the source where all the logic has
been written now I'll go step by step so that you understand it very in detail now
first of all we set we import the loging logging is where is it it it is module to display log messages because you can
zml sometimes some Zen zml you cannot in the pipeline you cannot have print whatever you should have the logging
system ready right because logging is what zml uses it and there are other like print Ln and all so the logging
module is configured to display log message with specific format for example we want to ensure ASC time what is the
level name log which is the log message log level and what is the message what what what was the tracking so that it
helps you in a debugging so that's what the configurations were set now then you create an abstract based class that
defines an interface for handling missing values that's what we are trying to do right so it uses the ABC you know
module which is abstract based classes to enforce that any subclass must implement this particular handle so the
reason why we have this so that any subass which extends this must implement the handle so values is kind of an
interface now if you go ahead it takes now this handle will take a data frame as an input and we'll
return a data frame with missing values handled the first strategy which we are having is dropping missing values so it
inherits the missing values and if there's anything additional to take it that take it and what X's it needs to
have for example uh over here it defines whether to drop rows or whether to drop columns so that's what X's is needed
because we want to know whether to drop rows or whether to drop columns in this case we want to drop rows that's why X
is equal to zero and threshold which means that the minimum number of a non non values requir to keep the row and
column so if the rows SL columns with fewer than thresh values the non non values are going to be
dropped okay so these are the AIS and thresh and then you create because it is mandatory
to have the handle it say loging doino dropping missing values with access and then threshold DF cleaned uh drop now
you get the access and threshold you give because you have already taken as an input and then you say loging INF for
missing values are dropped and then you return the DF CLE there's another strategy there's another strategy which
we which is concrete strategy for filling of the um missing values so this class implements the handle method to
fill missing values using various methods either by mean median mode or any value which you which you would like
which which we which is known as the constant value which you want you can also put constant value 10 11 12
whatever you want but the default is Method we want to use as mean and fill value is equals to none right we we
instantiate that thing method and fill fill value and then we make the handle class so handle class is made as
following that we first of all copy the data and if method is equals to mean then you select the data types that you
get only the numerical columns and then what you do uh and then you particularly go ahead
and then fill the null values of that particular numeric columns with the mean of that column okay same goes with
median and same goes with Mo so and if you have the constant then you fill the null values with whatever because it is
none right now nothing will be filled if you put I mean constant then you have to put some something in here otherwise the
value will be none so it will it either fills with mean it either fills with median or it FS with Mo or with a
constant and if this anything comes if this another metod somebody passes then it says missing values sorry unknown
method no missing values handled and then it says missing values filled that's what it helps you in debugging
that every you log every messages of it and then what you do you simply have the context class which we usually do so the
class maintains a reference to a missing value handling strategy which is a strategy that we are that we have
created an interface for and then and delegates the task of handling missing values to it it allows switching between
the different strategies dynamically so you can set the strategy and execute that strategy which is handle many
missing values which is do handle so you set so that you don't have to reinstantiate again and again to make
this work right so this is an example usage that we take a data and then we say missing values we want to drop
missing values so you just simply call DF clean. handle now you don't want to drop missing values you want to follow
the mean method to fill the missing values which is you set the strategy and then you follow the mean method and then
do handle and then you give the data and then you get the DF fil so this is an example usage what we're going to do we
going to convert this into a step which is the handle missing values step so handle missing values will have
this following we first of all import pandas as PD from source. handle missing values we import drop missing values
fill missing values and missing values handle which is an abstract class and then what it does that it takes data
frame as an input and what sort of strategy is to have the default one is mean you can override it by median mode
constant and then it says if the strategy is equals to drop then missing value Handler will take drop missing
values as in strategy and then possibly give that you need to only drop rows and then it starts to drop rows but if the
strategy is mean median mode constant then it's then you call the abstract and then you say I want to fill missing
value strategy with the method of strategy and strategy which you have taken is an input which is the meaning
to this case or else you raise value errors unsupported missing value handling strategy right and then
whatever Handler is there you just handler. handle missing values by giving it to the DF and then you get the clean
DF out from here so then once you have this you simply go into training pipeline which you have created and then
fill data and then you pass in just the raw data so how it works you you simply go you pass in your data frame because
strategy is mean you want you don't want to change it so you keep live it on mean and then it goes to your abstract class
then abstract class sets the strategy of filling mean values with mean value and then that executes with mean whatever
the code logic we have written and Returns the data frame with filled mean values I hope that it makes sense it is
pretty simple to understand it just that it is a way to do it I love this space and probably I love the way it works out
and then now let's run it so the way you can run it is you can just go ahead and then call python run pipeline right so
what it does I just need to fix up some of some of the warnings because I'm using some sort of unsupported uh ziml
behaviors and all so what happens that initiates a new Run for the pipeline ml pipeline the new
model versions was created and it says models can also viewed in the dashboard and all so because I said that I use a
stack of local wheel to I hope that you have read the document on setting up this project first so please set up the
project first before continuing this is the dashboard URL if you truly click on it you'll be seeing this dashboard and
it says data inje step has started and then it outputs a code data frame and then it goes to handle missing value
step and it outputs a core data frame too right and then it says data inje step has started because I've already
run it it says we are using a cache version you say Steed handle missing has started it's using a cash last version
of this too and it says it has been finished in following time so we have done with this now the next step which
we're going to do is we're going to do the feature engineering which is lock transformation to make sure that we
things are normalized and then we're going to work on the outly detection step which means that we'll detect if
there's an outliers and handle those outliers and then we'll split the model into training testing and test split and
then we train the model and then we evaluate the model that's it so that is the pipeline which we are looking at so
let's come back in the next one to talk more about feature engineering and outlier detection
step so hi everyone uh let's come back to our project and the project indicates that we have completed till handle
missing value step now we have also seen that there are that our Target variable sales price were skewed positively
skewed so we have to normalize it there are several other issues like outlier detection and handling and all those
things has to be taken care of so in into this we'll talk about two things which is feature engineering and outlier
detection step so let's go to feature engineering. piy and into this I wanted to look at this which is we do our
logging stuff same we set our strategy which is the interface for it where we we go ahead and then every strategy will
follow a simple step which is applying the uh which is a base class which defines a common interface for all our
feature engineering techniques or strategies and any subass must implement this apply transformation method right
so there are specific concrete strategies the lock transformation uh which is which is a
strategy which is to be skewed features to normalize the distribution because we have seen that sales price was positive
skewed skewed so we will what what we will do we'll try to use lock transformation also to implement that
and out right so lock transformation can be used to reduce the skewness in the data which means that if there is um
positive skew or negative skew it can be helped to skew um reduce the skewness in the data out there right so what we
could possibly do we could write apply transformation takes the day data frame as an input what sort of feature because
we want to indicate we cannot just go ahead and apply transformation each and every stuff we want to indicate where
features we which feature we should apply a transformation on so we apply the transformation we given the data it
Returns the data frame in return so it says we are applying the log transformations to Features this it
copies and it starts for feature in s. feature because it is a list um we should apply log which is by calculating
so I'm log transformation I want to look at it it's more mathematical thing but we simply apply the log transformation
on top of it to to to to reduce the skewness so this is one of the strategy to handle the skewness and uh
distributions to make it normalized for our algorithm to work right so another one is the standard scaling SC standard
scaling which means it transforms the data to have zero mean and unit variance so uh the you can actually use SC scalar
and standard scaler so right now I've just written this but when we actually do the modeling we apply log
transformation on the sales Target variable because we want it to not change it too much but for standard
scaling we'll be using our uh what do you say uh interest SK SK learn only to
implement this out which is apply transformation you apply fit transform on the features standard scaling get
completed Min Min Max scaling same however I've just shown you for an example that how could we implement this
however I I will not go in detail about each and every because it requires one hour another to explain you also this so
I want you to go and explore minmax zcore sorry Min minmax and standard scaling these are everything very easy
we have also taught lot into the pro probability must be in regression lectures um so I want you to look at it
it is so minmax and short it helps you to be between 0 to one and normalizes it for the sake of linear regression so uh
we have so basically what what we have did we have just for the numerical we have implemented log transformation
standard scaling and then minmax scaling for the because we have also categorical Columns of course we we are not going to
use this thing we are going to use S skarn formal skarn thing so it's more like we going to apply onto all the
features which are categorical right so it's it it concatenates the transformed because it also first of all um gets the
transformed and then it drops the columns which are categorical and imple conc concatenates the column which are
encoded so that's what we have encoded right now by calling fit transforms and then we get the feature names out of it
to to name the columns for it right so we have we have used we have used one hot encoding I hope that you have
already known about one hot encoding we have done that into the feature engineering part so we do the one hot
encoding and then it gets completed so the we create a a context class for feature engineering which means that it
takes the strategy in what sort of strategy and then switches the strategy and apply the feature engineering so
let's say that you want to implement the lock transformation so lock transformation is where we say feature
lock Transformer feature engine put in loog transformation what for sort of features we want to these two features
and then you run that you run the same for scaling for Min minm scaling and for one hot en coating so this is an example
usage but for our thing what we will do we will simply go to the training Pipeline and just apply lock
transformation to these two features which is ground living area and sale price because they were skewed um you
can also encode the values however I'll show you a different way to run feature engineering because I'm not going to do
encoding right now I'm going to do in coding little later but now the next step is now we
have the numerical columns how do we detect an outlier and handle it that is another big question which we should ask
so if go to the outlier detection. pi and same happens over here that you import necessary libraries and then you
create an abstract class which will have which you must have this detect outliers which will take data frame as an input
and return data frame as an input so we first of first first of all we will recognize and then we will
handle these these two things which we will do at uh uh right now so over here if you truly see zcore so first of all
we we going to implement the zcore so in a nutshell zcore outly detection is a statistical method which we use to
identify outliers in a data set so which means that we use the concept of standard deviation to determine how far
away a data point is from the mean of a data set so zcore is nothing but to and to know if there is a x data point how
far is that away from the mean so if that is too far which means that is an outlier but if it's too close which is
good right so we we given an threshold so we if a data point zcore whatever Z score we have appointed is beyond a
certain threshold like way then your mean then it is considered and as an outl so I don't want to go again deep
into maths but the zcore of zero indicates that a data point is exactly is at the mean so what I could tell um
and the zcore of one indicates that a data point is one standard deviation above the mean so one standard deviation
above the mean whatever standard deviation your variance you have then you have the further the zcore
from zero is the more unusual the data point is considered and then you can have that particular threshold in order
to determine how when based on your business rules so what I'm going to do is uh I'm
going to have a particular threshold so usually the thresholds um
so you say uh thresholds are three so if um thre the usual threshold which we have is either 2 2.5 or three it depends
on how hard you can handle right so I'm going to push out one of the example one of the data example the way it works out
so over here if you see this is a sale price and the zcore for the sales price is minus 0.75 95 so it is below that
mean but it is 1 point so all these are outlines because our threshold is three but as soon as we set our
threshold is one because we are too sensitive towards having an outlier then this will become true because this is an
outlier so this is what we we this is what the zcode does if you want to know more detail I want you to do your
research by your own and probably um get things sorted on this part now the same goes with IQR out we have another
strategy for detection which is IQ or outl detection which outline detection takes in a data frame and then figure
outs using the IQ IQ method is again same like a box plot so if any data points is above the viscus above the
viscus that's where what or below the viscus that's that's what the out outliers are so how could I explain you
if I could simply say IQR outlier detection and uh if I could show you this is the way so over here this is
where this is the median this is the q1 this is the Q2 and this is all this whis this whisker all the points around this
Fisker not outliers but all the points Above This Fisker and all the points below this Fisker out outliers the lower
fence and upper fence which we known as right so anything things which Beyonds or below your lower fence and upper
fence are outliers that's what the you know out IQ or outl detection means that we detect if they are above or below
that viscus right so this is another strategy for IQ outl detection this is one for Z
using zcore and then we create a context class that detects the outliers and handles it so we first of all set this
we asked the strategy what strategy which you want to use and then we set the strategy by making that method and
then we detect the strategy by calling detect outliers by calling the detect outliers from these methods and then we
handle outliers the way we handle the outliers if the method is removed we remove the outliers by calling DF doall
we just remove it all the outliers from that particular column and then if the method is capping so what what does
capping means capping means that I just want to don't don't want to go in very detail but in a in in a nutshell let's
say this is your data frame which is sales price in gr live area so now this is far away from this right this this is
this seems like an outlier right so what it does if that is an outlier it will change the value of that outlier to
a nearest data point which is not an outlier okay so over here it converts
that 2 lakhs to one L right 10,000 to 4,000 so that's that's what the capping means into the um C capping outlier so
we also tell what sort of quantites we should have the upper and a minimum so that if anything goes beyond it it looks
out for the lower one if anything goes above it it looks out for upper one what is the nearest one to it and then it
just changes the value right so this is what the outly detection is and then you simply go to
the training Pipeline and then you clean the data outl reduction step you give the engineer data and then the column
name is nothing but the sales price because that's where we want to look at it so I hope that it makes sense now the
next step is data splitting and uh then model building so you must you must be noticing why we haven't done any such um
encoding right now encoding we will directly do into the model building step because that's where we could um I'll
tell you why the reason when when when we do the model building step because it it is a big big reason to tell about
that but before going to that let's go ahead and then run this data splitting too so data splitting because we need to
split the data I don't want to explain it because we have already done a lot it's just that because we want to also
test our model whether it is performing good or not because if it truly train our model every data then if it just ask
the same questions then it already knows it will perform obviously better so we just split the data into training and
testing set and then we first of all train the data train the model on those training set and then test the test the
model on those training testing set so if we go to the um so if I could show you the feature
engineering step it says that if the strategy is logging you uh if we create that feature engineering step it takes
the data frame as an input the strategy the features list if there's anything needs to be there if the feature list is
none then you say raise an error right if the strategy is log you put in log strategy standard scaling the strategy
is one heart you do one heart and then you return your transformed stuff and then outline detection step so it
says received a non-type data frame so we are saying that the data frame should be must it should expect a pandas data
frame then then when it will work it should make sure that a column is present in that particular data frame
and then it selects the numerical columns from that and then it starts the outly detection and returns out and
handles those outliers and it returns out the DF cleint it is self-explanatory I don't want to go in very great great
detail because that's what we have done right now is very simple it just create converts in step and then call those
functions and methods and classes over here to make this turns out we using zcore outly detection ENT to this case
now once we have that done we go to this data splitter so which means that it will return data Frame data frame series
series X train X test y train y test and yeah so uh over here you call the from zml and then import data splitter
and then simple trains test split so if you go to data splitter we again try to make this very nice is create an
abstract class split the data because there a lot of things might be coming what must be the test size you simply
creates the concrete strategy by having s. test size random State and split the data into the following stuff and then
you create a concrete class for that by setting the strategy and splitting by calling that stuff up data splitter step
you call that thing and then you say strategy should be simple train to split if there's anything complex you need to
if you can just extend that abstract class to more complex strategy and then you simply call that do split and then
you give Target column and the DF it Returns the XT train X test y train and Y test now let's try to save it and we
run it perfect so let's go ahead very nice so here you have data
injection outputs it output something featuring data splitter steps output these four answers which is good
enough this is output one this is output zero this is output one this is output two and this is output three which is
correct good so we are done with the data splitter and the next one which we going to focus on is building the model
and then evaluating the model and then we'll be mostly done with our system um mostly hopefully and then we go ahead
and deploy the model and uh possibly what do you say uh test our model on top of it all right and then we mostly
finish our project so let's go jump onto the model building stuff so now we come to the model building part which is one
of the most I think I like this part too and uh probably where I spend a very less my time into model building because
I spend most of my time into analysis structuring processing and then because model building then becomes very easy
for me so we import B whatever libraries so linear regression pipeline from a skill learn so this is one one of one of
the thing which I will talk on why we are importing these two but uh this regress mixin is the type of the model
which linear regression trains and then when it is when it comes down when when you call do fit it returns this
regressor mix in so we set up the configurations for logging and then we create an abstract class so abstract
class is where your model building strategy comes into the play that we want to that abstract class must be
having build and train model method and any of the sub classes which is should it will have so X train is the panda
data frame and Y train is the panda data frame and it should return the regress and mixing which is a trained psyched
learn model instance not the untrained one right so you create a concrete class first of all linear regression strategy
so you train the model first by taking two inputs X train and Y train and then you ensure and then it returns a
pipeline so what it does first of all we want to make sure that the both are the correct types a data frame and a series
so once it's there we start that hey we are starting up with linear regression model and then what we do we create a
pipeline with a standard scaling and a linear regression what does it standard scaling means if you have seen I have
only did scaling to two two numerical features I not done to all so to make things easy for me for this project I'm
going to use Simple standard scaler which is feature scaling which we have also implemented the same and then a
standard scaler helps you to have the zero mean and unit variance I want you to learn learn about it so I'm going to
use that very simply for other features out there whatever other features I have I want to use standard scaling which is
what as standardly however you can go ahead and experiment it out with minmax scaling and other set of scaling based
on the context but for this context standard scaling works the best then the standard so now let's say that you do
not then then you train the model so this is the pipeline start with the standard scaler and then linear
regression model pipeline. fit and then return the pipeline which is the train sscar instance now why now you may ask
me hey aush why we need to have standard scaler just why can't we first of all scale it differently and then train the
model differently now let's say you give the Y train you give the Y train right so you give some testing example so that
has to be also scaled to whatever your linear regression has learned onto that scaling so let's say that if this linear
regression has learned your scaling onto the scaling of this only this can help right if you applied new scal you
instantiate a new class a new um standard scaler then it might scale that to differently and model will lead to
very differently a very logical thing right so if even any samples comes in that trained whatever standard scaling
which is trained on line regression is trained on they do that stand scaling on that one okay so we call this do fit and
then fit the pipeline so it starts with stand scaling and linear regression so model will first of all go through so if
any input comes in the model will first of all scale it down to what it already learn learned and then it trains and
then it actually predicts the model right do predict very simple I hope that it is
very simple because it is because it is very crucial to also understand why I'm doing it because if you don't not
understand then you might you I want you to try out very differently you'll try to think Lo logically too that if this
is different then this if if new example comes in then linear regression will expect the input uh the the input which
was scaled which was feature engineered by this standard scaler right not from the different
standard scaler from this only that is why we have to make it in a pipeline in the
Escalon so the context class for model building we first of all have the strategy now you can have multiple
algorithms too you can scale it down to polinomial regression you can scale to L2 L2 regression a lot of things which
you can do it scale it down uh because that that will also be your assignment also because you you you'll have to work
on to these several other algorithm compare it make a proper report so all those things will be given as an
assignments to the students out there now if you go ahead you can simply go ahead and then the strategy which you
have to follow which is the model building the the type of the strategy would be the because this is the subass
of the model building strategy the type of would be the model building strategy so you set the strategy of whatever and
then you build the model by calling the build and train model method and that's it that's pretty much it now you go
ahead model building and then you simply go ahead and create the step out of it this is again one of now we are also
doing lot of things over here in model building step so we'll be also using ml flow now so we'll be doing MLF flow
integration so again I'm going to say you please make sure that your stack so if you do ziml
stack describe it should look something similar to this
which is your orchestrator should be default when experiment racker would be MLF trer and model deployer should be ml
flow prices and the artifact store should be default so this this this should be your stack then only MLF flow
will work so over here we are going to import ml flow import pandas SPD we are going
to import the regressor mixing because we want to indicate what the output will come and then these two I'll explain you
in a bit right and the pipeline one encoder and things like that so over here what I have done is I
have not used the model building from this file because of several reasons of course I want you to use it you can use
it for sure but I just wanted to have it over here only so of course you can just change that fit to some something else
but uh but I I want to work through my I want you to work through my decision process so my decision process was that
the reason why I didn't use that because the pipeline over here involved couple of couple of more things I can also do
it over here but over there I want to also save this save that as an artifacts I don't want to just save it over here I
want to save that as an artifact you can also do over here both will make sense but most probably I had done done done
it over here to just save it as an artifact that's it there was no intention behind me to again you know do
not use that model building and come over here so of course I can also delete that if if I if I want because that that
does not helps now I want to first of all ignore this all these things right now just come to this over here if you
if you remember in our pipeline we have said model equals to price predictor that's here we instantiate about what
the model is so model price predictor what is the license of it the description of it with price prediction
model for the houses and then this is the unique name to identify anywhere right you can just call this price
predictor you'll be getting all the artifacts and stuff like that directly into the pipeline now we say that enable
cache equals to false because as you have seen that it was using my caches experiment tracker I will come back to
this in in a bit now it takes in xtrain and by train and then it returns in pipeline which is a trained pipeline
which first of all scales the value transforms The Columns and stuff like that and Returns the Escalon Pipeline
and and Returns the Escalon Pipeline and we say that is model artifact yes it is then output of the particular
step and that's what the artifact config means artifact config means that we indicate whatever output is coming is an
artifact please remember it because we will'll be using it to train and predict our model use this to predict or infer
our model so first of all we ensure things and then we because if if you have
noticed we have still not converted our categorical columns using one heart why because I wanted to do it here because I
wanted to be an artifact config so categorical columns we select the data types for categorical and then for
numerical as the same if you can see include object exclude object then what I do I simply
if so some sometimes what happens what I usually see sometimes when doing stuff we end up creating Nan values all by
ourself so we make sure even though this may not make sense we can also remove it but we make sure if any by chance
anything come into the play you just do simple imputer which is impute the missing values with the mean of it right
we have didn't we have did handle missing values but if by chance anything happens then you simply impude with the
mean because I I always like to be safe and then the pipeline looks looks like this over here we impute first of all
from the simple imputer which is the strategy which is the most frequen is the mean into this case and then we one
hot encode it one hot encoding means I hope you already know because it is bit of uh work to say but here here's what
it means that says ID one red two blue three green so red is being created color red and then if it is there then
it says one either 0 so some that that is what the one one coding is that it creates a separate column so it
increases the features complexity by creating new columns for that particular unique variable and then say and then
use a zero or one to indicate whether that is there or not not right so that's what one hot
encoding is and then we say and then what we do we actually have this column Transformer so what does column
Transformer means column Transformer means that we use a pipeline of simple imputer and one hot encoder in order to
um combine numerical and categorical Transformers so over here you have if you have seen one one part is that
numerical Transformer where we are uh where we using this to impute missing values from mean and there's a
categorical Transformer which is the uh for the categorical variables imputing with the most frequent values which is
the median right now and sorry mode right now and one H to Chang from the English to numeric format and then we
want to run this together so that's what the pre-processor means the column Transformer the Transformer it will run
the combines the numerical and categoric corers together to make the column Transformer so this allows steps to be
applied to different subsets of the data all together together and then what and then what we do we simply Define the
pipeline the pipeline is first of all this is the pre-processor that you first of all get through the numerical one and
then the categorical one and then you train and then you have the model of it and then what you can do you can simply
go ahead and then log the info saying that pipeline. fit which is the pipeline which you have created so it first of
all goes through a numerical columns and then categorical columns and then it applies all whatever pre-processing
steps and then it fits the model on top of it and then trains the model and then uh because see because the categorical
features will be lot so if you print right now you'll be having a lot of categorical features just like this
color color red so we want to know what my model expects we want to know what my model is going to expect so after
training it logs so by this we just get the feature names out of it which is the get feature names out of the categorical
columns which has been trained on it logs the column that the model expects which means that it is very helpful for
understanding the input required by the model after processing especially when using the one hot en coding because then
you can I I'll tell you why it why why it is helpful in in a bit because we also want to know what what columns
which my models is are expecting so um which are the columns which they have used to train our model
on now that is one thing another thing is that we also want to do the experiment of everything like we run on
this and then we let's say we change this to mean to median so that becomes another experiment right so we want to
also track the previous one and right one and compare it we changed this to another strategy we actually use some
sort of zcore on um in do something interesting over here so whatever we could do so we want to also extract
every run which which we are doing doing right so over here what we will do we will simply call
from zml do client import client which means that that it instantiates the get the active experiment tracker from the
zml right now ml flow is the active um which is from there so that's what we get because we have also it gets the
active experiment tracker and it says that we enable cach equals to false in the step decorator and experiment
tracker is equals to experiment TR do name which we have instantiated the name of the active and the model which we are
uh training from this is the model this is a price predictor so that your your system is aware because when when we do
the deployment this is very important to know where what model should I go ahead and deploy so prizes predicted is the
model which I should go ahead and deploy right so it says that if there's any current run ml flow is currently
running please stop it right of course uh please sorry if there's no current runs then start the Run starts it starts
a new MLF flow run if there's already not running and then if we use ml flow has a lot of there lot of available good
features but currently we'll be using skarn do autolock features so what it does it automatically captures the model
Matrix parameters artifacts inputs everything it and then it shows into you into the dashboard so what I'm going to
do and finally we end the Run once the things are completed I'm going to go ahead and show you the this in life so
the training pipeline we have um model building step over here we we split the data model building step over here I I I
I don't want to go to model evaluation step I just let's go to model building step right now and also you can see that
it that price is predictor because it says that your model which we are which we want to deploy is the prizes
predictor one we simply go and run the pipeline so the Run pipeline will look like this so I'm going to just cop uh un
uncomment this so that you get the u u now I'm going to run this to show you sorry how it
helps let's wait I just hope that no new errors comes in perfect so it says that your model
evaluation Matrix is following your mean Square eror which is very low R squ which is very low it also model expects
the following column you you must be noticing that it had dropped most of the columns who are not relevant in in outly
detection so numerical columns the CATE categorical columns there are no categorical of course there are some
category columns at that point but we have just used the numerical columns to go ahead and train it out model expects
the following uh numerical stuff right and then what what it
does it's it's simply you can just go ahead and uh you can run this mlflow
UI wait a sec let's run this perfect so now if you run this let's open this and this is the current one which we ran
which is the ml pipeline I want to go over here ml pip line which is just now which we ran 1 minute ago we click on
this and that's where you have what is the tax what is the estimator estimator name uh logged models the parameters it
is going to have what is the Matrix it it it is having the model Matrix the system Matrix the artifacts what are the
artifacts like ml model has been put in over here um you can see over here what sort of inputs it it requires what sort
of outputs it gives right uh the PK file so that you can use this model to further make predictions on top of it
now you can just go ahead and see our previous run too so this is the previous run so this is how you can track
experiments over here for the for the pipeline okay so this is how we use ml flow this was not a very big deal it's
just that you need to put it your little bit of Mind into model building step and autol locks a same single line that's
how that's why I call this zml very powerful because it helps you to automatically loog stuff and things
which is very help you can also manually log things if you want to in mlflow ml flow.
log perfect so the next step which I want to focus on is the model evaluator step which is not so hard um I I will
skim through it very quickly so what it does it simply creates an abstract class first of all
for model evaluation strategy it expects the model the testing set and the testing for labels
and then it simply goes ahead and predict the model and then it calculates the mean square error and the R2 score
and then you can set the strategy now you simply go ahead and the evaluator step and uh test make sure that things
are all right and then get the name steps and then transforms first of all as I said that if you give this X test
to the model the predictions will be very bad why because that is not what the input that input the model expects
model expects the pre-processed input the scaled input the CATE orical encoded input and all those things right so then
it initializes the evaluator with the regression strategy which is the model evaluator and then you strategy should
be regression model evaluation strategy and then we evaluate by giving we do not
give pre-processor into it we just give the model because we have already processed our testing set so we just
give the model from not the pre-processor and X test process pre-process not the directly X test and
the Y test of it okay and then it prints out the mean squ error that's it
so I hope that it makes sense we simply go to the training pipeline this is what it looks like it
we call this model evalu trained model whatever model which we have created and then it automatically take the model
from it by looking at by pre-processing first and then the model X test and the Y test and then finally it Returns the
model so that's it about the whole training pipeline which we have completed I want you to look at the zml
dashboard so let's go to pipelines let's go to ml Pipeline and let's go to this one the latest one this is what the
whole pipeline it starts from this and ends on the model evaluator step perfect now what we will do we will
go ahead and create the continuous deployment pipeline The Continuous deployment pipeline which means now we
will deploy our models and then we will and then once we get that API once the model is deployed we'll be getting the
local link local API calls which you can use that to call and make inference from our deployed model so let's go ahead and
then try that out and see how it works go to the our final step which is deployment and inferences of our model
now that is a amazing aspect of zml that you can literally via some commands some lines of code you can literally deploy
the model and infer it out from there so what we will do I will quickly make you go through some of the steps uh let me
just quickly close all the stuff y now if you go to the pipelines we have completed the training pipeline we are
do good we were able to get the ml flow now I wanted to go through this deployment pipeline so deployment
pipeline will import ml P pipeline Dynamic importer I'll talk about what is dynamic importer model loader and
prediction service in the predictor means in a bit but what it does it Imports the pipeline from the
integration from ml flow of steps it it Imports the ml flow model deployer steps so it uses the model deployer step to
import that so it is own ziml written step you don't need to know the logic behind it if you want to know then you
can go to the zml source code and try to that's what the zml tries to simplify it for you now if you truly see what
happens over here is it simply goes ahead and then we make this uh following continuous
deployment pipeline so continuous deployment pipeline is decorated with this pipeline decorator which indicates
that it is a ziml pipeline and this pipeline is responsible for training the following the model and gets the trained
model in return and then deploying it using the ml flow model deployer step so it takes three things this is already a
predefined zml step specifically designed for deploying the models with ML flow so so it says that workers
equals to three what does it this parameter indicates that there are three worker processes will be used for
serving the model so if you call any time there will be three guys who will be always available for handling
multiple requests simultaneously so it so your mod when serving the model the capacity will be nice the deploy
decision equals to True which means we want to deploy it that the train should be deployed or redeployed whenever the
pipeline runs and the last one is the what model to be deployed which is the train model to be deployed over here so
the continuous deployment pipeline into this ensures that whatever ml pipeline is run and a model is strained it is
automatically deployed or redeployed using a ml flow then we have inference pipeline so inference pipeline what it
does it first of all loads the batch data so what does batch data means so we are we using Dynamic importer I want you
to first of all see the dynamic importer step that is why we created a sample data for for for our model to make
predictions on this is the sample data which I've written that's why I looked at the numerical The Columns which my
model expects so that I can make the sample data you can also take your X test to do to perform it but I just
taken for a sake of sake and then I converted the data frame to a Json string because that's what your pipeline
accepts so this is the bash data which I want to make it for reference and then this is the now I want to load the
deployed model so this the function out here will load the deployed model for me from the pipeline name as continuous
deployment pipeline because this this was responsible for deploying the model into the server right and this what was
the step name of it the step name of what that was mlflow deployer step that that that is the one who deployed the
model right so let's quickly go to the go to the prediction service loader and what does prediction service loader uh
tells so over here you have this following which is responsible for loading an existing MLF flow prediction
Services which is already running because inference is what inference is making predictions once the model is
trained right so inference is once the model is trained so it is responsible for loading an existing MLF flow things
so it expects the pipeline name and and the step name where the model was used to so the step is designed to be used
within a zml pipeline so you can retrieve the prediction service that has been deployed using ml flow via
zml right so we import following statements where from Zen Integrations we import this mlflow deployer and then
MLF flow deployment service and then first of all we go ahead and uh what these two things does to first of all
give you Clarity MLF flow deployer is a class from zml ml flow integration because they've already integrated it
that manages the deployment of models using mlflow and then there's mlflow deployment Services which is a deployed
MLF flow model service which handles the model inference request wests once which is like a more sort of a prediction that
it helps you to make predictions right now over here if you go ahead and then try to make you
understand each and every step which is the function it retrieves an exactive model prediction service based on the
pipeline name and the step names which is over there and then we get an active model deployer so what it does this
method retrieves the active MLF flow deployer component from zl's active stack so whatever so that's why tell the
active stack should should be there right so whatever stack is there it gets the active MLF flow deployer which has
been used to deploy the model so this this is used to manage the deployment and services so once that is done we we
get our model deployer we get get the active model deployer now we find the model which is find model server so this
find model server from model deployer will look out for existing model Services mlflow model Services deployed
by that specific Pipeline and then in that specific step name which is a continuous deployment pipeline ml FL
deploy step name right and then this the the result is being stored in the existing Services which is a list of MLF
flow deployment service representing the deployed model Services right and then we say that if there's
some if if if there's no existing Services then you say no ml Pro prediction Services was found if there
is then you return um then you return the prediction service so if there's an active service then the function Returns
the first service which is the best model being deployed which can be used for making predictions now you can use
that do predict this service um out there right so let's go to our deployment pipeline once again and
that's where we get our model which is which is the train model of course we have to go and train first and then
you'll be running this and then you run the predictions using that model deployment so let's go to predictor so
this predictor expect the model which is trained on which is which we get from a previous step which is the prediction
service loader and input data which is in this case the batch D Dynamic utter which you the bash data it Returns the
numpy array of predictions so it loads out it expects these columns and then possibly it's converts that into a data
frame and then it converts the data frame to Json list for prediction and then it do service. predict by giving
the numpy array and then it Returns the predict which is a set of num
array right so this is what the predictor is that simply predicts so now we now the next step is that we want to
run this deployment pipeline which is not so easy I want to first of all explain you what this run deployment so
this is what the Run deployment is so let's go ahead and learn a little bit about what this run
deployment is let me have a cup of tea yeah so over here what we are going to do is we
orchestrate rate two zml pipelines we run two zml pipelines one is the continuous deplo deployment pipeline
which trains and deploys the model and another one is which uses the deployed model to make inferences so what we will
do um we will first of all import any Necessary Things click which if you want to stop our MLF flow Production service
we can just call this they I don't want to further make any inferences from the model that is what stop service will do
of course we won't do it right now we'll import our continuous deployment Pipeline and inference
Pipeline and then we import and then we import from zen. Integrations get tracking U so so that we know where our
model is being deployed right and then what we will do we will simply go ahead and then into uh import this um
mlflow model deploy to to deploy our models now this is that model name should be prizes predictor because this
was the model name if you have seen that we have registered when we were training the model right so this is the uniquely
way of taking the models in right now the run this this this this particular function will orchestrate the
both deployment and inference pipe processes now let's go ahead and uh try to get you the answers to it so if stop
service is equals to I mean uh true which means in in into this case of course it will be false so we
get the MLF flow deployer stack comp component over here so what does it mean that if the stop service flag is
provided the script attempts to stop the running of the ml FL Production service and then moves ahead into the training
of the model so mlflow deployed. active model deployer this one particular this one what it does it retrieves the active
model deployer component from the ziml so zenel has its own deployer steps so it takes it from there which is get
active model deployer and then it finds the model server it finds the model server so it
searches for an existing model server instances based on the pipeline name pipeline step model name because we
already know that it must be so it is more like if your thing has already been not run sorry run then this happens but
for for for the first time this will be run so to better make you understand if the stops service is um if if the
running if the if if the things are running if it is true uh and you and you have already T deployed the model it
simply goes and gets the existing Services that's it by looking at find model server from this continuous
deployment pipeline deployment what is the model name and all but if it is not deployed then it runs the continuous
deployment pipeline that is what happens in the first time second time it because the model is already deployed it will it
will not every time deploy the model right it will fetch the existing Services until unless there's no change
in the code if there's any change in the code it will run the whole pip pipeline so continuous deployment
pipeline what it does it runs your continuous deployment pipeline which eventually more makes the deploys the
best trrain model but if it is already ran then this script will run and it finds the best model server sorry uh
best model server based on the pipeline step and name now if now we say that we just stop
the existing services for example if the existing Services is there then we stop the existing Services which means if any
active model U is found it just stops the service using existing services so to make you understand what exactly it
does if the stop service is equals to true then it stops the service of the current
model make sense but if it is false most of the time it will be false then it will continue like this continuous
deployment pipeline then model deployer which is MLF flow get active model deployer it gets active and then it runs
the inference Pipeline and uh very simple ml4 deploy get active model deployer it runs the inference Pipeline
and it gets to inspect you can also run this track to inspect your experiments and then it fetches the existing
services with the same PIP plan name and step name and model name so existing Services which is the trained model
which is deployed now right so we this is the trained um pipeline this is the step where the model has been deployed
to right then says that the ml for protection services running locally as is a demon the process inference we are
accepting request at this prediction URL you can go ahead and make your prediction URL a request on top of it in
order to ahead but if you want to stop the service you can call this stop service so to summarize for you what we
what we have done if somebody says if this if it is to stop service then it first of all fetches any existing
services and stop it but if somebody says no Then it Contin by default it is false it just go ahead and then runs the
continuous it gets the active model deployer and then once it gets the active model deployer it runs the
inferences pipeline because the model has already been trained and it fetches the existing services to make
predictions by calling by giving it the name of the pipeline and step name of the thing where the model has been
deployed and then it gives the predictions U URL on top of it so lot of you have a problems in deployment why
because you're not trying to get the core of it the core of it is very simple that if there is any change in the code
which zml automatically understands from its past experiment it will rerun the whole thing it will rerun and if that um
Matrix is better than your current thing then it updates the model otherwise it does
not I hope you're trying to understand what what I'm trying to tell so this is the very basics of deployment is very
simple that you train the model first of all continuous deployment if there's any change it re reruns if the if you want
to stop the service if you want to stop the service what happens that it fetches the
existing and it stops the service but if you don't then it continues running the continuous deployment pipeline kind of
trains the model deploys the model if the model is better it shifts if it makes the model on top of it and then it
runs the inferences pipeline in inference pipeline what it will do it will simply go ahead and then find the
existing Services takes out the batch data and then possibly go ahead and then runs the service. predict and then it
eventually finds the model server whatever the model server is and then you get the U URL from it then then you
can use that URL to send requests to it and then get predictions for your model which you can further integrate into
streamlet or any other the application which you're building it is as simple as that okay so now what I'm going to do is
I'm going to run it okay but this time I'm going to
run deployment. Pi I hope it just works because sometimes even to me it just skes look
so it says predictor has started started starting services ml flow deployment service it start method completed and
now it says you can look at your experiments over here and then you can also ml flow prediction server is
running locally as D on process and accepts inference request at this part particular URL now most of you say that
hey I don't I want to know about how can we integrate into streamlit I mean it is pretty simple if you have learned this
then this should be pretty simple that you call this and then you send request to this particular URL so I'm going to
say sample predict and what what we do this is the URL of our ml for prodution service where our model is being
deployed where our model is being deployed and then this is the input data the sample input data uh you can make it
a stream lid by calling all of this and then you just convert the input data into Json format you send the post
request to the server and it says if the response status score is 200 you take the Json from it and then you print the
prediction R if there is what an error you print the status code and the response from it so it's just that
sending the request by following the right data to it that's it uh you don't need to you know need another 1 hour
lecture because lot of YouTubers don't don't focus on uh or creators don't focus on the core aspect of it they just
focus on deployment on stream deployment on stream bit can be done by class fifth student
nowadays I mean you guys are in college so you should be able to get the API request URL and then use that to do
something great right you use that to integrate in some complex stuff but yeah integrating s stream is not a very big
deal so we just call this sample predict dopy and here we go $280,000 if we give these then $28,000
is the pricee of that house I hope it makes sense to each and every people and we are done we are done
with everything we are done with most of the things and I hope this project giv you a sense of understanding of how
things work and how things should work we have done a lot of things we run and continuous deployment Pipeline and don't
so what is continuous continuous is more about if there's any change ziml automatically understands it right so it
runs a continuous deployment pipeline that trains and deploys the model we ran an inference pipeline that performs
batch predictions using the deployed model we can start or stop the ml flow model prediction service based on the
combine line options we can also inspect experiment runs and compare model performance using the mlflow model UI
which you can run this mlflow UI backend store whatever over here you can also see into your ZL dashboard and
everything over there too now there is lot of things to cover there are a lot of things like e2e batch
ETL lot of things we are coming up with into the course I want you to look at it we are done with this project it was a
simple House Press prediction While most of the people do it in just 30 minutes we complete an hours and get it done
very nicely so I hope you really like this project hopefully we come to the next one and uh uh we enjoy things out
here is very simple work is what is the future scope of work there are a lot of
things which could have been done into the processing steps I want you to experiment with standard scaling minmax
scaling see how the um how the things have been performing so I want you to look at it experiment it out use ml flu
experiment tracker to see the performance of the model and then I want you to also focus on testing other
assumptions of it and then seeing the performance of the model when you fix those assumptions I want you to also try
several outli detection things because these are the core things which is very very important which you can run as a
sort of an experiment every time so I wanted to focus on that too another aspect I want you to also focus on is
the um uh possibly you know trying out other interesting feature engineering techniques data processing techniques
new Eda things so that you Addy more of it so lot of things can be done over here my whole aim was to show you the
core aspect of it and mlops aspect of it now it's on you and how you can use it to make it the best project right now
this is now this this was not available on whole YouTube this is not available on whole YouTube so I want you to take
this as an opportunity do something great we'll be catching up into the next project if I ever come across I'll see
you later bye-bye
The project emphasizes implementation quality over novel ideas. Instead of just building a basic model, it focuses on core ML mastery, MLOps integration with tools like ZenML and MLflow, and using professional-grade code with design patterns like Factory, Strategy, and Template. This approach ensures the project is scalable, maintainable, and production-ready.
Design patterns are applied to enhance scalability and code readability. The Factory pattern handles data ingestion by creating different ingestors based on file format without hardcoding logic. The Strategy pattern is used in EDA, allowing switching between analysis methods like data types inspection or summary statistics at runtime.
ZenML is used as the MLOps orchestrator to manage and automate the machine learning workflow, creating a pipeline of steps. MLflow is integrated for experiment tracking, logging parameters and metrics, and for model deployment. Together, they enable CICD pipelines and production-ready model management.
The planned pipeline steps include data ingestion, EDA and data validation, data processing, model training, model evaluation, and model deployment via MLflow. This structured approach ensures each phase is automated and reproducible.
EDA goes beyond standard plots by creating a narrative from the analysis, making informed decisions about feature engineering, and testing algorithm assumptions to ensure data fits the model. The Strategy design pattern is used to implement different inspection methods like data types inspection and summary statistics, improving scalability.
Julius AI is recommended for rapid data exploration and visualization, offering workflows for tasks like correlation matrices and data cleaning. Community support is encouraged through ZenML and MLflow Slack/Discord communities, acknowledging that MLOps tooling is still evolving.
Key differentiators include robust error handling, type checking with hints and docstrings, moving logic from notebooks to structured Python modules for reproducibility, and using design patterns for scalable design. This ensures the project is maintainable and can easily adapt to new requirements without breaking existing code.
Keep this summary
Save it to LunaNotes and it becomes a real note in your library — editable, searchable, and ready to turn into flashcards or a diagram. Free to start.
Save to LunaNotesOr summarise for another video.
32K+ people have turned 65K+ videos into notes
“Very useful tool. I'm using it for the last couple weeks and I'm loving it so far. Makes learning on YouTube a great experience.”
This summary and transcript were automatically generated using AI with the Free YouTube transcript summary tool by LunaNotes.
Related summaries
Complete Machine Learning Course: 60-Hour Hands-On Tutorial with Python Projects
This comprehensive 60-hour machine learning course covers conceptual topics and hands-on Python implementation across five parts, featuring use cases like rock vs. mine prediction, diabetes detection, and spam email classification. The first module focuses on machine learning fundamentals, Python basics, essential libraries (NumPy, Pandas, Matplotlib, Seaborn), and data preprocessing techniques including handling missing values, standardization, label encoding, and imbalanced datasets.
100 Days of Machine Learning: Comprehensive Beginner to Intermediate Guide
Discover the upcoming '100 Days of Machine Learning' playlist designed to teach a structured, end-to-end ML life cycle over 100 days. This video introduces key concepts, explains machine learning's real-world significance, and outlines the learning path for beginners and intermediate learners alike.
Comprehensive Introduction to AI: History, Models, and Optimization Techniques
This lecture provides a detailed overview of Artificial Intelligence, covering its historical evolution, core paradigms like modeling, inference, and learning, and foundational optimization methods such as dynamic programming and gradient descent. It also discusses AI's societal impacts, challenges, and course logistics for Stanford's CS221.
Understanding Introduction to Deep Learning: Foundations, Techniques, and Applications
Explore the exciting world of deep learning, its techniques, applications, and foundations covered in MIT's course.
Master SQL: Comprehensive Guide to Advanced Data Analytics and Optimization
Explore an extensive SQL course covering fundamentals to advanced topics including data warehousing, analytics, complex querying, performance tuning, and AI-powered coding assistance. Learn practical techniques, real-world project workflows, and best practices to excel in data engineering and analysis using SQL.
Most viewed summaries
A Comprehensive Guide to Using Stable Diffusion Forge UI
Explore the Stable Diffusion Forge UI, customizable settings, models, and more to enhance your image generation experience.
Kolonyalismo at Imperyalismo: Ang Kasaysayan ng Pagsakop sa Pilipinas
Tuklasin ang kasaysayan ng kolonyalismo at imperyalismo sa Pilipinas sa pamamagitan ni Ferdinand Magellan.
Mastering Inpainting with Stable Diffusion: Fix Mistakes and Enhance Your Images
Learn to fix mistakes and enhance images with Stable Diffusion's inpainting features effectively.
Pamamaraan at Patakarang Kolonyal ng mga Espanyol sa Pilipinas
Tuklasin ang mga pamamaraan at patakaran ng mga Espanyol sa Pilipinas, at ang epekto nito sa mga Pilipino.
How to Install and Configure Forge: A New Stable Diffusion Web UI
Learn to install and configure the new Forge web UI for Stable Diffusion, with tips on models and settings.
Found this summary useful?
Take it with you. One click puts it in your own LunaNotes library.
Save to LunaNotes