Question: Implement sqimpurity First, implement the function sqimpurity, which takes as input a vector of labels and outputs the corresponding squared loss impurity: = 1 (

Implement sqimpurity
First, implement the function sqimpurity, which takes as input a vector
of
labels and outputs the corresponding squared loss impurity:
=1()2, where ==1.
Again, the squared loss impurity works fine even though our final objective is classification. This is because the labels are binary and classification problems can be framed as regression problems.
def sqimpurity(yTr):
"""
Computes the squared loss impurity (variance) of the labels.
Input:
yTr: n-dimensional vector of labels
Output:
squared loss impurity: weighted variance/squared loss impurity of the labels
"""
N,= yTr.shape
assert N >0 # must have at least one sample
impurity =0
# YOUR CODE HERE
raise NotImplementedError()
return impurity

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!