Resolved: Code for the Practice Exam
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?
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.
Thanks for your prompt reply!
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 🙏🏻
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 = *4, centers = ..., cluster_std = ..., random_state = ...) x_test, y_test = make_blobs(n_samples = *4, centers = ..., cluster_std = ..., random_state = ...)
Here, the list
*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
random_state are set in exactly the way you've done it.
Hope this helps!