用法:
class cuml.SGD(*, loss='squared_loss', penalty='none', alpha=0.0001, l1_ratio=0.15, fit_intercept=True, epochs=1000, tol=0.001, shuffle=True, learning_rate='constant', eta0=0.001, power_t=0.5, batch_size=32, n_iter_no_change=5, handle=None, output_type=None, verbose=False)
隨機梯度下降是一種非常常見的機器學習算法,通過梯度步驟優化一些成本函數。這使得 SGD 對於很難甚至不可能找到確切解決方案的大型問題非常有吸引力。
cuML 的 SGD 算法接受 numpy 矩陣或 cuDF DataFrame 作為輸入數據集。 SGD 算法目前適用於線性回歸、嶺回歸和 SVM 模型。
- loss:‘hinge’, ‘log’、‘squared_loss’(默認 = ‘squared_loss’)
‘hinge’ 使用線性 SVM ‘log’ 使用邏輯回歸 ‘squared_loss’ 使用線性回歸
- penalty: ‘none’, ‘l1’, ‘l2’, ‘elasticnet’ (default = ‘none’):
‘none’ 不執行任何正則化 ‘l1’ 執行 L1 範數(Lasso),最小化係數的絕對值之和 ‘l2’ 執行 L2 範數(Ridge),最小化係數的平方和 ‘elasticnet’ 執行彈性網絡正則化,它是 L1 和 L2 範數的加權平均
- alpha: float (default = 0.0001):
決定正則化程度的常數值
- fit_intercept:布爾值(默認 = True)
如果為 True,模型會嘗試校正 y 的全局平均值。如果為 False,則模型預計您已將數據居中。
- epochs:int(默認值 = 1000)
模型在訓練期間應該遍曆整個數據集的次數(默認 = 1000)
- tol:浮點數(默認 = 1e-3)
如果 current_loss > previous_loss - tol,訓練過程將停止
- shuffle:布爾值(默認 = True)
True,在每個 epoch 之後打亂訓練數據 False,在每個 epoch 之後不打亂訓練數據
- eta0:浮點數(默認 = 0.001)
初始學習率
- power_t:浮點數(默認 = 0.5)
用於計算 invscaling 學習率的 index
- learning_rate:‘optimal’, ‘constant’, ‘invscaling’、‘adaptive’(默認 = ‘constant’)
下一個版本中支持的最佳選項常量保持學習率常量如果訓練損失或驗證準確度在 n_iter_no_change 個時期內沒有提高,則自適應地改變學習率。老學習率一般除以5
- n_iter_no_change:int(默認值 = 5)
在模型沒有任何改進的情況下訓練的 epoch 數
- handle:cuml.Handle
指定 cuml.handle 保存用於此模型中計算的內部 CUDA 狀態。最重要的是,這指定了將用於模型計算的 CUDA 流,因此用戶可以通過在多個流中創建句柄在不同的流中同時運行不同的模型。如果為 None,則創建一個新的。
- output_type:{‘input’, ‘cudf’, ‘cupy’, ‘numpy’, ‘numba’},默認=無
用於控製估計器的結果和屬性的輸出類型的變量。如果為 None,它將繼承在模塊級別設置的輸出類型
cuml.global_settings.output_type
。有關詳細信息,請參閱輸出數據類型配置。- verbose:int 或布爾值,默認=False
設置日誌記錄級別。它必須是
cuml.common.logger.level_*
之一。有關詳細信息,請參閱詳細級別。
參數:
例子:
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) cu_pred = cu_sgd.predict(pred_data).to_numpy() print(" cuML intercept : ", cu_sgd.intercept_) print(" cuML coef : ", cu_sgd.coef_) print("cuML predictions : ", cu_pred)
輸出:
cuML intercept : 0.0041877031326293945 cuML coef : 0 0.984174 1 0.009776 dtype: float32 cuML predictions : [3.005588 2.0214138]
- classes_:
- 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.SGD。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。