用法:
class cuml.ForestInference(*, handle=None, output_type=None, verbose=False)
ForestInference 为随机森林和增强决策树模型提供GPU-accelerated 推理(预测)。
该模块不支持训练模型。相反,用户应该在另一个包中训练模型并将其保存为 treelite-compatible 格式。 (参见https://github.com/dmlc/treelite)目前支持LightGBM XGBoost 和 SKLearn GBDT 和随机森林模型。
用户通常通过使用ForestInference.load加载保存的模型文件来创建ForestInference对象。也可以使用ForestInferenceload_from_sklearn从SKLearn模型创建它。生成的对象提供
predict
方法来执行推理。- 已知限制:
- 单行数据应该适合线程块的共享内存,否则(从 5000-12288 个特征开始)FIL 可能推断较慢
- 仅来自 sklearn.ensemble
{RandomForest,GradientBoosting,ExtraTrees}{Classifier,Regressor}
支持模型。目前不支持其他sklearn.ensemble 型号。 - 导入大型 SKLearn 模型可能会很慢,因为它是在 Python 中完成的。
- LightGBM 分类特征不受支持。
- 推理使用密集矩阵格式,这对许多问题都很有效,但对于稀疏数据集可能不是最优的。
- 仅支持分类和回归。
- 许多其他随机森林实现,包括 LightGBM 和 SKLearn GBDT 都使用 64 位浮点参数,但 ForestInference 的底层库仅使用 32 位参数。由于在将此类模型加载到 ForestInference 时会发生截断,您可能会观察到准确性略有下降。
- 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
。有关详细信息,请参阅输出数据类型配置。
参数:
注意:
有关其他使用示例,请参阅示例笔记本,位于https://github.com/rapidsai/cuml/blob/branch-0.15/notebooks/forest_inference_demo.ipynb
例子:
在下面的示例中,合成数据在推理之前被复制到主机。 ForestInference 也可以直接接受 numpy 数组,但会产生轻微的性能开销。
# Assume that the file 'xgb.model' contains a classifier model that was # previously saved by XGBoost's save_model function. import sklearn, sklearn.datasets, numpy as np from numba import cuda from cuml import ForestInference model_path = 'xgb.model' X_test, y_test = sklearn.datasets.make_classification() X_gpu = cuda.to_device(np.ascontiguousarray(X_test.astype(np.float32))) fm = ForestInference.load(model_path, output_class=True) fil_preds_gpu = fm.predict(X_gpu) accuracy_score = sklearn.metrics.accuracy_score(y_test, np.asarray(fil_preds_gpu))
相关用法
- 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.ForestInference。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。