Enrollments Open for Certification Course on Artificial Intelligence and Deep Learning by IIT RoorkeeApply Now
Let us now implement the function which calculates the accuracy. This function takes as arguments the predicted labels and the actuals of the corresponding dataset.
We do this in 2 steps:
np.abs(Y_predicted - Y_actual), we calculate the absolute difference between the actual labels and predicted labels.
Then, we use
np.mean() and calculate accuracy.
np.abs gets the absolute value of each element in the input array.
np.mean returns the mean of the elements in the input array.
Let us assume
y_predicted are the actual labels and predicted labels respectively. Copy the following code.
y_actual = np.array([1,1,1,0,1]) print("y_actual :", y_actual ) y_predicted = np.array([1,0,0,0,1]) print("y_predicted :", y_predicted )
Get the absolute differences of the corresponding elements in
np.abs(), and store them in
c = << your code comes here >>(y_actual - y_predicted)
Store the mean of the elements of
c_mean = << your code goes here >>(c)
Accuracy could be calculated as:
accuracy = 100 - (c_mean * 100)
This logic is written in the following
get_accuracies function. Copy-paste the following
def get_accuracies(Y_predicted, Y_actual): abs_diff = np.abs(Y_predicted - Y_actual) accuracy = 100 - np.mean(abs_diff) * 100 return accuracy
No hints are availble for this assesment
Answer is not availble for this assesment
Note - Having trouble with the assessment engine? Follow the steps listed here