Welcome everybody, you're watching Mr. Fugu Data Science. i decided to make
another video doing 10 more real data science interview questions; i've
came across personally. I would like to say thank you to those who
started watching my channel, as well as my subscribers.
The code will be in the link and description below. If we're looking at a
random forest classifier which of the following involves randomness?
Choosing which trees to discard during inference.
Which loss function to use. Which subset of features to use
for any given tree; or which branch to follow at a given node? You say oh wow
this is intimidating because it seems very likely that any of these could be
the case. First of all, i could say i would probably get rid of
this second one right here. The first third and fourth though, i have
to evaluate. Let's kind of do some
inspection. What exactly is a random forest
classifier? A simple explanation i could just say that we're putting together
multiple decision trees merging them, averaging, and then getting a more
accurate and stable model from there. We are doing classification but, it could
be used for regression. It's a predictive not a descriptive tool
and it's pretty robust from overfitting unlike a decision tree.
But, now if we are looking at this and we say well each tree is built from a
random feature that is selected or features. And we have
to note: that not all of the selective features
or even the observations are known to all
trees. So this is leading us to one of the
answers. Now, this is really good because, the random
force is helping us avoid correlation and overfitting. And when we look at
these answers it would appear that this
would probably be the best answer in my opinion.
The branches which to follow are interesting because, the higher
the node on the tree the more important it usually is.
And when you're moving down the branches you're
creating many subsets from your data for it to move
through. This i wouldn't necessarily worry
about because this is something you don't really have to worry about.
It says which involves randomness; while subsetting these trees
is working at randomness and that's what i'm thinking is going on
here because that seems the most important. Now,
let's look at sql joins and figure out which result would
incur more matching rows in either the input tables. So this is
interesting and i had to think about this because, it
said more matching rows. That's the key point that you have to
remember. Let's remember what the outer left right and inner joins are.
If we're looking at the full outer join we're basically taking
everything from the left and right side if everything matches and
then anything that doesn't match it's just a row that has
null values. The right and the left join are basically same but, they're in
reverse. So you're returning everything from the right table and anything like
matched in the left and then anything let's not match is
just a null value. The inner join is you could think of an
intersection of both tables, okay. The real question is:
what is creating more matching rows? Well, i would have to say the inner join..
Okay, so there's a few reasons why i would say this for example.
So give me a second.
Here we go for our joins the inner, the left, the right,
and our full outer. Okay, now that we come back here
and we see this: why did i say more match as well?
You have more matches for the inner join because,
you will not have any of these rows that are populated by
null values. So while you get from a full outer left or right joi nt more rows
in total. The null values are what you have to reconsider. So if we're doing a tradeoff between speed and accuracy
when calculating the product of many probabilities
How can we take care of this? And it says which approaches.
So you have a big int you have a float 32 for example single precision.
You have a Fourier transform trick and a log sum
exponential trick. It looks like we're using two of the
four. But, which ones are we using? To think about this,
it's very interesting and there's a lot going on. So if we had
many probabilities we were dealing with. We could assume that we had put them
into some form of a matrix. And if we were to do that the matrix
multiplications can be a problem. And you'd have to think about something
like this. So your time complexity is horrible, and if we had for instance two
matrices that were 10 to the third you would now have 10 to the six
operations. Which would be a million operations, right. So you're like oh no
what's going on with this junk? So then you say all right there are
algorithms that take care of reducing time complexity for
matrix multiplications where you have to do tricks. So that's one of the things
for the speed up that we need to consider.
But, the other thing we need to look at is accuracy.
The accuracy are two options are the big Integer
and the flow 32. Now, if you're looking at this problem as a whole, you have three
things you need to consider one converting your multiplications to
additions. When you do that you automatically get a
speed up. Two underflow and overflow for accuracy of
your probabilities is something you need to consider.
Underflow meaning that; if you had a really small number
getting close to zero like point zero zero zero zero five
you know something like this you could end up with just 0 showing up instead.
Which is a problem. Hardware versus software is something
also for speed. For instance the single precision
32 would be a hardware setup whereas, the big
integer would be a software implementation. Now,
these days the distinction between hardware or
software implementation for speedups are fairly close together.
So if we were to look into these we would see that the log
exponential trick while, it's good for doing multiplications
and converting them to additions you have issues with
underflow actually. And then you have the float 32 which is good for adding and
slower for multiplications. So if you indeed used the log sum
exponential trick with the flow 32 you might be pretty good
except for this underflow issue you'd have to figure out.
It depends on what kind of operations you're doing. If you're building a bridge
and you only need is something to be like
within a you know quarter of an inch or two inches then it doesn't matter. But, if
you have something that needs to be like you know 10 to the minus 10. You're gonna
have some issues. Then the big answer is the reverse of
that where it's really good with multiplying
but not so good for additions. And then that Fourier trick is really interesting
because, it's not bad time complexity is n log
n. And it's really good if you have large amounts of data
if i'm correct. If i were to choose two of these
i'm not sure which two i would choose to tell you the truth.
The big integer would not be one i would think about for
working with floats. So my option would have to be this.
Also, if you're getting into double precision the larger you get
the slower the computation is. So i would have to consider
saying you need the flow 32 but, between these two i don't know
probably the Fourier transform. Since, the underflow issue.
But, i don't know. Now, if we're comparing a validation set with a test set can you
do this well it's kind of a problem. Because, you got
to think about your original data. If you have enough data you can do a
train, validate, test where you're splitting
your data. Now, you're using the validation set to
address any problems you may have in your model and
adjust and tune your parameters. Because, in essence what you're doing is
trying to avoid overfitting your model. And the test set
is something that you're not using on any of your original data to
basically see how good your model is. Now, streaming a data set.
This is something that i have only had come up once in my life.
And streaming data is really interesting and challenging. So if you are only able
to read whatever you're streaming one time:
because, it's too big and it just doesn't fit into memory.
Can you do a mean, variance, both, neither, one or the other? And this
is something that i just was uncertain with. Because, i haven't had to do this.
Doing some research, i found that there's algorithms
that are good for one pass. That's what you'll look at one pass algorithms.
And there's things built for this for streaming data. It appears that
something called a Welford algorithm which
is good for finding the variance and there's variations of these algorithms.
And then you could apparently do a recursive call to find the mean
of your data by taking your current data and then whatever was
previous that just came in. So it appears that you could find both.
Now what are some assumptions when you're looking into
Naive-Bayes algorithm? Well this does look promising to say well
you would have a normal distribution as an assumption.
But, you would not be correct because there is not a distribution assumption,
linearly separable, now you have two independents.
And you need to choose conditionally independent.
That would be your answer for this. Now, if we are looking at reversing a list:
how do we do this? Well as soon as i looked at evaluating these
i had to figure out well, we need to go to the end. We need something that goes
to the end. And this minus 1 look very promising. But,
then you say well what's going on with this minus i? Then i
remembered from algorithms, and i said oh yes, i remember when i had to reverse
some stuff and this is actually what i need. Because,
you need to take what you're looking at and then you need to subtract it from
the end. And if you notice here that's what's
going on and that's your correct answer. And mind you, if you're looking at these
and have one minute to think about it you can't really solve the problem you
just have to know. Okay you have to have some big idea of
what's really going on, so put that into context. So if we're
looking at some queries: and we say we have both of these queries
and we need to think about what are the differences.
And i put here think about the distinction between these. Because,
you're having a group by versus over partitioned by. Where both of them you
are using an average, and so what's the distinction?
The first thing: what are the answers that we have to
work with the first one computes the average price for the category while the
second does not. The first one is not valid sql code the
second one is. The first returns unique categories
the second may return duplicate categories.
And the first one is less efficient to compute than the second.
You say well what's the answer? Let's think about this: a group by is
used for doing like sums and averages but what it does is it collapse
and returns less rows. While over partition will return the rows preserved.
Okay, and it's a window function. So what does that even mean?
Well if we're looking at these i'm going to chuck this out.
Because, these are valid sql code. Now the second one does not well this one
looks like valid sql code too. It says we have these two. Now, you
have something with efficiency, and then you have something that's
returning unique categories. Well the efficiency is really
interesting. And if you delve deeper into this partition by with this
over: you notice that it does a sequence of
operations to perform this. Where you're first throwing a sort and then it's
doing some kind of aggregating and maybe that could be slower than
doing this operation. But, when i look into the research
i don't really see anything that's definitive that could prove this assumption.
Maybe i'm wrong, maybe there is something here but i don't really
know and i'm going to avoid saying that. And i'm going to keep this one.
Because, this is giving unique categories because you're collapsing these rows
and this one while it may reassign your row ids
it may look like you're actually having a duplicate and some rows
but you're not actually duplicating all your values.
You know so you may have like a row id that may look different
or you may have some information that looks the same.
But you're not actually creating more data than you have.
Now this would probably be my answer. If we're looking at what actually is a
activation function like you would use in a neural
network well then what's really going on here
you know? Like what is it? So if i was to think about that, and give
some kind of short answer i'd have to think
this. If we were thinking about what an activation function is: I would preface with
saying think of an on off switch. And you're
doing this with weighted sums and applying it to a
bias term. And you need to introduce some kind of non-linearity.
Because, if you are leaving this as a linear function
just think of running a regression you know. You're not able to make a model
you're not able to make any complex models you know.
And so basically at the output being received
and updated depending on the weights and biases
for your error. Now if you're considering the input:
where you're looking at the current neuron and moving to the next layer.
and the neuron will reach the activation function
and it'll be on or off, right. And there's two different kinds either linear
nonlinear activation function, okay. and you can
think about that here where you consider your neuron
you have your input, an activation function can look like
such as like think of a gate you know and
you're feeding in your input neuron and it's outputting it to the next
layer right. And here's your activation function here's your weight
and here's the bias that you're adding into it. And basically it's deciding
whether this neuron should be activated or not activated.
Okay, so what's wrong with this code block? You're doing a try
and a finally and you're trying to open some file and you're trying to read it
in and then you're closing the file. And then you have a few answers and it
says not all the bytes from the file are read. The file may be closed before all
the data is read. If you fail during opening a different
error code will be raised. If an error is raised the
file will remain open. Well the third answer right here is
the correct one and this is because
you will not have caught any errors. and
you can use either a try and accept or try accept
and an optional else clause to kind of take care of
any errors that may come up. So we'll scroll down here.
So something like this so an (OS) error that you can say
or you can call a value error. Here's an example of what you can do,
and here's another example right here. so that's what i would say for that.
Let's do this last one which is very involved. There's a lot going on with
this. So which of the following expressions
defines the variance of a random variable
x? If you're doing this you need to realize a few things.
The expected value of x, is your mean. So here this is just the x squared
value it's not the mean squared, all right.
The first one doesn't appear to be what we need.
We do need a squared term, such as one of these.
But, this is definitely not what we need, So you could rule out these two.
If you solve these and the third and the fourth one are really interesting.
But, you have to realize something: here you are now squaring the mean here
and you just have some random variable x. But, what's going on
is you in turn have two variances of x which cancel out to zero
that's definitely not what you want. The fourth one right here, like i said
you need something like squared. When you're looking at this is
going to work. You got to pay attention to how this
notation is. Okay so it's just like doing your
squaring when you're you know doing a quadratic or something
like that you know. So this is this is the breakdown of what it looks
like when you do it. But, mind you if you're looking at this
and you're doing this for an exam. It's not going to be very fast. So you do
have to realize that you need a squared value. But, then you have to figure out
which squared value you're going to need. All right, so i'd like to say thank you
for watching this video, I hope it brought utility
to somebody. Please like, share and subscribe and if you subscribe turn on
that notification bell. As always i'll see you in the next video.
Thank you for watching. Bye