Git Product home page Git Product logo

cpc_ml_tutorial's Introduction

Machine Learning with Normative Modeling Tutorial

Computational Psychiatry Course 2022

This repository contains written instructions, links to code, and data used for the (virtual) Machine Learning/Normative Modeling Practical at the Computational Psychiatry Course on September 17th, 2022.

This repository is a group effort by Saige Rutherford and Thomas Wolfers.

We will be running all of our code in Google Colab python notebooks. These are essentially Jupyter notebooks run in the ☁️ cloud ☁️. Running our code using Colab will save us from dealing with python library installation and virtual environment setup. It also ensures that we are all working on the same operating system which makes troubleshooting much easier (since there are only 2 instructors and lots of students)!

If you have never used Google Colab before, you can check out an introduction notebook with lots of helpful links here: Open In Colab

We will also be using the Pandas library for a lot of our code. There is a great intro to Pandas Colab notebook here: Open In Colab

Other helpful pandas:panda_face:/plotting:bar_chart: links (not required to do during the practial, just added for those who might need extra python help):

  1. Pandas cheatsheet
  2. Pandas Selecting/Indexing API

⚠️ Setup instructions for Google Colab ⚠️

You can open the python notebook that we will use in this practical directly from this Github account (the links to the notebook are at the bottom of this Read Me file). Before you open the notebook, make sure you are logged into a Google account. All of the code has been tested using Google Chrome web browser. When you are ready to begin, you will click on the template Google Colab button below. This will launch a new browser tab with the Google Colab notebook.

Once you are in the Colab notebook tab, in the top right corner you will see a Connect (or Reconnect) button. Click on this, and a dropdown menu will appear as shown below. Click on Connect to hosted runtime this will allow you to run the notebook using Google’s cloud resources, which are likely much faster than your computer. If you would prefer to use your own computer’s resources (this is not recommended and instructors will not be able to help you troubleshoot if you are not running the notebook in the cloud), select Connect to local runtime.

⚠️ Note: sometimes if the notebook is left running for a long time without any activity (i.e. your computer goes to sleep), you will be disconnected from the runtime. In that case, you will need to click on this same button. It will appear as Reconnect instead of Connect. You will also need to re-run all code blocks.

➡️ If you are using the Google cloud hosted option: in the upper left corner, you will see a button called Runtime. Click on Runtime, and another dropdown panel will appear (as shown below). Click on Change runtime type.

➡️ This box will open, and you can click the GPU option, then click save.

➡️ In the same menu you used to change the runtime, there are several other optional things you can explore that may make your interacting with the notebook easier. Under ‘Tools’ there is a ‘Settings’ tab, which you can use to change the theme to light or dark mode using the ‘Site’ sub-tab. Then under the ‘Miscellaneous’ sub-tab, you can select Corgi or Kitty mode, and this will make cute animals walk across the top of your screen. There is no practical utility to this whatsoever, and it is for the sole purpose that cute animals spark joy.

➡️ Also under the ‘Tools’ tab, there is an option to look at Keyboard shortcuts. You don’t need to change any of these, but you can review some of them if you want to learn about speeding up your coding practice.

➡️ In the Colab python notebook, there are 2 types of cells: text cells & code cells. The text cells have plain text in them, that the notebook will not interpret as code. These are the cells that contain the background story & task instructions. The code cells have a ▶️ play button on the left side. These are the cells that the notebook will run as code. To run a code cell, you can either click on the play button ▶️ on the left side or use ‘Shift + Enter’ (your cursor must be inside the code cell).

Now you are ready to begin coding 🧠 💻!

Good luck 🍀 and remember to have fun 😃!

Before clicking on the colab button below, make sure you are logged into a google account and using Chrome or Firefox internet browser (hopefully a current version)

Task 1: Fitting normative models from scratch Open In Colab

Task 2: Applying pre-trained normative models Open In Colab

Task 3: Interpreting and visualizing the outputs of normative models Open In Colab

Task 4: Using the outputs (Z-scores) as features in predictive model Open In Colab

cpc_ml_tutorial's People

Contributors

mariam186 avatar saigerutherford avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

cpc_ml_tutorial's Issues

Question on dummy setup

Hello,

Thanks for this wonderful tutorial, I am getting stuck when trying to plot some of my own data, I was wondering if I could have some help as to what mismatch is causing the error. Thanks!

yhat, s2 = self.blr.predict(theta, Phi, y, Phis,
229 var_groups_test=var_groups_te,
230 var_covariates_test=var_cov_te,

~/opt/anaconda3/lib/python3.9/site-packages/pcntoolkit/model/bayesreg.py in predict(self, hyp, X, y, Xs, var_groups_test, var_covariates_test, **kwargs)
450 N_test = Xs.shape[0]
451
--> 452 ys = Xs.dot(self.m)
453
454 if self.var_groups is not None:

ValueError: shapes (58,11) and (13,) not aligned: 11 (dim 1) != 13 (dim 0)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.