Keyerror:0 during decision tree

Hi everyone. In ungraded lab of this week, I run the code on my pc and I get error below:


And it doesn’t draw last trees of decision tree. All of packages are updated and all of lab files are with python file.
What do I do?

Hello @Mohammadamin,

Seems you were uploading some screenshots but you had clicked the button to send out your post before the uploading was done. Please re-post the screenshots. The text “Uploading” shall be gone after the upload is successful.

Raymond

1 Like

Uploaded. Thanks. So what do i do?

Hi @Mohammadamin,

From your screenshot, it seems to me you were running the lab on your own environment. Please be noted that the lab is only tested to run on Coursera, so I suggest you to check out the lab on Coursera for your study.

However, if you have the same problem running the lab on Coursera, please follow these steps to refresh the notebook. I have just tried this out myself and it worked.

Raymond

It runs on Coursera for me too. But i want to run it on my pc. I don’t have any problem with other labs on my pc.

@Mohammadamin, there is no one-click solution to that. One possible cause is that your environment (or more specifically some packages used by the lab) is different from that on Coursera. From your screenshots, the first package I will look into is networkx.

image

If you are familiar with configuing a separate environment for Coursera’s content, then you may try to. Otherwise, I suggest you not to because it can end up more problems.

Here are something you can start your preparation and search with, if you are eager to try it yourself:

  1. Before you dive into it, please note the following:

    • The following steps will tell you how to build an environment for one lab. Although it is likely that different labs use the same environment, it is NOT guaranteed.

    • Be reminded the risk of breaking your current working environment if you didn’t handle it properly. You might need to reinstall your Anaconda to hopefully get it back (but not guaranteed). So, before start, do more research, and read a few more online tutorials to figure out which are more reliable.

    • It may not be successful even though you have followed what I have said, or any tutorials, because, for example, some packages available on Coursera may not be available on the internet for you to download

    • We really don’t and actually sometimes can’t support you for what you do on your machine, so unless you are determined to try and you are ready to take up the responsibility, please stick with Coursera.

  2. Googling keywords: “Create virtual environment with Anaconda”.
    Here is the official doc: Managing environments — conda 23.3.0.post10+b4642ed8f documentation. For other step-by-step guidance, google with the keywords.

  3. Before you start to create a virtual environment, you need to know the version of each of the packages. We do not provide it, but you can check it yourself on Coursera. Go to Coursera, then open the lab that you are interested in.

    • run !pip3 freeze will give you a full list of packages
    • then you can search for the package name to see its version
  4. In the new virtual environment that you set up for that Coursera lab, install the packages but of the exact versions used by Coursera. For how to install a package of specific version, check out this tutorial.

Raymond

1 Like

@Danfb did you have this problem and if it is, what did you do?

@Mohammadamin I don’t have that line of code in my notebook, so I think I have an old version of that notebook