A Python virtual environment for TensforFlow
Some examples to test the virtual environment for exploring machine learning
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
- Installed packages in
tf
virtual environment (NumPy, SciPy, SymPy, pandas, Pillow, Matplotlib, Seaborn, scikit-learn, Keras, TensorFlow, Jupyter Notebok) have been tested using various available examples and all work, showing that the packages are installed properly. - Some of the packages can not be tested without support from other packages.
- The file
requirements.txt
fortf
virtual environment is available on previous story. - All examples can be downloaded from https://github.com/dudung/py-jupyter-nb/tree/main/src/apply/misc/medium/3056789ab7a2.
Thanks to Aayushi Johari, Sneha Bajaj, Monica Pérez Nogueras, Esther Vaati for inspirational and working examples.
- Bajaj S (2023), “Ten Must-Know Seaborn Plots”, Medium, 28 Dec 2023, url https://medium.com/p/1f3a82dc99c5 [20240509].
- Campbell S (2024), “SciPy in Python Tutorial: What is, Library, Function & Examples”, Guru99, 9 Mar 2024, url https://www.guru99.com/scipy-tutorial.html [20240509].
- Codex A C (2023), “How to Create a Neural Network with TensorFlow”, Reintech, 26 Jul 2023, url https://reintech.io/blog/how-to-create-a-neural-network-with-tensorflow [20240509].
- GfG (2024), “Python Pandas DataFrame”, Geeks for Geeks, 25 Jan 2024, url https://www.geeksforgeeks.org/python-pandas-dataframe/ [20240509].
- Johari A (2017), “A Beginner’s Guide To Scikit Learn — Implement Scikit Learn In Logistic Regression”, Edureka — Medium, 4 Dec 2017, url https://medium.com/p/7a2d92e4dd07 [20240509].
- nkmk (2019), “How to use Pillow (PIL: Python Imaging Library)”, nkmk.me, 14 May 2019, url https://note.nkmk.me/en/python-pillow-basic/ [20240509].
- Nogueras MP (2023), “10 Graph Examples using Matplotlib”, Medium, 17 Jul 2023, url https://medium.com/p/b08e6c7bebcf [20240509].
- Rout A (2020), “7 Numpy Practical Examples: Sample Code for Beginners”, DevopsCube, 8 Jun 2020, url https://devopscube.com/numpy-practical-examples/ [20240509].
- Vaati E (2020), “Deep Learning tutorial with Keras”, Analytics Vidhya — Medium, 18 May 2020, url https://medium.com/p/7a34a1a322cd [20240509].
- Viridi S (2024), “Install Python (again) on Windows 11”, Medium, 9 May 2024, url https://medium.com/p/37a19f179b77 [20240509].