用法:
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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。