用法:
class cuml.TruncatedSVD(*, algorithm='full', handle=None, n_components=1, n_iter=15, random_state=None, tol=1e-07, verbose=False, output_type=None)
TruncatedSVD 用於計算大矩陣 X 的前 K 個奇異值和向量。當 n_components 較小時,速度要快得多,例如在使用 3 個分量進行 3D 可視化時使用 PCA。
cuML 的 TruncatedSVD 是一個 array-like 對象或 cuDF DataFrame,並提供 2 種算法 Full 和 Jacobi。 Full(默認)使用完整的特征分解,然後選擇前 K 個奇異向量。 Jacobi 算法要快得多,因為它迭代地嘗試糾正前 K 個奇異向量,但可能不太準確。
- algorithm:‘full’ or ‘jacobi’ 或 ‘auto’(默認 = ‘full’)
Full 使用協方差矩陣的特征分解然後丟棄分量。 Jacobi 在迭代校正時要快得多,但準確性較低。
- handle:cuml.Handle
指定 cuml.handle 保存用於此模型中計算的內部 CUDA 狀態。最重要的是,這指定了將用於模型計算的 CUDA 流,因此用戶可以通過在多個流中創建句柄在不同的流中同時運行不同的模型。如果為 None,則創建一個新的。
- n_components:int(默認值 = 1)
您想要的前 K 個奇異向量/值的數量。必須是 <= 數字(列)。
- n_iter:int(默認值 = 15)
用於 Jacobi 求解器。迭代次數越多,精度越高,但速度越慢。
- random_state:int /無(默認 = 無)
如果您希望重新啟動 Python 時結果相同,請選擇一個狀態。
- tol:浮點數(默認 = 1e-7)
如果算法 = “jacobi” 則使用。較小的容差可以提高準確性,但會減慢算法的收斂速度。
- verbose:int 或布爾值,默認=False
設置日誌記錄級別。它必須是
cuml.common.logger.level_*
之一。有關詳細信息,請參閱詳細級別。- output_type:{‘input’, ‘cudf’, ‘cupy’, ‘numpy’, ‘numba’},默認=無
用於控製估計器的結果和屬性的輸出類型的變量。如果為 None,它將繼承在模塊級別設置的輸出類型
cuml.global_settings.output_type
。有關詳細信息,請參閱輸出數據類型配置。
參數:
注意:
TruncatedSVD(隨機版本 [Jacobi])在您想要的組件數量遠小於函數數量時非常棒。對最大奇異值和向量的逼近非常穩健,但是,當您需要很多很多組件時,這種方法會失去很多準確性。
TruncatedSVD的應用
TruncatedSVD 也稱為潛在語義索引 (LSI),它試圖找到字數矩陣的主題。如果 X 以前以均值去除為中心,則 TruncatedSVD 與 TruncatedPCA 相同。TruncatedSVD 也用於信息檢索任務、推薦係統和數據壓縮。
有關其他文檔,請參閱 scikitlearn’s TruncatedSVD docs 。
例子:
# Both import methods supported from cuml import TruncatedSVD from cuml.decomposition import TruncatedSVD import cudf import numpy as np gdf_float = cudf.DataFrame() gdf_float['0'] = np.asarray([1.0,2.0,5.0], dtype = np.float32) gdf_float['1'] = np.asarray([4.0,2.0,1.0], dtype = np.float32) gdf_float['2'] = np.asarray([4.0,2.0,1.0], dtype = np.float32) tsvd_float = TruncatedSVD(n_components = 2, algorithm = "jacobi", n_iter = 20, tol = 1e-9) tsvd_float.fit(gdf_float) print(f'components: {tsvd_float.components_}') print(f'explained variance: {tsvd_float._explained_variance_}') exp_var = tsvd_float._explained_variance_ratio_ print(f'explained variance ratio: {exp_var}') print(f'singular values: {tsvd_float._singular_values_}') trans_gdf_float = tsvd_float.transform(gdf_float) print(f'Transformed matrix: {trans_gdf_float}') input_gdf_float = tsvd_float.inverse_transform(trans_gdf_float) print(f'Input matrix: {input_gdf_float}')
輸出:
components: 0 1 2 0 0.58725953 0.57233137 0.5723314 1 0.80939883 -0.41525528 -0.4152552 explained variance: 0 55.33908 1 16.660923 explained variance ratio: 0 0.7685983 1 0.23140171 singular values: 0 7.439024 1 4.0817795 Transformed Matrix: 0 1 2 0 5.1659107 -2.512643 1 3.4638448 -0.042223275 2 4.0809603 3.2164836 Input matrix: 0 1 2 0 1.0 4.000001 4.000001 1 2.0000005 2.0000005 2.0000007 2 5.000001 0.9999999 1.0000004
- components_:數組
U, S, VT = svd(X) 中的前 K 個分量 (VT.T[:,:n_components])
- explained_variance_:數組
每個組件在多大程度上解釋了 S**2 給出的數據中的差異
- explained_variance_ratio_:數組
S**2/sum(S**2) 解釋了多少百分比的方差
- singular_values_:數組
前 K 個奇異值。記住所有奇異值 >= 0
屬性:
相關用法
- Python cuml.metrics.pairwise_distances.pairwise_distances用法及代碼示例
- Python cuml.neighbors.KNeighborsClassifier用法及代碼示例
- Python cuml.ensemble.RandomForestRegressor用法及代碼示例
- Python cuml.svm.SVC用法及代碼示例
- Python cuml.svm.SVR用法及代碼示例
- Python cuml.Lasso用法及代碼示例
- Python cuml.tsa.ARIMA.predict用法及代碼示例
- Python cuml.multiclass.OneVsRestClassifier用法及代碼示例
- Python cuml.preprocessing.LabelBinarizer用法及代碼示例
- Python cuml.random_projection.GaussianRandomProjection用法及代碼示例
- Python cuml.MBSGDRegressor用法及代碼示例
- Python cuml.experimental.preprocessing.PolynomialFeatures用法及代碼示例
- Python cuml.PCA用法及代碼示例
- Python cuml.feature_extraction.text.HashingVectorizer用法及代碼示例
- Python cuml.DBSCAN用法及代碼示例
- Python cuml.dask.feature_extraction.text.TfidfTransformer用法及代碼示例
- Python cuml.common.memory_utils.using_output_type用法及代碼示例
- Python cuml.preprocessing.text.stem.PorterStemmer用法及代碼示例
- Python cuml.experimental.preprocessing.add_dummy_feature用法及代碼示例
- Python cuml.dask.manifold.UMAP用法及代碼示例
注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cuml.TruncatedSVD。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。