Skip to content

Latest commit

 

History

History
125 lines (93 loc) · 5.39 KB

File metadata and controls

125 lines (93 loc) · 5.39 KB

Intel® Python: NumPy vs Numba vs DPNP Sample

The Intel® Python: NumPy vs Numba vs DPNP sample shows how to achieve the same accuracy of the k-NN model classification while using NumPy*, Numba*, and Data Parallel Extension for NumPy* (dpnp).

Property Description
Category Code Optimization
What you will learn How to program using the Data Parallel Extension for NumPy* (dpnp)
Time to complete 5 minutes

Note: This sample is validated on Intel® Distribution for Python* Offline Installer and AI Tools Offline Installer. For the full list of validated platforms refer to Platform Validation.

Purpose

In this sample, you will run a k-nearest neighbors algorithm using 3 different Intel® Distribution for Python* libraries: NumPy, Numba, and dpnp. You will learn how to use k-NN model and how to optimize it by dpnp operations without sacrificing accuracy.

Prerequisites

Optimized for Description
OS Ubuntu* 20.04
Hardware CPU
Software Intel® Distribution for Python*

Key Implementation Details

This sample code is implemented for the CPU using Python. The sample assumes you have dpnp installed inside a Conda environment, similar to what is installed with the Intel® Distribution for Python*.

The sample tutorial contains one Jupyter Notebook and one Python script. You can use either.

Environment Setup

You will need to download and install the following toolkits to use the sample.

1. Get Intel® Distribution for Python*

If you have not already, install Intel® Distribution for Python* via Installer.

2. Activate the Intel® Distribution for Python* base environment

If the default path is used during the installation of Intel® Distribution for Python*:

source $HOME/intelpython3/bin/activate

If a non-default path is used:

source <custom_path>/bin/activate

3. Clone the GitHub repository

git clone https://github.com/oneapi-src/oneAPI-samples.git
cd oneAPI-samples/AI-and-Analytics/Features-and-Functionality/IntelPython_Numpy_Numba_dpex_kNN

4. Install dependencies

Note: Before running the following commands, make sure your Conda environment is activated

pip install ipykernel
pip install notebook

For Jupyter Notebook, refer to Installing Jupyter for detailed installation instructions.

Run the Sample

Note: Before running the sample, make sure Environment Setup is completed.

Intel® Distribution for Python* Offline Installer (Validated)

1. Register Conda kernel to Jupyter Notebook kernel

If the default path is used during the installation of Intel® Distribution for Python*:

$HOME/intelpython3/bin/python -m ipykernel install --user --name=base

If a non-default path is used:

<custom_path>/bin/python -m ipykernel install --user --name=base

2. Launch Jupyter Notebook

jupyter notebook --ip=0.0.0.0

3. Follow the instructions to open the URL with the token in your browser

4. Select the Notebook

IntelPython_Numpy_Numba_dpex_kNN.ipynb

5. Change the kernel to base

6. Run every cell in the Notebook in sequence

Example Output

Numpy accuracy: 0.7222222222222222

Numba accuracy: 0.7222222222222222

Numba_dpex accuracy 0.7222222222222222

[CODE_SAMPLE_COMPLETED_SUCCESSFULLY]

Related Samples

License

Code samples are licensed under the MIT license. See License.txt for details.

Third party program Licenses can be found here: third-party-programs.txt

*Other names and brands may be claimed as the property of others. Trademarks