Practice Lab: Decision_trees

Hi, I have a problem with the Practice Lab: Decision trees.
The error is can’t compile student’s code.
I have a pdf file with the print screens but I cannot upload it here.
Do you have an email address?
I would like to send you an email with the print screens.
Zuhal

Hello @Zuhal,

You can wait for someone to share their email with you, but usually we don’t and I won’t too.

You might try to save the screenshot in an image file (png, jpg) (Google for instructions if you don’t know how to), and then upload it here.

Cheers,
Raymond

even with the png file I get the following error
Sorry, there was an error uploading that file. Please try again.

1 Like

Seems like you have some problem with the Discourse.

@chris.favila, is there anything you could suggest to @Zuhal?

Raymond

1 Like

jpeg same no upload possibility

Thanks for reporting, @Zuhal . While we are waiting for some suggestions from the staff,

  1. Is this the exact same message that you saw?
    image

  2. how many KB is your image?

The staff might ask more questions to understand your situation, but I believe the above one would be useful.

Raymond

200 KB it is. so small.

Good. What about my first question?

yes it is the same error

Thanks @Zuhal. Sorry about the first question because you have actually shared the error message in text form in a previous reply, and I have overlooked that.

Now, going back to your lab’s error, can you also share the error message by the autograder in text form?

I expect you are seeing something like the below but with a different error message, can you copy and paste the error message here? I think there should be something else after “Can’t compile the student’s code”
螢幕擷取畫面 2023-06-06 180635

Raymond

@Zuhal,

I have to go now. If there is other text around “Can’t compile the student’s code”, please share here. If it talked about which exericse it is about, please also share. I hope other mentors can help you.

Raymond

error Index error (list index out of range)
then many file names

Please paste the full error as shown in the below image. We need to see the file names. It may also give you Cell numbers as well.
螢幕擷取畫面 2023-06-06 180635

I cannot upload png or jpeg

Copy and paste the complete error (text) here.

Cell #9. Can’t compile the student’s code. Error: ValueError(‘not enough values to unpack (expected 2, got 0)’)
Traceback (most recent call last):
File “/home/www/app/grading/exceptions.py”, line 112, in handle_solution_errors
yield {}
File “/home/www/app/grading/abstract.py”, line 393, in _grade
context = compiled_code.run(cell_index=cell.index)
File “/home/www/app/grading/submission/compiled_code.py”, line 195, in run
return list(self._code_items.values())[cell_num - 1].run()
File “/home/www/app/grading/submission/compiled_code.py”, line 54, in run
return import_module(self.import_statement, items)
File “/usr/local/lib/python3.7/importlib/init.py”, line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 1006, in _gcd_import
File “”, line 983, in _find_and_load
File “”, line 967, in _find_and_load_unlocked
File “”, line 677, in _load_unlocked
File “”, line 728, in exec_module
File “”, line 219, in _call_with_frames_removed
File “/tmp/student_solution_cells/cell_9.py”, line 26, in
generate_split_viz(root_indices, left_indices, right_indices, feature)
File “/tmp/utils.py”, line 32, in generate_split_viz
G.add_node(idx,image= generate_node_image(indices))
File “/tmp/utils.py”, line 9, in generate_node_image
widths, heights = zip(*(i.size for i in images))
ValueError: not enough values to unpack (expected 2, got 0)

OK. Something is wrong in your Cell # 9.

My Cell # 9 has this code:

root_indices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

# Feel free to play around with these variables
# The dataset only has three features, so this value can be 0 (Brown Cap), 1 (Tapering Stalk Shape) or 2 (Solitary)
feature = 0

left_indices, right_indices = split_dataset(X_train, root_indices, feature)

print("Left indices: ", left_indices)
print("Right indices: ", right_indices)

# Visualize the split 
generate_split_viz(root_indices, left_indices, right_indices, feature)

# UNIT TESTS
split_dataset_test(split_dataset)    

Check your cell # 9. Count the cell number from the start (or the cell number at the side of a cell). If it is the same, you may need to check your implementation of the split_dataset function.

Best,
Saif.

Hi Saif, my code look like below:

Case 1

root_indices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Feel free to play around with these variables

The dataset only has three features, so this value can be 0 (Brown Cap), 1 (Tapering Stalk Shape) or 2 (Solitary)

feature = 0

left_indices, right_indices = split_dataset(X_train, root_indices, feature)

print(“CASE 1:”)
print("Left indices: ", left_indices)
print("Right indices: ", right_indices)

Visualize the split

generate_split_viz(root_indices, left_indices, right_indices, feature)

print()

Case 2

root_indices_subset = [0, 2, 4, 6, 8]
left_indices, right_indices = split_dataset(X_train, root_indices_subset, feature)

print(“CASE 2:”)
print("Left indices: ", left_indices)
print("Right indices: ", right_indices)

Visualize the split

generate_split_viz(root_indices_subset, left_indices, right_indices, feature)

UNIT TESTS

split_dataset_test(split_dataset)

I couldn’t find the problem. Do you have an idea what it might be?

There might be a mistake in your implementation of split_dataset. That might be Cell # 8. Have you checked the hint?

def split_dataset(X, node_indices, feature):

   # You need to return the following variables correctly
   left_indices = []
   right_indices = []

   ### START CODE HERE ###
   # Go through the indices of examples at that node
   for i in node_indices:   
       if # Your code here to check if the value of X at that index for the feature is 1
           left_indices.append(i)
       else:
           right_indices.append(i)
   ### END CODE HERE ###

return left_indices, right_indices