• Jupyter Notebooks in VS Code OSS, 12 March 2024

    Recently I changed the distribution on my laptop to Arch Linux and there one has the possibility to install the open source version of Visual Studio Code (Code - OSS), which I use regularly in class. However, I was not able to run jupyter notebooks within. After a short search online I found out that starting code in the console with a parameter resolves the problem:

    code --enable-proposed-api ms-toolsai.jupyter .
    

  • Burning an SD card/USB Stick, 2 October 2022

    First find out the device of the SD Card/USB Stick using the command

    lsblk
    

    Burn the SD Card/USB Stick using the command dd. As input file (if) you use the image file and as output file the device you want to burn the image to.

    sudo dd if=openhabian.img of=/dev/sda bs=32M
    

    gz-compressed files

    zcat openhabian.img.gz | sudo dd of=/dev/sda bs=32M
    

    xz-compressed files

    sudo apt-get install xz-utils
    
    xzcat openhabian.img.xz | sudo dd of=/dev/sda bs=32M
    

  • Jupyter notebooks in Visual Studio Code, 5 May 2021

    For the exercice classes on statistical inference I prepared some jupyter notebooks and in the exercice classes on arithmetics we used sage. I usualy code using Visual Studio Code. Therefore I was looking for a combination of the two worlds.

    In the case of statistical inference I am using a virtual environment with jupyter inside. This works more or less out of the box using the python extension.

    However, sage uses a jupyter server together with a different version of python. Since I am using Linux, I was following the Mac OSX part of the tutorial Sagemath and Vscode. This did not work out and so I’ve looked into the settings of vscode. There I’ve set the python.pythonPath to /usr/share/sagemath/bin/sage-python and the jupyter.jupyterServerType to local. My .vscode/settings.json looks like this:

    {
      "python.pythonPath": "/usr/share/sagemath/bin/sage-python",
      "jupyter.jupyterServerType": "local"
    }
    

    With these settings I can run the notebooks, however, the display uses the local (with respect to vscode) jupyter server and not the one of sagemath.

    References


  • The Wilcoxon test in Python, 5 May 2021

    In statistical inference we heard of the Mann-Whitney U Test (which we called the Wilcoxon rank-sum test) for comparing differences between two samples. In particular, we had an exam and we wanted to know whether there is a significant difference in the performance of female and male students.

    References


  • Stats for linear regression, 30 April 2021

    Programming a linear regression in plotly you can use a scatter plot together with the option trendline='ols'. However, on the one hand this resulted in an ModuleNotFound error for me and I had to install the package statsmodels. On the other hand I needed the plot for a logarithmic scale and this resulted in a “line” which was not straight.

    In order to solve the first problem I’ve installed the necessary package

    pip install statsmodels
    

    For the second problem I’ve changed the data accordingly.

    df['logconsommation'] = np.log(df['consommation'])
    fig = px.scatter(df,
                     x='logconsommation',
                     y='vie',
                     labels=dict(logconsommation='log consommation de cacao par habitant (kg/an)',
                                 vie='espérance de vie en bonne santé (an)'
                                ),
                     trendline='ols',
                     trendline_color_override='red')
    fig.show()
    

    References


  • A virtual environment for statistical inference, 13 April 2021

    In the exercice classes on statistical inference we are writing pseudo code in R or Python. In the following I want to describe how one can create a virtual environment in python and install some necessary tools.

    First install a virtual environment. On Linux or Mac OS X:

    python3 -m venv myenv
    

    On Windows:

    c:\>python -m venv myenv
    

    Here I’ve supposed that you have configured python in your PATH and PATHEXT variables.

    Now we have to activate the virtual environment. On Linux or Mac OS X:

    source myenv/bin/activate
    

    On Windows:

    .\myenv\Scripts\activate
    

    This should change the command prompt. Now we are ready to install the required libraries.

    pip install notebook pandas plotly scipy
    

    or if you have a requirements.txt

    pip install -r requirements.txt
    

    Everynow and then you should upgrade the packages by typing.

    pip install --upgrade notebook pandas plotly scipy
    

    You can run a local notebook by typing.

    jupyter notebook
    

    Finally you leave the virtual environment by typing.

    deactivate
    

    References