# M121 Chapter 3 Lab 2

I haven’t been able to figure out what they are asking for:

“Calculate an average rating for each movie in our collection where English is an available language, the minimum imdb.rating is at least 1, the minimum imdb.votes is at least 1, and it was released in 1990 or after. You’ll be required to rescale (or normalize ) imdb.votes. The formula to rescale imdb.votes and calculate normalized_rating is included as a handout.”

The documents already contain the “average of the rating”. So why would I need to do rescale the votes? Given the handout, I can guess that they mean “the average of rating and normalized votes”. Is that it?

Hi @Joerg_Schmuecker, welcome to the community.
As mentioned in the handout:

// general scaling
min + (max - min) * ((x - x_min) / (x_max - x_min))

// we will use 1 as the minimum value and 10 as the maximum value for scaling,
// so all scaled votes will fall into the range [1,10]

scaled_votes = 1 + 9 * ((x - x_min) / (x_max - x_min))

// NOTE: We CANNOT simply do 10 * ((x - x_min))..., results will be wrong
// Order of operations is important!

// use these values for scaling imdb.votes
x_max = 1521105
x_min = 5
min = 1
max = 10

// within a pipeline, it should look something like the following
/*
{
1,
{
\$multiply: [
9,
{
\$divide: [
{ \$subtract: [<x>, <x_min>] },
{ \$subtract: [<x_max>, <x_min>] }
]
}
]
}
]
}
*/

// given we have the numbers, this is how to calculated normalized_rating
// yes, you can use \$avg in \$project and \$addFields!

All you need to do now is implement the above formula in a \$project/\$addFields stage.

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

1 Like

Hi Sourabh, I have done that and passed. Unfortunately, the formula doesn’t reflect what is in the textual description. Can you please review?

Hi @Joerg_Schmuecker, thanks for sharing your feedback, I will forward this feedback to the Curriculum Engineering Team.

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.