Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...


Python2 and Python3 are already installed on Debian 10, but the default version is Python2. How to check it...$ python

Code Block
languagebash
python --version

# That will return Python 2.x.x


Check for Python3
$ python3

Code Block
languagebash
themeConfluence
python3 --version

# That will return Python 3.x.x


We have to make Python3 as the default version for the distro.
Firstly we have to find the directories for each version...$ ls

Code Block
languagebash
themeConfluence
ls /usr/bin/python* -la


In this example it returns a bunch of directories...

...

Now we must update/create the "Python alternatives list" using the above paths. $ sudo

Code Block
languagebash
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1


Code Block
languagebash

...

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 2


Finally we can switch between Python versions. Running the following command, a menu will appear in order to choose the Python version that we want as default.

Code Block

...

sudo update-alternatives --config python


There are 2 choices for the alternative python (providing /usr/bin/python).

...

Choosing the selection 2 then Python3 will become the default version.
We could check if Python3 has applied as default, running...

Code Block
languagebash

...

python --version

# In my case it returns Python 3.7.3




2. Download and install Miniforge3

...

But first check if there is the Download directory on your distro. If there is none, then create one...
$ mkdir

Code Block
languagebash
mkdir ~/Download

...


cd ~/Download

...


sudo wget https://github.com/conda-forge/miniforge/releases/download/4.8.3-4/Miniforge3-Linux-aarch64.sh

...

 
bash Miniforge3-Linux-aarch64.sh



* Miniforge3 will be installed at this location: ~/miniforge3/bin/ and add it to your PATH variable.
In order to check the location of executable "conda" file, type the following...

Code Block
languagebash

...

sudo find / -type f -name "conda"


For In my case it returned "~/miniforge3/bin/" and the variable PATH must be changed to...
$ export

Code Block
languagebash
export PATH=$PATH:~/miniforge3/bin




3. Install MLFlow using Conda


Code Block
languagebash

...

conda install -c https://conda.anaconda.org/paulscherrerinstitute mflow

...


conda update conda

...


conda --version

# In my case the version is 4.9.2




4. Create and activate a conda virtual environment and install MLFlow


A conda environment is a directory that contains a specific collection of conda packages that you have installed. For example, you may have one environment with NumPy 1.7 and its dependencies. The name of the environment is env_mlflow.
Use your Python's version to create an environment...

Code Block
languagebash

...

conda create --name env_mlflow python=3.7.3

...


conda activate env_mlflow


Reboot the machine and login again. If you are using a remote machine, reboot the remote instance and use ssh to login again.

After the reboot we can install MLFlow using pip3.

Code Block
languagebash

...

pip3 install mlflow




5.Install Sklearn using pip3 and other dependencies


We need GCC and G++ compilers as dependencies to build Sklearn.

Code Block
languagebash

...

sudo apt-get install gcc

...


sudo apt-get install g++


This app helps us to save the point of the process, when the connection drops. As a result, when we reconnect, we can continue from the point where our process was disrupted and not from the very beginning.

(optional) Install tmux.
It takes a lot of time to build Sklearn, and there is a high possibility the internet access will be lost. So, tmux helps us to continue the proccess from where it left off. $

Code Block
sudo apt-get install tmux


$ tmux
# We open tmux environment Install sklearn To open tmux just type... tmux

Install Sklearn using pip3 and the dependencies.
$ pip3 install sklearn
$ pip3 install Cython
$ pip3 install

Code Block
languagebash
pip3 install sklearn
pip3 install Cython
pip3 install --upgrade setuptools




6. Install Matplotlib


Matplotlib is a plotting library for the Python programming language and its numerical mathematics extension NumPy. It provides an object-oriented API for embedding plots into applications using general-purpose GUI toolkits like Tkinter, wxPython, Qt, or GTK+.$ conda install

Code Block
languagebash
conda install -c conda-forge matplotlib


In order to check the installation...

Code Block
languagebash

...

pip3 install matplotlib

# The return must be "Requirement already satisfied"

...


PostgreSQL, also known as Postgres, is a free and open-source relational database management system emphasizing emphasising extensibility and SQL compliance.
$ sudo

Code Block
languagebash
sudo apt-get install postgresql

...


sudo apt-get install postgresql-contrib

...

 
sudo apt-get install postgresql-server-dev-all





8. Install Psycopg


Psycopg is the most popular PostgreSQL database adapter for the Python programming language. Its main features are the complete implementation of the Python DB API 2.0 specification and the thread safety (several threads can share the same connection).
$ pip3 install

Code Block
languagebash
pip3 install psycopg2




9. Download and run MLFlow examples


Check if Git is already installed...

Code Block
languagebash

...

git --version


If the Git is not installed... $ sudo apt update
$ sudo apt install

Code Block
languagebash
sudo apt update
sudo apt install git


Clone MLFlow example code

Code Block
languagebash

...

cd ~

...


git clone https://github.com/mlflow/mlflow

...


cd ~/mlflow/examples/sklearn_elasticnet_diabetes/linux


Run the example "train_diabetes"

Code Block
languagebash

...

python train_diabetes.py 0.1 0.9

...


python train_diabetes.py 0.5 0.5

...


python train_diabetes.py 0.9 0.1


# For each example above the return must be something like this...
RMSE: 71.98302888908191
MAE: 60.5647520017933
R2: 0.2165516143465459

MLflow runs can be recorded either locally in files or remotely to a tracking server. By default, the MLflow Python API logs runs to files in an mlruns directory wherever you ran your program. You can then run "mlflow ui" to see the logged runs.

Code Block
languagebash

...

mlflow ui


# The return must be something like that...
2020-12-03 14:17:36 +0000] [1267] [INFO] Starting gunicorn 20.0.4
[2020-12-03 14:17:36 +0000] [1267] [INFO] Listening at: http://127.0.0.1:5000 (1267)
[2020-12-03 14:17:36 +0000] [1267] [INFO] Using worker: sync
[2020-12-03 14:17:36 +0000] [1270] [INFO] Booting worker with pid: 1270

At the 2nd line there is the localhost's IP and the port (127.0.0.1:5000). Now we can use them to get the results.
Using a remote machine (OpenStack), the instances does not have a Desktop Environment (GNOME, XFCE, e.t.c.) in order to see the results. But we can check if it has created the "index.html" file at at http://127.0.0.1:5000...
$ cd

Code Block
languagebash
cd ~/Download

...


wget 127.0.0.1:5000

...


cat index.html


But, using SSH Tunneling we can see the OpenStack's instance localhost on the local Web browser.
Syntax: ssh -L port:localhost:port userName@FloatingIP
Example: ssh -L 5000:localhost:5000 debian@214.152.131.68
(We can replace the localhost with the 127.0.0.1)