|
- import SubAreaTitle from '@/components/SubAreaTitle';
- import {
- AutoMLEnsembleClass,
- AutoMLResamplingStrategy,
- AutoMLTaskType,
- autoMLEnsembleClassOptions,
- autoMLResamplingStrategyOptions,
- autoMLTaskTypeOptions,
- } from '@/enums';
- import { Col, Form, InputNumber, Radio, Row, Select, Switch } from 'antd';
-
- // 分类算法
- const classificationAlgorithms = [
- 'adaboost',
- 'bernoulli_nb',
- 'decision_tree',
- 'extra_trees',
- 'gaussian_nb',
- 'gradient_boosting',
- 'k_nearest_neighbors',
- 'lda',
- 'liblinear_svc',
- 'libsvm_svc',
- 'mlp',
- 'multinomial_nb',
- 'passive_aggressive',
- 'qda',
- 'random_forest',
- 'sgd',
- ].map((name) => ({ label: name, value: name }));
-
- // 回归算法
- const regressorAlgorithms = [
- 'adaboost',
- 'ard_regression',
- 'decision_tree',
- 'extra_trees',
- 'gaussian_process',
- 'gradient_boosting',
- 'k_nearest_neighbors',
- 'liblinear_svr',
- 'libsvm_svr',
- 'mlp',
- 'random_forest',
- 'sgd',
- ].map((name) => ({ label: name, value: name }));
-
- // 特征预处理算法
- const featureAlgorithms = [
- '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_classification',
- 'select_percentile_regression',
- 'select_rates_classification',
- 'select_rates_regression',
- 'truncatedSVD',
- ].map((name) => ({ label: name, value: name }));
-
- // 分类指标
- export const classificationMetrics = [
- 'accuracy',
- 'balanced_accuracy',
- 'roc_auc',
- 'average_precision',
- 'log_loss',
- 'precision_macro',
- 'precision_micro',
- 'precision_samples',
- 'precision_weighted',
- 'recall_macro',
- 'recall_micro',
- 'recall_samples',
- 'recall_weighted',
- 'f1_macro',
- 'f1_micro',
- 'f1_samples',
- 'f1_weighted',
- ].map((name) => ({ label: name, value: name }));
-
- // 回归指标
- export const regressionMetrics = [
- 'mean_absolute_error',
- 'mean_squared_error',
- 'root_mean_squared_error',
- 'mean_squared_log_error',
- 'median_absolute_error',
- 'r2',
- ].map((name) => ({ label: name, value: name }));
-
- function ExecuteConfig() {
- const form = Form.useFormInstance();
- const task_type = Form.useWatch('task_type', form);
- const include_classifier = Form.useWatch('include_classifier', form);
- const exclude_classifier = Form.useWatch('exclude_classifier', form);
- const include_regressor = Form.useWatch('include_regressor', form);
- const exclude_regressor = Form.useWatch('exclude_regressor', form);
- const include_feature_preprocessor = Form.useWatch('include_feature_preprocessor', form);
- const exclude_feature_preprocessor = Form.useWatch('exclude_feature_preprocessor', form);
-
- return (
- <>
- <SubAreaTitle
- title="执行配置"
- image={require('@/assets/img/model-deployment.png')}
- style={{ marginTop: '20px', marginBottom: '24px' }}
- ></SubAreaTitle>
- <Row gutter={8}>
- <Col span={10}>
- <Form.Item
- label="任务类型"
- name="task_type"
- rules={[{ required: true, message: '请选择任务类型' }]}
- >
- <Radio.Group
- options={autoMLTaskTypeOptions}
- onChange={() => form.resetFields(['metrics'])}
- ></Radio.Group>
- </Form.Item>
- </Col>
- </Row>
-
- <Row gutter={8}>
- <Col span={10}>
- <Form.Item
- label="特征预处理算法"
- name="include_feature_preprocessor"
- tooltip="如果不选,则使用所有可能的特征预处理算法。否则,将只使用包含的特征预处理算法"
- >
- <Select
- allowClear
- placeholder="请选择特征预处理算法"
- options={featureAlgorithms}
- disabled={exclude_feature_preprocessor?.length > 0}
- mode="multiple"
- showSearch
- />
- </Form.Item>
- </Col>
- </Row>
-
- <Row gutter={8}>
- <Col span={10}>
- <Form.Item
- label="排除特征预处理算法"
- name="exclude_feature_preprocessor"
- tooltip="如果不选,则使用所有可能的特征预处理算法。否则,将排除包含的特征预处理算法"
- >
- <Select
- allowClear
- placeholder="排除特征预处理算法"
- options={featureAlgorithms}
- disabled={include_feature_preprocessor?.length > 0}
- mode="multiple"
- showSearch
- />
- </Form.Item>
- </Col>
- </Row>
-
- <Form.Item dependencies={['task_type']} noStyle>
- {({ getFieldValue }) => {
- return getFieldValue('task_type') === AutoMLTaskType.Classification ? (
- <>
- <Row gutter={8}>
- <Col span={10}>
- <Form.Item
- label="分类算法"
- name="include_classifier"
- tooltip="如果不选,则使用所有可能的分类算法。否则,将只使用包含的算法"
- >
- <Select
- allowClear
- placeholder="请选择分类算法"
- options={classificationAlgorithms}
- mode="multiple"
- disabled={exclude_classifier?.length > 0}
- showSearch
- />
- </Form.Item>
- </Col>
- </Row>
-
- <Row gutter={8}>
- <Col span={10}>
- <Form.Item
- label="排除分类算法"
- name="exclude_classifier"
- tooltip="如果不选,则使用所有可能的分类算法。否则,将排除包含的算法"
- >
- <Select
- allowClear
- placeholder="排除分类算法"
- options={classificationAlgorithms}
- mode="multiple"
- disabled={include_classifier?.length > 0}
- showSearch
- />
- </Form.Item>
- </Col>
- </Row>
- </>
- ) : (
- <>
- <Row gutter={8}>
- <Col span={10}>
- <Form.Item
- label="回归算法"
- name="include_regressor"
- tooltip="如果不选,则使用所有可能的回归算法。否则,将只使用包含的算法"
- >
- <Select
- allowClear
- placeholder="请选择回归算法"
- options={regressorAlgorithms}
- mode="multiple"
- disabled={exclude_regressor?.length > 0}
- showSearch
- />
- </Form.Item>
- </Col>
- </Row>
-
- <Row gutter={8}>
- <Col span={10}>
- <Form.Item
- label="排除的回归算法"
- name="exclude_regressor"
- tooltip="如果不选,则使用所有可能的回归算法。否则,将排除包含的算法"
- >
- <Select
- allowClear
- placeholder="排除回归算法"
- options={regressorAlgorithms}
- mode="multiple"
- disabled={include_regressor?.length > 0}
- showSearch
- />
- </Form.Item>
- </Col>
- </Row>
- </>
- );
- }}
- </Form.Item>
-
- <Row gutter={8}>
- <Col span={10}>
- <Form.Item
- label="集成方式"
- name="ensemble_class"
- tooltip="仅使用单个最佳模型还是集成模型"
- >
- <Radio.Group options={autoMLEnsembleClassOptions}></Radio.Group>
- </Form.Item>
- </Col>
- </Row>
-
- <Form.Item dependencies={['ensemble_class']} noStyle>
- {({ getFieldValue }) => {
- return getFieldValue('ensemble_class') === AutoMLEnsembleClass.Default ? (
- <>
- <Row gutter={8}>
- <Col span={10}>
- <Form.Item
- label="集成模型数量"
- name="ensemble_size"
- tooltip="集成模型数量,如果设置为0,则没有集成。默认50"
- >
- <InputNumber placeholder="请输入集成模型数量" min={0} precision={0} />
- </Form.Item>
- </Col>
- </Row>
-
- <Row gutter={8}>
- <Col span={10}>
- <Form.Item
- label="集成最佳模型数量"
- name="ensemble_nbest"
- tooltip="仅集成最佳的N个模型"
- >
- <InputNumber placeholder="请输入集成最佳模型数量" min={0} precision={0} />
- </Form.Item>
- </Col>
- </Row>
- </>
- ) : null;
- }}
- </Form.Item>
-
- <Row gutter={8}>
- <Col span={10}>
- <Form.Item
- label="最大数量"
- name="max_models_on_disc"
- tooltip="定义在磁盘中保存的模型的最大数量。额外的模型数量将被永久删除,它设置了一个集成可以使用多少个模型的上限。必须是大于等于1的整数,默认50"
- >
- <InputNumber placeholder="请输入最大数量" min={0} precision={0} />
- </Form.Item>
- </Col>
- </Row>
-
- <Row gutter={8}>
- <Col span={10}>
- <Form.Item
- label="内存限制(MB)"
- name="memory_limit"
- tooltip="机器学习算法的内存限制(MB)。如果自动机器学习试图分配超过memory_limit MB,它将停止拟合机器学习算法。默认3072"
- >
- <InputNumber placeholder="请输入内存限制" min={0} precision={0} />
- </Form.Item>
- </Col>
- </Row>
-
- <Row gutter={8}>
- <Col span={10}>
- <Form.Item
- label="单次时间限制(秒)"
- name="per_run_time_limit"
- tooltip="单次调用机器学习模型的时间限制(以秒为单位)。如果机器学习算法运行超过时间限制,将终止模型拟合,默认600"
- >
- <InputNumber placeholder="请输入时间限制" min={0} precision={0} />
- </Form.Item>
- </Col>
- </Row>
-
- <Row gutter={8}>
- <Col span={10}>
- <Form.Item
- label="搜索时间限制(秒)"
- name="time_left_for_this_task"
- tooltip="搜索合适模型的时间限制(以秒为单位)。通过增加这个值,自动机器学习有更高的机会找到更好的模型。默认3600。"
- >
- <InputNumber placeholder="请输入搜索时间限制" min={0} precision={0} />
- </Form.Item>
- </Col>
- </Row>
-
- <Row gutter={8}>
- <Col span={10}>
- <Form.Item
- label="测试集比率"
- name="test_size"
- tooltip="将数据划分为训练数据和测试数据,测试数据集所占比例,0到1之间"
- >
- <InputNumber placeholder="请输入测试集比率" min={0} max={1} />
- </Form.Item>
- </Col>
- </Row>
-
- <Row gutter={8}>
- <Col span={10}>
- <Form.Item label="计算指标" name="scoring_functions" tooltip="需要计算并打印的指标">
- <Select
- allowClear
- placeholder="请选择计算指标"
- options={
- task_type === AutoMLTaskType.Classification
- ? classificationMetrics
- : regressionMetrics
- }
- showSearch
- />
- </Form.Item>
- </Col>
- </Row>
-
- <Row gutter={8}>
- <Col span={10}>
- <Form.Item label="随机种子" name="seed" tooltip="随机种子,将决定输出文件名">
- <InputNumber placeholder="请输入随机种子" min={0} precision={0} />
- </Form.Item>
- </Col>
- </Row>
-
- <SubAreaTitle
- title="重采样策略"
- image={require('@/assets/img/resample-icon.png')}
- style={{ marginTop: '20px', marginBottom: '24px' }}
- ></SubAreaTitle>
-
- <Row gutter={8}>
- <Col span={10}>
- <Form.Item
- label="重采样策略"
- name="resampling_strategy"
- tooltip="重采样策略,分为holdout和crossValid。holdout指定训练数据划分为训练集和验证集的比例。crossValid为交叉验证。"
- >
- <Select
- allowClear
- placeholder="请选择重采样策略"
- options={autoMLResamplingStrategyOptions}
- showSearch
- />
- </Form.Item>
- </Col>
- </Row>
-
- <Form.Item dependencies={['resampling_strategy']} noStyle>
- {({ getFieldValue }) => {
- return getFieldValue('resampling_strategy') === AutoMLResamplingStrategy.CrossValid ? (
- <Row gutter={8}>
- <Col span={10}>
- <Form.Item
- label="交叉验证折数"
- name="folds"
- rules={[
- {
- required: true,
- message: '请输入交叉验证折数',
- },
- ]}
- >
- <InputNumber placeholder="请输入交叉验证折数" min={0} precision={0} />
- </Form.Item>
- </Col>
- </Row>
- ) : null;
- }}
- </Form.Item>
-
- <Row gutter={8}>
- <Col span={10}>
- <Form.Item label="是否打乱" name="shuffle" tooltip="拆分数据前是否打乱顺序">
- <Switch />
- </Form.Item>
- </Col>
- </Row>
-
- <Row gutter={8}>
- <Col span={10}>
- <Form.Item
- label="训练集比率"
- name="train_size"
- tooltip="重采样划分训练集和验证集,训练集的比率,0到1之间"
- >
- <InputNumber placeholder="请输入训练集比率" min={0} max={1} />
- </Form.Item>
- </Col>
- </Row>
-
- {/* <Row gutter={8}>
- <Col span={10}>
- <Form.Item
- label="文件夹路径"
- name="tmp_folder"
- tooltip="存放配置输出和日志文件的文件夹"
- rules={[
- {
- pattern: /^\/[a-zA-Z0-9._/-]+$/,
- message:
- '请输入正确的文件夹路径,以 / 开头,只支持字母、数字、点、下划线、中横线、斜杠',
- },
- ]}
- >
- <Input placeholder="请输入文件夹路径" maxLength={64} showCount allowClear />
- </Form.Item>
- </Col>
- </Row> */}
-
- {/* <Form.List name="hyper-parameter">
- {(fields, { add, remove }) => (
- <>
- <Row gutter={8}>
- <Col span={10}>
- <Form.Item
- label="超参数"
- style={{ marginBottom: 0, marginTop: '-14px' }}
- tooltip="超参数"
- ></Form.Item>
- </Col>
- </Row>
- <div className={styles['hyper-parameter']}>
- <Flex align="center" className={styles['hyper-parameter__header']}>
- <div className={styles['hyper-parameter__header__name']}>参数名称</div>
- <div className={styles['hyper-parameter__header__type']}>约束类型</div>
- <div className={styles['hyper-parameter__header__space']}>搜索空间</div>
- <div className={styles['hyper-parameter__header__operation']}>操作</div>
- </Flex>
-
- {fields.map(({ key, name, ...restField }, index) => (
- <Flex key={key} align="center" className={styles['hyper-parameter__body']}>
- <Form.Item
- className={styles['hyper-parameter__body__name']}
- {...restField}
- name={[name, 'name']}
- rules={[{ required: true, message: 'Missing first name' }]}
- >
- <Input placeholder="Key" />
- </Form.Item>
- <Form.Item
- className={styles['hyper-parameter__body__name']}
- {...restField}
- name={[name, 'type']}
- rules={[{ required: true, message: 'Missing last name' }]}
- >
- <Input placeholder="Value" />
- </Form.Item>
- <Form.Item
- className={styles['hyper-parameter__body__name']}
- {...restField}
- name={[name, 'space']}
- rules={[{ required: true, message: 'Missing last name' }]}
- >
- <Input placeholder="Value" />
- </Form.Item>
- <div className={styles['hyper-parameter__body__operation']}>
- <Button
- style={{
- marginRight: '3px',
- }}
- shape="circle"
- disabled={fields.length === 1}
- type="text"
- size="middle"
- onClick={() => remove(name)}
- icon={<MinusCircleOutlined />}
- ></Button>
- {index === fields.length - 1 && (
- <Button
- shape="circle"
- size="middle"
- type="text"
- onClick={() => add()}
- icon={<PlusCircleOutlined />}
- ></Button>
- )}
- </div>
- </Flex>
- ))}
- {fields.length === 0 && (
- <div className={styles['hyper-parameter__add']}>
- <Button type="link" onClick={() => add()} icon={<KFIcon type="icon-xinjian2" />}>
- 添加一行
- </Button>
- </div>
- )}
- </div>
- </>
- )}
- </Form.List> */}
- </>
- );
- }
-
- export default ExecuteConfig;
|