用法:
class cuml.CD(*, loss='squared_loss', alpha=0.0001, l1_ratio=0.15, fit_intercept=True, normalize=False, max_iter=1000, tol=0.001, shuffle=True, handle=None, output_type=None, verbose=False)
坐標下降 (CD) 是一種非常常見的優化算法,它沿著坐標方向最小化以找到函數的最小值。
cuML 的 CD 算法接受 numpy 矩陣或 cuDF DataFrame 作為輸入 dataset.algorithm CD 算法目前適用於線性回歸和 ridge、lasso 和 elastic-net 懲罰。
- loss:‘squared_loss’(目前僅支持‘squared_loss’)
‘squared_loss’ 使用線性回歸
- alpha: float (default = 0.0001):
決定正則化程度的常數值。 ‘alpha = 0’相當於普通的最小二乘,由LinearRegression對象解決。
- l1_ratio: float (default = 0.15):
ElasticNet 混合參數,0 <= l1_ratio <= 1。對於 l1_ratio = 0,懲罰是 L2 懲罰。對於 l1_ratio = 1,這是 L1 懲罰。對於 0 < l1_ratio < 1,懲罰是 L1 和 L2 的組合。
- fit_intercept:布爾值(默認 = True)
如果為 True,模型會嘗試校正 y 的全局平均值。如果為 False,則模型預計您已將數據居中。
- max_iter:int(默認值 = 1000)
模型在訓練期間應該遍曆整個數據集的次數(默認 = 1000)
- tol:浮點數(默認 = 1e-3)
優化的容差:如果更新小於 tol,求解器停止。
- shuffle:布爾值(默認 = True)
如果設置為“True”,則每次迭代都會更新隨機係數,而不是默認按順序循環特征。這(設置為“True”)通常會導致收斂速度明顯加快,尤其是當 tol 高於 1e-4 時。
- handle:cuml.Handle
指定 cuml.handle 保存用於此模型中計算的內部 CUDA 狀態。最重要的是,這指定了將用於模型計算的 CUDA 流,因此用戶可以通過在多個流中創建句柄在不同的流中同時運行不同的模型。如果為 None,則創建一個新的。
- verbose:int 或布爾值,默認=False
設置日誌記錄級別。它必須是
cuml.common.logger.level_*
之一。有關詳細信息,請參閱詳細級別。- output_type:{‘input’, ‘cudf’, ‘cupy’, ‘numpy’, ‘numba’},默認=無
用於控製估計器的結果和屬性的輸出類型的變量。如果為 None,它將繼承在模塊級別設置的輸出類型
cuml.global_settings.output_type
。有關詳細信息,請參閱輸出數據類型配置。
參數:
例子:
import numpy as np import cudf from cuml.solvers import CD as cumlCD cd = cumlCD(alpha=0.0) 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([6.0, 8.0, 9.0, 11.0], dtype = np.float32) ) reg = cd.fit(X,y) print("Coefficients:") print(reg.coef_) print("intercept:") print(reg.intercept_) X_new = cudf.DataFrame() X_new['col1'] = np.array([3,2], dtype = np.float32) X_new['col2'] = np.array([5,5], dtype = np.float32) preds = cd.predict(X_new) print(preds)
輸出:
Coefficients: 0 1.0019531 1 1.9980469 Intercept: 3.0 Preds: 0 15.997 1 14.995
- coef_:
屬性:
相關用法
- 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.TruncatedSVD用法及代碼示例
- Python cuml.common.memory_utils.using_output_type用法及代碼示例
- Python cuml.preprocessing.text.stem.PorterStemmer用法及代碼示例
- Python cuml.experimental.preprocessing.add_dummy_feature用法及代碼示例
注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cuml.CD。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。