Setting up VS code for Machine learning projects

Setting up VS code for Machine learning projects

To make machine learning projects, we need to setup following in vs code

  1. Jupyter environment

  2. Virtual environment

  3. Python and it's libraries installation

  4. Version control integration (Git and GitHub)

Step 1 : Create a Virtual environment

  1. Open VS code

  2. Create and select a folder where all your projects will be available.

  3. Let's assume folder structure

    • Machine_learning_series folder → Projects folder
  • “Projects” folder includes, Datasets (csv, excel, json files), file_name.ipynb files, and venv

  1. In vs code, click on top left “Terminal” option, and then “New terminal”

  2. It will open a new terminal window

  3. To create a virtual environment having name “.venv”, type “python3 -m venv .venv”

  4. To activate virtual environment, type “source .venv/bin/activate”

  5. To check which python version is installed in your virtual environment, type “python - -version”

  6. To check location of above installed python, type “which python”

  7. To check what pip packages are installed already, type “pip list”, it will list 2 packages : pip , setuptools

  8. To upgrade pip, type “pip install - -upgrade pip”

  9. Again, check “pip list”

Step 2 : Setup ipynb kernel

  1. Create an file_name.ipynb file, let's matches.ipynb

  2. On top right, click “Select kernel”

  3. Choose “Python Environments”

  4. Then, “+Create Python Environment”

  5. Then, “Enter interpreter path”

  6. Then,”Find”

  7. It will open the location of folder (here ,Projects folder), Right-click mouse and choose “Show hidden files”, then choose “.venv” folder

  8. When you open “.venv” folder, you find “bin” folder there, open it , and select “python3.11” or whatever latest python version available, and then “Select interpreter” option.

  9. Now, vs code will automatically download “ipykernel” package, and select the .venv kernel

  10. We don't need to download , jupyter lab or jupyter notebook separately, just download following extensions

Step 3 : Download extensions

In extensions tab of VS code, install following extensions :

  1. Python

  2. Jupyter

  3. GitHub copilot

Step 4 : Download Python libraries

We need to download python libraries like pandas, numpy, matplotlib, etc to perform EDA on datasets.

In VS code , open “Terminal”(Top left), “New terminal”

And type following commands

  1. pip install ipykernel ipython

  2. pip install <package_name> like pip install pandas numpy matplotlib

  3. Remember, activate the .venv before typing above commands

  4. To deactivate the vene, type “deactivate”

Step 5 : Version control setup

To setup version control like Git, in VS code, we need to

  1. Open “Accounts”(Bottom left icon), and “sign-in” with GitHub account username and email password.

  2. “Initialize Repository” in folder, here we have “Projects” folder opened.

  3. In “source control” tab, we can stage our files, commit and push to “clone”d repo

  4. Important point “Open .gitignore file” and type below statements

  • .venv/

  • .ipynb_checkpoints/

These are to avoid pushing the virtual environment to version control.

Now, our VS Code is set up for machine learning projects.