NetApp Solutions

Contributors Suggest changes In a manner similar to the previous section, load Criteo Click Logs day 15 in Pandas and train a scikit-learn random forest model. In this example, we performed DataFrame loading with Dask cuDF and trained a random forest model in Dask cuML. We compared the differences in training time and scale in the section “Training time comparison.”

This notebook imports `numpy`, `cuml`, and the necessary `dask` libraries, as shown in the following example:

```import cuml
from dask.distributed import Client, progress, wait
import numpy as np
import cudf

`client = Client()`

If your cluster is configured correctly, you can see the status of worker nodes.

```client
workers = client.has_what().keys()
n_workers = len(workers)
n_streams = 8 # Performance optimization```

In our AKS cluster, the following status is displayed: Note that Dask employs the lazy execution paradigm: rather than executing the processing code instantly, Dask builds a Directed Acyclic Graph (DAG) of execution instead. DAG contains a set of tasks and their interactions that each worker needs to run. This layout means the tasks do not run until the user tells Dask to execute them in one way or another. With Dask you have three main options:

• Call compute() on a DataFrame. This call processes all the partitions and then returns results to the scheduler for final aggregation and conversion to cuDF DataFrame. This option should be used sparingly and only on heavily reduced results unless your scheduler node runs out of memory.

• Call persist() on a DataFrame. This call executes the graph, but, instead of returning the results to the scheduler node, it maintains them across the cluster in memory so the user can reuse these intermediate results down the pipeline without the need for rerunning the same processing.

• Call head() on a DataFrame. Just like with cuDF, this call returns 10 records back to the scheduler node. This option can be used to quickly check if your DataFrame contains the desired output format, or if the records themselves make sense, depending on your processing and calculation.

Therefore, unless the user calls either of these actions, the workers sit idle waiting for the scheduler to initiate the processing. This lazy execution paradigm is common in modern parallel and distributed computing frameworks such as Apache Spark.

The following paragraph trains a random forest model by using Dask cuML for distributed GPU-accelerated computing and calculates model prediction accuracy.

```Adsf
# Random Forest building parameters
n_streams = 8 # optimization
max_depth = 10
n_bins = 16
n_trees = 10
cuml_model = cumlDaskRF(max_depth=max_depth, n_estimators=n_trees, n_bins=n_bins, n_streams=n_streams, verbose=True, client=client)
cuml_model.fit(gdf_sliced_small, Y)
# Model prediction
pred_df = cuml_model.predict(gdf_test)
# calculate accuracy
cu_score = cuml.metrics.accuracy_score( test_y, pred_df )```
{"ft_lang_label":"__label__en","ft_lang_prob":0.77905095,"math_prob":0.68556035,"size":4052,"snap":"2023-40-2023-50","text_gpt3_token_len":898,"char_repetition_ratio":0.10004941,"word_repetition_ratio":0.006472492,"special_character_ratio":0.20138204,"punctuation_ratio":0.096969694,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9787776,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12],"im_url_duplicate_count":[null,1,null,2,null,2,null,2,null,2,null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-04T23:42:06Z\",\"WARC-Record-ID\":\"<urn:uuid:269c6779-c692-4472-861c-2c75ca6bfa80>\",\"Content-Length\":\"496384\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:20d153d6-d7a6-46b8-aff6-4251fd43690d>\",\"WARC-Concurrent-To\":\"<urn:uuid:5efbf9b5-1bbc-40f7-bfed-5f3e535457c8>\",\"WARC-IP-Address\":\"23.73.247.190\",\"WARC-Target-URI\":\"https://docs.netapp.com/us-en/netapp-solutions/ai/aks-anf_load_day_15_in_dask_and_train_a_dask_cuml_random_forest_model.html\",\"WARC-Payload-Digest\":\"sha1:QDKJN4SPNQ742RYIJ5VYRW4TBLQGJQFN\",\"WARC-Block-Digest\":\"sha1:MA7KOE4AG3PYGG5F5YD7B4DBGKH2QBUN\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100535.26_warc_CC-MAIN-20231204214708-20231205004708-00225.warc.gz\"}"}