A Python virtual environment for TensforFlow

Some examples to test the virtual environment for exploring machine learning

Sparisoma Viridi
Mr. Plan ₿ Publication
7 min readMay 9, 2024

--

A previous created virtual environment tf, which is for studying machine learning (Viridi, 2024), is tested and the results are reported in this story.

Jupyter Notebook

On a Windows Command Prompt activate virtual environment and run Jupyter notebook as follow

M:\py-jupyter-nb>v:\tf\Scripts\activate

(tf) M:\py-jupyter-nb>jupyter notebook
[I 2024-05-09 16:17:28.362 ServerApp] Extension package jupyter_lsp took 0.1784s to import
[I 2024-05-09 16:17:28.476 ServerApp] Extension package jupyter_server_terminals took 0.1161s to import
[I 2024-05-09 16:17:29.820 ServerApp] jupyter_lsp | extension was successfully linked.
[I 2024-05-09 16:17:29.834 ServerApp] jupyter_server_terminals | extension was successfully linked.
[I 2024-05-09 16:17:29.853 ServerApp] jupyterlab | extension was successfully linked.
[I 2024-05-09 16:17:29.866 ServerApp] notebook | extension was successfully linked.
[I 2024-05-09 16:17:30.519 ServerApp] notebook_shim | extension was successfully linked.
[I 2024-05-09 16:17:30.596 ServerApp] notebook_shim | extension was successfully loaded.
[I 2024-05-09 16:17:30.601 ServerApp] jupyter_lsp | extension was successfully loaded.
[I 2024-05-09 16:17:30.601 ServerApp] jupyter_server_terminals | extension was successfully loaded.
[I 2024-05-09 16:17:30.610 LabApp] JupyterLab extension loaded from V:\tf\Lib\site-packages\jupyterlab
[I 2024-05-09 16:17:30.610 LabApp] JupyterLab application directory is V:\tf\share\jupyter\lab
[I 2024-05-09 16:17:30.610 LabApp] Extension Manager is 'pypi'.
[I 2024-05-09 16:17:31.130 ServerApp] jupyterlab | extension was successfully loaded.
[I 2024-05-09 16:17:31.143 ServerApp] notebook | extension was successfully loaded.
[I 2024-05-09 16:17:31.144 ServerApp] Serving notebooks from local directory: M:\py-jupyter-nb
[I 2024-05-09 16:17:31.144 ServerApp] Jupyter Server 2.14.0 is running at:
[I 2024-05-09 16:17:31.144 ServerApp] http://localhost:8888/tree?token=f96d9c7bb05a42c051ae2bce2e040d3a9accb7acb3b9ff09
[I 2024-05-09 16:17:31.144 ServerApp] http://127.0.0.1:8888/tree?token=f96d9c7bb05a42c051ae2bce2e040d3a9accb7acb3b9ff09
[I 2024-05-09 16:17:31.146 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 2024-05-09 16:17:31.244 ServerApp]

To access the server, open this file in a browser:
file:///C:/Users/Sparisoma%20Viridi/AppData/Roaming/jupyter/runtime/jpserver-17624-open.html
Or copy and paste one of these URLs:
http://localhost:8888/tree?token=f96d9c7bb05a42c051ae2bce2e040d3a9accb7acb3b9ff09
http://127.0.0.1:8888/tree?token=f96d9c7bb05a42c051ae2bce2e040d3a9accb7acb3b9ff09
[I 2024-05-09 16:17:34.194 ServerApp] Skipped non-installed server(s): bash-language-server, dockerfile-language-server-nodejs, javascript-typescript-langserver, jedi-language-server, julia-language-server, pyright, python-language-server, python-lsp-server, r-languageserver, sql-language-server, texlab, typescript-language-server, unified-language-server, vscode-css-languageserver-bin, vscode-html-languageserver-bin, vscode-json-languageserver-bin, yaml-language-server

The examples is part of https://github.com/dudung/py-jupyter-nb repository on GitHub.

Next step is to navigate to folder and create the examples. Or when the folder does not exists, create it first.

A new folder 3056789ab7a2 is created for this post examples.

Installed packages

There are NumPy, SciPy, SymPy, pandas, Pillow, Matplotlib, Seaborn, scikit-learn, Keras, TensorFlow, Jupyter Notebok to be tested. The last has been tested by running Jupyter Notebook as shown in previous figure.

NumPy

There are some critical examples for NumPy (Rout, 2020) that are used as examples.

It shows, at least for the given examples, that installed NumPy package works.

SciPy

Following examples are obtained in a SciPy tutorial (Campbell, 2024).

The last example is also showing the use of SciPy and NumPy, that works.

pandas

Following are examples of using pandas DataFrame (GfG, 2024).

Other important features from pandas to learn are save DataFrame to file and also read it from file.

Pillow

Next is to test installed Pillow package with the an example (nkmk, 2019).

Notice that it can find the installed font, where error message appears by removing # in front of font = .. line.

Matplotlib

An example from provided ones in a story (Nogueras, 2023).

It requires NumPy in generating random numbers with normal distribution.

Seaborn

Two of the ten provided Seaborn plots (Bajaj, 2023) are as follow.

You can further explore the story and try the other plots.

scikit-learn

Following is an example of using scikit-learn for machine learning with SVM (Johari, 2017).

It shows 8 training data, number 0 to 7.

Keras

An example of Keras, without using TensorFlow explicitely, is available (Vaati, 2020).

First epoch requires 695s for 5000 steps and the second is still in process.

The accuracy improves in second epoch.

TensorFlow

A tutorial for creating a Neural Network using TensorFlow is available as follow (Codex, 2023).

It uses the MNIST dataset, which consists of 70,000 images of handwritten digits.

Summaries

Thanks to Aayushi Johari, Sneha Bajaj, Monica Pérez Nogueras, Esther Vaati for inspirational and working examples.

--

--