### Install pre-commit with pip Source: https://docs.nvidia.com/cuml/latest/developer_guide/code_quality Install the pre-commit tool using pip. ```bash pip install pre-commit ``` -------------------------------- ### Install cuml.accel Programmatically Source: https://docs.nvidia.com/cuml/latest/cuml-accel/usage Call the install method before importing the libraries to be accelerated. ```python import cuml cuml.accel.install() ``` -------------------------------- ### PowerTransformer Example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.preprocessing.PowerTransformer Example demonstrating how to instantiate PowerTransformer, fit it to data, and transform the data. ```APIDOC ### Example ```pycon >>> import cupy as cp >>> from cuml.preprocessing import PowerTransformer >>> pt = PowerTransformer() >>> data = cp.array([[1, 2], [3, 2], [4, 5]]) >>> print(pt.fit(data)) PowerTransformer() >>> print(pt.lambdas_) [ 1.386... -3.100...] >>> print(pt.transform(data)) [[-1.316... -0.707...] [ 0.209... -0.707...] [ 1.106... 1.414...]] ``` ``` -------------------------------- ### MaxAbsScaler Example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.preprocessing.MaxAbsScaler Example demonstrating how to instantiate MaxAbsScaler, fit it to data, and transform the data. ```APIDOC ### Example ```pycon >>> from cuml.preprocessing import MaxAbsScaler >>> import cupy as cp >>> X = [[ 1., -1., 2.], ... [ 2., 0., 0.], ... [ 0., 1., -1.]] >>> X = cp.array(X) >>> transformer = MaxAbsScaler().fit(X) >>> transformer MaxAbsScaler() >>> transformer.transform(X) array([[ 0.5, -1. , 1. ], [ 1. , 0. , 0. ], [ 0. , 1. , -0.5]]) ``` ``` -------------------------------- ### Expected GPU acceleration log output Source: https://docs.nvidia.com/cuml/latest/cuml-accel/examples/third-party-apps Example log messages confirming that the accelerator is installed and UMAP is running on the GPU. ```text [cuml.accel] Accelerator installed. [cuml.accel] `UMAP.fit_transform` ran on GPU ``` -------------------------------- ### Install Git hooks Source: https://docs.nvidia.com/cuml/latest/developer_guide/code_quality Initialize the pre-commit Git hooks from the repository root. ```bash pre-commit install ``` -------------------------------- ### Example: Using spectral_clustering with random data Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.cluster.spectral_clustering/index.html Shows how to import spectral_clustering, generate a random dataset, and apply clustering with specified parameters. The example uses n_clusters=5, n_neighbors=10, and random_state=42. ```pycon >>> import numpy as np >>> from cuml.cluster import spectral_clustering >>> X = np.random.rand(100, 10).astype(np.float32) >>> labels = spectral_clustering(X, n_clusters=5, n_neighbors=10, random_state=42) ``` -------------------------------- ### SVC Example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.svm.SVC Example demonstrating how to create an SVC instance, fit it to data, and make predictions using CuPy arrays. ```APIDOC ### Example ```python >>> import cupy as cp >>> from cuml.svm import SVC >>> X = cp.array([[1,1], [2,1], [1,2], [2,2], [1,3], [2,3]], ... dtype=cp.float32); >>> y = cp.array([-1, -1, 1, -1, 1, 1], dtype=cp.float32) >>> clf = SVC(kernel='poly', degree=2, gamma='auto', C=1) >>> clf.fit(X, y) SVC(C=1, degree=2, gamma='auto', kernel='poly') >>> print("Predicted labels:", clf.predict(X)) Predicted labels: [-1. -1. 1. -1. 1. 1.] ``` ``` -------------------------------- ### SGD Example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.solvers.SGD Example demonstrating how to create an SGD model, fit it to data, and make predictions using cuML. ```APIDOC ## SGD Example ### Description Example of using the SGD solver for regression with cuML. ### Code ```python >>> import numpy as np >>> import cudf >>> from cuml.solvers import SGD as cumlSGD >>> X = cudf.DataFrame() >>> X['col1'] = np.array([1,1,2,2], dtype=np.float32) >>> X['col2'] = np.array([1,2,2,3], dtype=np.float32) >>> y = cudf.Series(np.array([1, 1, 2, 2], dtype=np.float32)) >>> pred_data = cudf.DataFrame() >>> pred_data['col1'] = np.asarray([3, 2], dtype=np.float32) >>> pred_data['col2'] = np.asarray([5, 5], dtype=np.float32) >>> cu_sgd = cumlSGD(learning_rate='constant', eta0=0.005, epochs=2000, ... fit_intercept=True, batch_size=2, ... tol=0.0, penalty=None, loss='squared_loss') >>> cu_sgd.fit(X, y) SGD(batch_size=2, epochs=2000, eta0=0.005, tol=0.0) >>> cu_pred = cu_sgd.predict(pred_data).to_numpy() >>> print(" cuML intercept : ", cu_sgd.intercept_) cuML intercept : 0.00418... >>> print(" cuML coef : ", cu_sgd.coef_) cuML coef : 0 0.9841... 1 0.0097... dtype: float32 >>> print("cuML predictions : ", cu_pred) cuML predictions : [3.0055... 2.0214...] ``` ``` -------------------------------- ### ElasticNet Example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.linear_model.ElasticNet/index.html Example demonstrating how to create an ElasticNet model, fit it to data, and make predictions using cuML. ```APIDOC ## ElasticNet Example ### Description Example usage of the ElasticNet class from cuML, showing model creation, fitting, and prediction. ### Code ```pycon >>> import cupy as cp >>> import cudf >>> from cuml.linear_model import ElasticNet >>> enet = ElasticNet(alpha = 0.1, l1_ratio=0.5, solver='qn') >>> X = cudf.DataFrame() >>> X['col1'] = cp.array([0, 1, 2], dtype = cp.float32) >>> X['col2'] = cp.array([0, 1, 2], dtype = cp.float32) >>> y = cudf.Series(cp.array([0.0, 1.0, 2.0], dtype = cp.float32) ) >>> result_enet = enet.fit(X, y) >>> print(result_enet.coef_) 0 0.445... 1 0.445... dtype: float32 >>> print(result_enet.intercept_) 0.108433... >>> X_new = cudf.DataFrame() >>> X_new['col1'] = cp.array([3,2], dtype = cp.float32) >>> X_new['col2'] = cp.array([5,5], dtype = cp.float32) >>> preds = result_enet.predict(X_new) >>> print(preds) 0 3.674... 1 3.228... dtype: float32 ``` ``` -------------------------------- ### StandardScaler Example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.preprocessing.StandardScaler Example demonstrating how to create a StandardScaler, fit it to data, and transform data. ```APIDOC ### Example ```pycon >>> from cuml.preprocessing import StandardScaler >>> import cupy as cp >>> data = [[0, 0], [0, 0], [1, 1], [1, 1]] >>> data = cp.array(data) >>> scaler = StandardScaler() >>> print(scaler.fit(data)) StandardScaler() >>> print(scaler.mean_) [0.5 0.5] >>> print(scaler.transform(data)) [[-1. -1.] [-1. -1.] [ 1. 1.] [ 1. 1.]] >>> print(scaler.transform(cp.array([[2, 2]]))) [[3. 3.]] ``` ``` -------------------------------- ### install Source: https://docs.nvidia.com/cuml/latest/api/cuml.accel/index.html Enables the cuml.accel accelerator. This function should be called to activate the acceleration functionality. ```APIDOC ## install ### Description Enables the cuml.accel accelerator. ### Method install ### Parameters None ### Returns None ``` -------------------------------- ### LinearSVR Example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.svm.LinearSVR Example demonstrating how to create a LinearSVR model, fit it to data, and make predictions using CuPy arrays. ```APIDOC ### Example ```pycon >>> import cupy as cp >>> from cuml.svm import LinearSVR >>> X = cp.array([[1], [2], [3], [4], [5]], dtype=cp.float32) >>> y = cp.array([1.1, 4, 5, 3.9, 8.], dtype=cp.float32) >>> reg = LinearSVR(epsilon=0.1, C=10).fit(X, y) >>> print("Predicted values:", reg.predict(X)) Predicted values: [1.8993504 3.3995128 4.899675 6.399837 7.899999] ``` ``` -------------------------------- ### Install accelerator programmatically Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.accel.profile/index.html Use cuml.accel.install to ensure the accelerator is active before profiling. ```pycon >>> import cuml >>> cuml.accel.install() ``` -------------------------------- ### Install embedding-atlas Source: https://docs.nvidia.com/cuml/latest/cuml-accel/examples/third-party-apps Install the embedding-atlas tool alongside cuML. ```console pip install embedding-atlas ``` -------------------------------- ### PowerTransformer usage example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.preprocessing.PowerTransformer Demonstrates initializing the PowerTransformer, fitting it to data, and applying the transformation. ```pycon >>> import cupy as cp >>> from cuml.preprocessing import PowerTransformer >>> pt = PowerTransformer() >>> data = cp.array([[1, 2], [3, 2], [4, 5]]) >>> print(pt.fit(data)) PowerTransformer() >>> print(pt.lambdas_) [ 1.386... -3.100...] >>> print(pt.transform(data)) [[-1.316... -0.707...] [ 0.209... -0.707...] [ 1.106... 1.414...]] ``` -------------------------------- ### Install pre-commit with Conda Source: https://docs.nvidia.com/cuml/latest/developer_guide/code_quality Install the pre-commit tool using the conda-forge channel. ```bash conda install -c conda-forge pre-commit ``` -------------------------------- ### Fit and Predict with QN Solver Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.solvers.QN Demonstrates initializing the QN solver with a sigmoid loss function, fitting it to input data, and generating predictions. ```pycon >>> import cupy as cp >>> from cuml.solvers import QN >>> X = cp.array([[1, 1], [1, 2], [2, 2], [2, 3]]) >>> y = cp.array([0, 0, 1, 1]) >>> solver = QN(loss="sigmoid").fit(X, y) >>> solver.predict(X) array([0, 0, 1, 1], dtype=int32) ``` -------------------------------- ### GaussianRandomProjection Example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.random_projection.GaussianRandomProjection Example demonstrating how to use GaussianRandomProjection to reduce the dimensionality of a dataset. ```APIDOC ## GaussianRandomProjection Example ### Description Example usage of GaussianRandomProjection to reduce the dimensionality of a dataset. ### Code ```pycon >>> from cuml.random_projection import GaussianRandomProjection >>> from cuml.datasets import make_blobs >>> X, _ = make_blobs(n_samples=200, n_features=1000, random_state=42) >>> model = GaussianRandomProjection(n_components=50, random_state=42) >>> X_new = model.fit_transform(X) >>> X_new.shape (200, 50) ``` ``` -------------------------------- ### QuantileTransformer Example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.preprocessing.QuantileTransformer Example demonstrating how to use QuantileTransformer to fit and transform data. ```APIDOC ### Example ```pycon >>> import cupy as cp >>> from cuml.preprocessing import QuantileTransformer >>> rng = cp.random.RandomState(0) >>> X = cp.sort(rng.normal(loc=0.5, scale=0.25, size=(25, 1)), axis=0) >>> qt = QuantileTransformer(n_quantiles=10, random_state=0) >>> qt.fit_transform(X) array([...]) ``` ``` -------------------------------- ### GaussianRandomProjection usage example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.random_projection.GaussianRandomProjection Demonstrates how to initialize the GaussianRandomProjection model, fit it to a dataset, and transform the data to a lower-dimensional space. ```pycon >>> from cuml.random_projection import GaussianRandomProjection >>> from cuml.datasets import make_blobs >>> X, _ = make_blobs(n_samples=200, n_features=1000, random_state=42) >>> model = GaussianRandomProjection(n_components=50, random_state=42) >>> X_new = model.fit_transform(X) >>> X_new.shape (200, 50) ``` -------------------------------- ### KMeans Clustering Example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.cluster.KMeans Demonstrates how to import KMeans, prepare data using cudf, fit the model, and access labels and cluster centers. ```python >>> # Both import methods supported >>> from cuml import KMeans >>> from cuml.cluster import KMeans >>> import cudf >>> import numpy as np >>> import pandas as pd >>> >>> a = np.asarray([[1.0, 1.0], [1.0, 2.0], [3.0, 2.0], [4.0, 3.0]], ... dtype=np.float32) >>> b = cudf.DataFrame(a) >>> # Input: >>> b 0 1 0 1.0 1.0 1 1.0 2.0 2 3.0 2.0 3 4.0 3.0 >>> >>> # Calling fit >>> kmeans_float = KMeans(n_clusters=2, n_init="auto", random_state=1) >>> kmeans_float.fit(b) KMeans(n_clusters=2, random_state=1) >>> >>> # Labels: >>> kmeans_float.labels_ 0 0 1 0 2 1 3 1 dtype: int32 >>> # cluster_centers: >>> kmeans_float.cluster_centers_ 0 1 0 1.0 1.5 1 3.5 2.5 ``` -------------------------------- ### MissingIndicator Example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.preprocessing.MissingIndicator Example demonstrating how to use MissingIndicator to transform data with missing values. ```APIDOC ## MissingIndicator Example ### Description Demonstrates fitting a MissingIndicator on one dataset and transforming another to obtain boolean missing value indicators. ### Code ```pycon >>> import numpy as np >>> from sklearn.impute import MissingIndicator >>> X1 = np.array([[np.nan, 1, 3], ... [4, 0, np.nan], ... [8, 1, 0]]) >>> X2 = np.array([[5, 1, np.nan], ... [np.nan, 2, 3], ... [2, 4, 0]]) >>> indicator = MissingIndicator() >>> indicator.fit(X1) MissingIndicator() >>> X2_tr = indicator.transform(X2) >>> X2_tr array([[False, True], [ True, False], [False, False]]) ``` ``` -------------------------------- ### ColumnTransformer Example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.compose.ColumnTransformer Example demonstrating how to use ColumnTransformer with Normalizer on different column subsets. ```APIDOC ## ColumnTransformer Example ### Description Demonstrates creating a ColumnTransformer with two Normalizer transformers applied to different column subsets, and fitting/transforming a sample array. ### Code ```pycon >>> import cupy as cp >>> from cuml.compose import ColumnTransformer >>> from cuml.preprocessing import Normalizer >>> ct = ColumnTransformer( ... [("norm1", Normalizer(norm='l1'), [0, 1]), ... ("norm2", Normalizer(norm='l1'), slice(2, 4))]) >>> X = cp.array([[0., 1., 2., 2.], ... [1., 1., 0., 1.]]) >>> # Normalizer scales each row of X to unit norm. A separate scaling >>> # is applied for the two first and two last elements of each >>> # row independently. >>> ct.fit_transform(X) array([[0. , 1. , 0.5, 0.5], [0.5, 0.5, 0. , 1. ]]) ``` ``` -------------------------------- ### NearestNeighbors Example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.neighbors.NearestNeighbors Example usage of NearestNeighbors to fit data and generate a radius neighbors graph. ```APIDOC ## NearestNeighbors Example ### Description Example of using the NearestNeighbors class to fit data and generate a radius neighbors graph. ### Code ```pycon >>> import cupy as cp >>> from cuml.neighbors import NearestNeighbors >>> X = cp.array([[0], [3], [1]]) >>> nn = NearestNeighbors().fit(X) >>> A = nn.radius_neighbors_graph(X, radius=1.5) >>> A.toarray() array([[1., 0., 1.], [0., 1., 0.], [1., 0., 1.]]) ``` ``` -------------------------------- ### Generate a classification dataset with Dask Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.dask.datasets.make_classification/index.html This example demonstrates how to initialize a Dask cluster and generate a classification dataset using make_classification. ```python >>> from dask.distributed import Client >>> from dask_cuda import LocalCUDACluster >>> from cuml.dask.datasets.classification import make_classification >>> cluster = LocalCUDACluster() >>> client = Client(cluster) >>> X, y = make_classification(n_samples=10, n_features=4, ... random_state=1, n_informative=2, ... n_classes=2) >>> print(X.compute()) [[-1.1273878 1.2844919 -0.32349187 0.1595734 ] [ 0.80521786 -0.65946865 -0.40753683 0.15538901] [ 1.0404129 -1.481386 1.4241115 1.2664981 ] [-0.92821544 -0.6805706 -0.26001272 0.36004275] [-1.0392245 -1.1977317 0.16345565 -0.21848428] [ 1.2273135 -0.529214 2.4799604 0.44108105] [-1.9163864 -0.39505136 -1.9588828 -1.8881643 ] [-0.9788184 -0.89851004 -0.08339313 0.1130247 ] [-1.0549078 -0.8993015 -0.11921967 0.04821599] [-1.8388828 -1.4063598 -0.02838472 -1.0874642 ]] >>> print(y.compute()) [1 0 0 0 0 1 0 0 0 0] >>> client.close() >>> cluster.close() ``` -------------------------------- ### Ridge Example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.linear_model.Ridge/index.html Example demonstrating how to create a Ridge model, fit it on data, and make predictions. ```APIDOC ### Example ```pycon >>> import cupy as cp >>> import cudf >>> from cuml import Ridge ``` ```pycon >>> X = cudf.DataFrame() >>> X['col1'] = cp.array([1,1,2,2], dtype = cp.float32) >>> X['col2'] = cp.array([1,2,2,3], dtype = cp.float32) >>> y = cudf.Series(cp.array([6.0, 8.0, 9.0, 11.0], dtype=cp.float32)) ``` ```pycon >>> ridge = Ridge(alpha=1e-5).fit(X, y) >>> print(ridge.coef_) 0 1.000... 1 1.999... >>> print(ridge.intercept_) 3.0... >>> X_new = cudf.DataFrame() >>> X_new['col1'] = cp.array([3,2], dtype=cp.float32) >>> X_new['col2'] = cp.array([5,5], dtype=cp.float32) >>> preds = ridge.predict(X_new) >>> print(preds) 0 15.999... 1 14.999... ``` ``` -------------------------------- ### RandomForestClassifier Example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.ensemble.RandomForestClassifier/index.html Example demonstrating how to create, fit, and predict with the RandomForestClassifier using CuPy arrays. ```APIDOC ## RandomForestClassifier Example ### Description This example shows how to instantiate a RandomForestClassifier, fit it on synthetic data, and make predictions. ### Code ```python >>> import cupy as cp >>> from cuml.ensemble import RandomForestClassifier as cuRFC >>> X = cp.random.normal(size=(10,4)).astype(cp.float32) >>> y = cp.asarray([0,1]*5, dtype=cp.int32) >>> cuml_model = cuRFC(max_features=1.0, ... n_bins=8, ... n_estimators=40) >>> cuml_model.fit(X,y) RandomForestClassifier() >>> cuml_predict = cuml_model.predict(X) >>> print("Predicted labels : ", cuml_predict) Predicted labels : [0. 1. 0. 1. 0. 1. 0. 1. 0. 1.] ``` ``` -------------------------------- ### QuantileTransformer usage example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.preprocessing.QuantileTransformer Demonstrates how to initialize the QuantileTransformer and apply it to a dataset using fit_transform. ```pycon >>> import cupy as cp >>> from cuml.preprocessing import QuantileTransformer >>> rng = cp.random.RandomState(0) >>> X = cp.sort(rng.normal(loc=0.5, scale=0.25, size=(25, 1)), axis=0) >>> qt = QuantileTransformer(n_quantiles=10, random_state=0) >>> qt.fit_transform(X) array([...]) ``` -------------------------------- ### LinearSVC Example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.svm.LinearSVC Example demonstrating how to create, fit, and predict with a LinearSVC model using CuPy arrays. ```APIDOC ### Example ```pycon >>> import cupy as cp >>> from cuml.svm import LinearSVC >>> X = cp.array([[1,1], [2,1], [1,2], [2,2], [1,3], [2,3]], ... dtype=cp.float32); >>> y = cp.array([0, 0, 1, 0, 1, 1], dtype=cp.float32) >>> clf = LinearSVC(penalty='l1', C=1).fit(X, y) >>> print("Predicted labels:", clf.predict(X)) Predicted labels: [0 0 1 0 1 1] ``` ``` -------------------------------- ### SparseRandomProjection usage example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.random_projection.SparseRandomProjection Demonstrates how to initialize the SparseRandomProjection model, fit it to a dataset, and transform the data to a lower dimension. ```pycon >>> from cuml.random_projection import SparseRandomProjection >>> from cuml.datasets import make_blobs >>> X, _ = make_blobs(n_samples=200, n_features=1000, random_state=42) >>> model = SparseRandomProjection(n_components=50, random_state=42) >>> X_new = model.fit_transform(X) >>> X_new.shape (200, 50) ``` -------------------------------- ### LogisticRegression Example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.linear_model.LogisticRegression/index.html Example demonstrating how to create, fit, and predict with a LogisticRegression model using cuML and CuPy. ```APIDOC ## LogisticRegression Example ### Description Demonstrates basic usage of the cuML LogisticRegression model. ### Code ```pycon >>> import cuml >>> import cupy as cp >>> X = cp.array([[1, 1], [1, 2], [2, 2], [2, 3]]) >>> y = cp.array([0, 0, 1, 1]) >>> model = cuml.LogisticRegression().fit(X, y) >>> model.predict(X) array([0, 0, 1, 1]) ``` ``` -------------------------------- ### MinMaxScaler usage example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.preprocessing.MinMaxScaler Demonstrates initializing the scaler, fitting it to data, and transforming both the original data and new samples. ```pycon >>> from cuml.preprocessing import MinMaxScaler >>> import cupy as cp >>> data = [[-1, 2], [-0.5, 6], [0, 10], [1, 18]] >>> data = cp.array(data) >>> scaler = MinMaxScaler() >>> print(scaler.fit(data)) MinMaxScaler() >>> print(scaler.data_max_) [ 1. 18.] >>> print(scaler.transform(data)) [[0. 0. ] [0.25 0.25] [0.5 0.5 ] [1. 1. ]] >>> print(scaler.transform(cp.array([[2, 2]]))) [[1.5 0. ]] ``` -------------------------------- ### Discretizing data with KBinsDiscretizer Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.preprocessing.KBinsDiscretizer This example demonstrates how to initialize, fit, and transform data using KBinsDiscretizer with uniform binning strategy. ```pycon >>> from cuml.preprocessing import KBinsDiscretizer >>> import cupy as cp >>> X = [[-2, 1, -4, -1], ... [-1, 2, -3, -0.5], ... [ 0, 3, -2, 0.5], ... [ 1, 4, -1, 2]] >>> X = cp.array(X) >>> est = KBinsDiscretizer(n_bins=3, encode='ordinal', strategy='uniform') >>> est.fit(X) KBinsDiscretizer(...) >>> Xt = est.transform(X) >>> Xt array([[0, 0, 0, 0], [1, 1, 1, 0], [2, 2, 2, 1], [2, 2, 2, 2]], dtype=int32) ``` -------------------------------- ### TruncatedSVD Example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.decomposition.TruncatedSVD Example demonstrating how to use TruncatedSVD with cuDF and CuPy, including fitting, transforming, and inverse transforming. ```APIDOC ## TruncatedSVD Example ### Description Demonstrates usage of TruncatedSVD with cuDF and CuPy. ### Code ```python >>> # Both import methods supported >>> from cuml import TruncatedSVD >>> from cuml.decomposition import TruncatedSVD >>> import cudf >>> import cupy as cp >>> gdf_float = cudf.DataFrame() >>> gdf_float['0'] = cp.asarray([1.0,2.0,5.0], dtype=cp.float32) >>> gdf_float['1'] = cp.asarray([4.0,2.0,1.0], dtype=cp.float32) >>> gdf_float['2'] = cp.asarray([4.0,2.0,1.0], dtype=cp.float32) >>> tsvd_float = TruncatedSVD(n_components = 2, algorithm = "jacobi", ... n_iter = 20, tol = 1e-9) >>> tsvd_float.fit(gdf_float) TruncatedSVD(algorithm='jacobi', n_components=2, n_iter=20, tol=1e-09) >>> print(f'components: {tsvd_float.components_}') components: 0 1 2 0 0.587259 0.572331 0.572331 1 0.809399 -0.415255 -0.415255 >>> exp_var = tsvd_float.explained_variance_ >>> print(f'explained variance: {exp_var}') explained variance: 0 0.494... 1 5.505... dtype: float32 >>> exp_var_ratio = tsvd_float.explained_variance_ratio_ >>> print(f'explained variance ratio: {exp_var_ratio}') explained variance ratio: 0 0.082... 1 0.917... dtype: float32 >>> sing_values = tsvd_float.singular_values_ >>> print(f'singular values: {sing_values}') singular values: 0 7.439... 1 4.081... dtype: float32 >>> trans_gdf_float = tsvd_float.transform(gdf_float) >>> print(f'Transformed matrix: {trans_gdf_float}') Transformed matrix: 0 1 0 5.165910 -2.512643 1 3.463844 -0.042223 2 4.080960 3.216484 >>> input_gdf_float = tsvd_float.inverse_transform(trans_gdf_float) >>> print(f'Input matrix: {input_gdf_float}') Input matrix: 0 1 2 0 1.0 4.0 4.0 1 2.0 2.0 2.0 2 5.0 1.0 1.0 ``` ``` -------------------------------- ### cuml.accel.install Source: https://docs.nvidia.com/cuml/latest/api Install cuML acceleration hooks. This function sets up the necessary hooks to enable cuML acceleration. ```APIDOC ## cuml.accel.install ### Description Install cuML acceleration hooks. ### Module cuml.accel ### Usage Call this function to enable cuML acceleration. ``` -------------------------------- ### Install cuML Dask dependencies Source: https://docs.nvidia.com/cuml/latest/dask_multigpu_guide Commands to install the necessary dependencies for using cuML with Dask via Conda or pip. ```bash # Install with Conda: conda install rapids-dask-dependency dask-cudf raft-dask # Or install with pip (replace cu13 with your CUDA version): pip install cuml-cu13[dask] ``` -------------------------------- ### Example Script for Profiling Source: https://docs.nvidia.com/cuml/latest/cuml-accel/logging-and-profiling A sample script demonstrating Ridge regression usage that triggers both GPU acceleration and CPU fallback scenarios. ```python from sklearn.linear_model import Ridge from sklearn.datasets import make_regression X, y = make_regression(n_samples=100) # Fit and predict on GPU ridge = Ridge(alpha=1.0) ridge.fit(X, y) ridge.predict(X) # Retry, using a hyperparameter that isn't supported on GPU ridge = Ridge(positive=True) ridge.fit(X, y) ridge.predict(X) ``` -------------------------------- ### Initialize CD solver Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.solvers.CD Import necessary libraries and initialize the CD solver with alpha=0.0. ```pycon >>> import cupy as cp >>> import cudf >>> from cuml.solvers import CD ``` ```pycon >>> cd = CD(alpha=0.0) ``` -------------------------------- ### LinearSVR usage example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.svm.LinearSVR Demonstrates initializing, fitting, and predicting with LinearSVR using CuPy arrays. ```pycon >>> import cupy as cp >>> from cuml.svm import LinearSVR >>> X = cp.array([[1], [2], [3], [4], [5]], dtype=cp.float32) >>> y = cp.array([1.1, 4, 5, 3.9, 8.], dtype=cp.float32) >>> reg = LinearSVR(epsilon=0.1, C=10).fit(X, y) >>> print("Predicted values:", reg.predict(X)) Predicted values: [1.8993504 3.3995128 4.899675 6.399837 7.899999] ``` -------------------------------- ### PCA Example Source: https://docs.nvidia.com/cuml/latest/api/generated/cuml.decomposition.PCA/index.html Example demonstrating how to use PCA with cuDF and CuPy, including fitting, transforming, and inverse transforming data. ```APIDOC ## PCA Example ### Description Demonstrates the usage of the PCA class from cuML, including both import methods, fitting on a cuDF DataFrame, and accessing attributes like components_, explained_variance_, and singular_values_. ### Code ```python >>> # Both import methods supported >>> from cuml import PCA >>> from cuml.decomposition import PCA >>> import cudf >>> import cupy as cp >>> gdf_float = cudf.DataFrame() >>> gdf_float['0'] = cp.asarray([1.0,2.0,5.0], dtype = cp.float32) >>> gdf_float['1'] = cp.asarray([4.0,2.0,1.0], dtype = cp.float32) >>> gdf_float['2'] = cp.asarray([4.0,2.0,1.0], dtype = cp.float32) >>> pca_float = PCA(n_components = 2) >>> pca_float.fit(gdf_float) PCA(n_components=2) >>> print(f'components: {pca_float.components_}') components: 0 1 2 0 0.69225764 -0.5102837 -0.51028395 1 -0.72165036 -0.48949987 -0.4895003 >>> print(f'explained variance: {pca_float.explained_variance_}') explained variance: 0 8.510... 1 0.489... dtype: float32 >>> exp_var = pca_float.explained_variance_ratio_ >>> print(f'explained variance ratio: {exp_var}') explained variance ratio: 0 0.9456... 1 0.054... dtype: float32 >>> print(f'singular values: {pca_float.singular_values_}') singular values: 0 4.125... 1 0.989... dtype: float32 >>> print(f'mean: {pca_float.mean_}') mean: 0 2.666... 1 2.333... 2 2.333... dtype: float32 >>> trans_gdf_float = pca_float.transform(gdf_float) >>> print(f'Inverse: {trans_gdf_float}') Inverse: 0 1 0 -2.8547091 -0.42891636 1 -0.121316016 0.80743366 2 2.9760244 -0.37851727 >>> input_gdf_float = pca_float.inverse_transform(trans_gdf_float) >>> print(f'Input: {input_gdf_float}') Input: 0 1 2 0 1.0 4.0 4.0 1 2.0 2.0 2.0 2 5.0 1.0 1.0 ``` ```