万壑松风知客来,摇扇抚琴待留声
说明:对 auto-sklearn 的所有参数做一个记录,旨在帮助使用者能快速了解、自定义 auto-sklearn,从而达到尽量充分的使用该工具
1. Auto-Sklearn
本文只说参数,不做介绍,介绍可参考另一篇文章。由于项目原因这里以回归问题作为记录主题进行阐述,其中所有参数的表述由本人参考官方文档和较为专业的文献得出,所以有疑问者可以从官方文档找寻答案。
1 | # Regression |
2. 参数详解
2.1. time_left_for_this_task: int, optional (default=3600)
(目前理解两个时间参数是独立的)。auto-sklearn 整体运行时间,以秒为时间单位限制来搜索合适的模型们。通过增加这个值,auto-sklearn 将会有更高的机会找到更好的模型。官方给出的建议时间为 24 小时,也就是 time_left_for_this_task=86400 。
说明:当时间不够时,auto-sklearn 会给出一个 metalearning 的值。可能这个值不是 SMAC 算法能给出的最好结果,但依旧是一个效果不错的超参数选择。
2.2. per_run_time_limit: int, optional (default=360)
(目前理解两个时间参数是独立的)调用单次机器学习模型的时间(单位秒)限制。如果该机器学习算法超过这个时间限制,模型拟合将会被终止。将此值设置得足够高,以便典型的机器学习算法可以拟合的更好。官方给出的每个模型建议时间为 1 小时,也就是 per_run_time_limit=3600 。
说明:当时间不够时,auto-sklearn 会给出一个 metalearning 的值。可能这个值不是 SMAC 算法能给出的最好结果,但依旧是一个效果不错的超参数选择。
2.3.(理解模糊) initial_configurations_via_metalearning: int, optional (default=25)
(issues)使用一定的配置数量,初始化超参数优化算法,这些配置在先前看到的数据集上运行良好,官方测试 25 最好。通过元学习选择的配置数量以热启动 SMAC 算法。如果超参数优化算法应从头开始,则禁用设置为 0。
auto-sklearn 支持在共享文件系统上共享数据共享并行执行。在这种模式下,SMAC 算法通过每次迭代后将其写入磁盘,共享其模型的训练数据。在每次迭代开始时,SMAC 都会加载所有新发现的数据点。在示例目录中可以找到一个示例。将元学习的初始配置设置为零,使得 auto-sklearn 使用常规的 SMAC 算法来表示新的超参数配置。
2.4. ensemble_size: int, optional (default=50)
设定模型集成数量。从 auto-sklearn 的模型库中通过集成选择,选择添加到集成模型中的的模型数量。Models are drawn with replacement。
2.5. ensemble_nbest: int, optional (default=50)
当构建一个集成模型时,只考虑 n 个最好的模型。从集合选择中获取最大化,实现模型库修剪。
2.6. ensemble_memory_limit: int, optional (1024)
集成构建过程的内存限制(单位MB)。如果达到内存限制,auto-sklearn 将减少所考虑模型的数量(ensemble_nbest)。
说明:我们电脑的配置完全够用了。我忘了从哪里看到的,目前的电脑内存 8G 足够,给出 3-4G 就行,仅供参考。
2.7. (理解模糊)seed: int, optional (default=1)
设定 SMAC 的种子,将确定输出的文件名。
2.8. ml_memory_limit: int, optional (3072)
机器学习算法的内存限制(MB)。如果 auto-sklearn 尝试分配超过 ml_memory_limit MB,则会停止使用机器学习算法。
2.9. include_estimators: list, optional (None)
如果为 None,将尝试使用所有可能的模型,否则使用指定列表中的一组估计器。
16 classifiers
(可以被指定或者筛选,include_estimators=[“random_forest”, ])
- adaboost, bernoulli_nb, decision_tree, extra_trees, gaussian_nb, gradient_boosting, k_nearest_neighbors, lda, liblinear_svc, libsvm_svc, multinomial_nb, passive_aggressive, qda, random_forest, sgd, xgradient_boosting
13 regressors
(可以被指定或者筛选,exclude_estimators=None)
- adaboost, ard_regression, decision_tree, extra_trees, gaussian_process, gradient_boosting, k_nearest_neighbors, liblinear_svr, libsvm_svr, random_forest, ridge_regression, sgd, xgradient_boosting
2.10. exclude_estimators: list, optional (None)
如果为 None,将尝试使用所有可能的模型,否则不使用指定列表中的一组估计器。与参数 include_estimators 不兼容。
2.11. include_preprocessors: list, optional (None)
如果为 None,将会使用所有可能的预处理器,否则使用指定的一组预处理器。
- 18 feature preprocessing methods(这些过程可以被手动关闭全部或者部分,include_preprocessors=[“no_preprocessing”, ]),如下:
- densifier, extra_trees_preproc_for_classification, extra_trees_preproc_for_regression, fast_ica,feature_agglomeration, kernel_pca, kitchen_sinks, liblinear_svc_preprocessor, no_preprocessing, nystroem_sampler, pca, polynomial, random_trees_embedding, select_percentile, select_percentile_classification, select_percentile_regression, select_rates, truncatedSVD
2.12. exclude_preprocessors: list, optional (None)
如果为 None,将会使用所有可能的预处理器,否则不使用指定的一组预处理器。与参数 include_preprocessors不兼容。
2.13. resampling_strategy: string or object, optional (‘holdout’)
重采样策略。防止过拟合的措施,需要与 ‘resampling_strategy_arguments’(超参数:重采样策略参数)组合使用,如下:
‘holdout’: 67:33 (train:test) 划分
‘holdout-iterative-fit’: 67:33 (train:test) 划分, calls iterative fit where possible
cv’: 交叉验证, 需要参数 ‘folds’
‘partial-cv’: crossvalidation with intensification, requires ‘folds’
BaseCrossValidator object: any BaseCrossValidator class found
in scikit-learn model_selection module
_RepeatedSplits object: any _RepeatedSplits class found
in scikit-learn model_selection module
BaseShuffleSplit object: any BaseShuffleSplit class found
in scikit-learn model_selection module
2.14. resampling_strategy_arguments: dict, optional if ‘holdout’ (train_size default=0.67)
重采样策略参数。需要根据 resampling_strategy 参数的选择添加字典参数(也就是对前一个参数设置的参数)
train_size训练数据集划分的比例,应该在浮点数0-1之间。shuffle确定数据样本在划分成训练集与验证集之前是否随机打乱。
可用参数设置样例如下:
‘holdout’: {‘train_size’: float}
‘holdout-iterative-fit’: {‘train_size’: float}
‘cv’: {‘folds’: int}
‘partial-cv’: {‘folds’: int, ‘shuffle’: bool}
BaseCrossValidator or _RepeatedSplits or BaseShuffleSplit object: all arguments
required by chosen class as specified in scikit-learn documentation. If arguments are not provided, scikit-learn defaults are used. If no defaults are available, an exception is raised. Refer to the ‘n_splits’ argument as ‘folds’.
强调说明:如果使用这两个参数的话,在 fit 完毕,选择出最佳模型之后,还需要 refit 一次,这样原来的模型才能根据新的数据进行调整,然后才能进行预测,直接使用 refit 命令无法进行预测,而只是用fit命令,不使用 refit 命令也会报下面的错
2.15. tmp_folder: string, optional (None)
用于存储配置输出和日志文件的文件夹,如果为 None 自动使用 /tmp/autosklearn_tmp_$pid_$random_number。可以定义文件存放路径,为防止删除需要设置 delete_tmp_folder_after_terminate 参数为 False。
2.16. output_folder: string, optional (None)
用于存储可选测试集预测的文件夹,如果为 None 自动使用 /tmp/autosklearn_output_$pid_$random_number。可以定义文件存放路径,为防止删除需要设置 delete_output_folder_after_terminate 参数为 False。
2.17. delete_tmp_folder_after_terminate: string, optional (True)
完成后删除 tmp_folder。 如果 tmp_folder 为 None,则将始终删除 tmp_dir,如果需要保留文件夹数据则设置为 False。
2.18. delete_output_folder_after_terminate: bool, optional (True)
完成后删除 output_folder。 如果 output_folder 为 None,则将始终删除 output_dir,如果需要保留文件夹数据则设置为 False。
2.19. shared_mode: bool, optional (False)
默认为 False,设置为 True 后在共享模型节点中运行 SMAC,即SMAC共享模型。 这仅在给定参数 tmp_folder 和 output_folder 并且 delete_tmp_folder_after_terminate 和 delete_output_folder_after_terminate 都设置为 False 时有效。 不能与 n_jobs 一起使用。
2.20. n_jobs: int, optional, experimental
fit() 并行运行的作业数。 不能与 shared_mode 一起使用。-1 表示使用所有处理器(最好不要使用 -1 参数,容易报超列表长度错误)。 默认情况下,auto-sklearn 使用单个核心来拟合机器学习模型,使用单个核心来拟合整体。 集成模型不受 n_jobs 的影响,但可以通过整体中的模型数量来控制。 与大多数 scikit-learn 模型相比,构造函数中给出的 n_jobs 不适用于 predict() 方法。
3. fit 说明
1 | fit(self, X, y, X_test=None, y_test=None, metric=None, feat_type=None, dataset_name=None) |
通过 auto-sklearn 拟合给定的训练集(X,y)。与 sklearn 的接口使用极其的相似,但是内部实现不同的是,auto-sklearn 训练的是一堆机器学习模型,包括了数据预处理算法。
3.1. X: array-like or sparse matrix of shape = [n_samples, n_features]
输入的训练样本。
3.2. y: array-like, shape = [n_samples]
回归目标值(分类则是分类目标值)。
3.3. X_test: array-like or sparse matrix of shape = [n_samples, n_features]
输入的测试数据样本。这将用于保存所有模型的测试预测结果,这些结果将用来评估 auto-sklearn 随时间变化其性能的变化。
3.4. y_test: array-like, shape = [n_samples]
回归目标值。这将用于计算所有模型在测试集上的预测误差。这些结果将用来评估 auto-sklearn 随时间变化其性能的变化。
3.5. metric: callable, optional (default=’autosklearn.metrics.r2’)
通过 autosklearn.metrics.make_scorer() 方法创建的 autosklearn.metrics.Scorer 实例。也就是优化函数,回归默认为 R2。参数相关选项即说明如下:
3.5.1 分类指标:
默认的 autosklearn.metrics.f1,autosklearn.metrics.precision 和 autosklearn.metrics.recall 内置指标仅适用于二进制分类。为了将它们应用于多标签和多类分类,请使用相应的度量标准和适当的平均机制,例如autosklearn.metrics.f1_macro。有关如何使用这些指标的更多信息,请阅读此scikit-learn文档。
autosklearn.metrics.accuracyautosklearn.metrics.balanced_accuracyautosklearn.metrics.f1autosklearn.metrics.f1_macroautosklearn.metrics.f1_microautosklearn.metrics.f1_samplesautosklearn.metrics.f1_weightedautosklearn.metrics.roc_aucautosklearn.metrics.precisionautosklearn.metrics.precision_macroautosklearn.metrics.precision_microautosklearn.metrics.precision_samplesautosklearn.metrics.precision_weightedautosklearn.metrics.average_precisionautosklearn.metrics.recallautosklearn.metrics.recall_macroautosklearn.metrics.recall_microautosklearn.metrics.recall_samplesautosklearn.metrics.recall_weightedautosklearn.metrics.log_lossautosklearn.metrics.pac_score
3.5.2 回归指标:
autosklearn.metrics.r2autosklearn.metrics.mean_squared_errorautosklearn.metrics.mean_absolute_errorautosklearn.metrics.median_absolute_error
4. refit 说明
根据新数据重新调整找到的所有模型。
说明:使用 Auto-Sklearn 的分类或回归函数中的
resampling_strategy和resampling_strategy_arguments这两个参数定义交叉验证时,必须要使用 refit 函数。在训练期间,auto-sklearn 会在数据集上为每个模型拟合 k 次,但不保留任何经过训练的模型,因此不能用于预测新的数据点。This methods fits all models found during a call to fit on the data given。该方法还可以与重采样策略
holdout一起使用,以避免仅使用 66% 的训练数据来拟合最终模型。
4.1. Parameters
X: array-like or sparse matrix of shape = [n_samples, n_features]
输入的训练样本。
y: array-like, shape = [n_samples] or [n_samples, n_outputs]
训练样本目标值。
4.2. Return
self。
5. get_models_with_weights(self) 说明
返回 auto-sklearn 找到的最终集成模型的列表。
Returns: [(weight_1,model_1),…,(weight_n,model_n)]
6. get_params(self, deep=True) 说明
得到估计模型的参数。
6.1. Parameters: deep: boolean, optional
如果为True,将返回此估计器的参数并包含作为估算器的子对象。
6.2. Return: params: mapping of string to any
参数名字映射到它们的值
7. predict(self, X, batch_size=None, n_jobs=1) 说明
对 X 数据样本进行预测,得到其目标值。
7.1. Parameters: X: array-like or sparse matrix of shape = [n_samples, n_features]
7.2. Returns: y: array of shape = [n_samples] or [n_samples, n_outputs]
返回预测结果。
8. show_models(self)
返回通过 auto-sklearn 找到的最终集成模型。
9. 结语
后续如果有相关内容将进行补充和说明。。。