28 Jun 2022

Posted on:

25 Jun 2022

1

# Resolved:Code for the Practice Exam

Hi,

I have finished this lecture and took the practice exam 'CarStore' but I still have a hard time understanding some questions even though I went through the written answers.

Can you please share a code solution so that I can fully understand and study this?

Thanks :)

Instructor
Posted on:

27 Jun 2022

0

Hey Yongjun,

Thank you for you question!

Unfortunately, it is not possible to provide an example solution to an exam. Could you please tell us which questions you are referring to and what parts you found difficult. We would gladly clarify any confusion and, if necessary, could reformulate the exam questions.

Thank you!

Kind regards,
365 Hristina

Posted on:

27 Jun 2022

0

Hi Hristina,

I was confused with question 1's 2nd condition: <<Add 50 rep of each class to the training set and 40 rep of each class to the test data set>>

Does this mean that I have to set n_sample = 360 while applying make_blobs and test_size=4/9 for train_test_split?

I have attached the screenshots of my code. Please let me know which parts I have made mistakes 🙏🏻

Instructor
Posted on:

28 Jun 2022

1

Hey again Yongjun,

The idea here is to create the training and test sets separately, as hinted in the Jupyter notebook, so there would be no need to use the `train_test_split` function. One way to do this is as follows:

``````x_train, y_train = make_blobs(n_samples = [50]*4, centers = ..., cluster_std = ..., random_state = ...)
x_test, y_test = make_blobs(n_samples = [40]*4, centers = ..., cluster_std = ..., random_state = ...)
``````

Here, the list `[50]*4` is equivalent to the list `[50, 50, 50, 50]` - you can use both syntaxes. It sets 50 representatives of each class to the training set. This is done for the test set analogously, with 40 representatives from each class. The parameters `centers`, `cluster_std`, and `random_state` are set in exactly the way you've done it.

Hope this helps!

Kind regards,
365 Hristina