You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 8.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. import ConfigInfo, { type BasicInfoData } from '@/components/ConfigInfo';
  2. import {
  3. AutoMLTaskType,
  4. AutoMLType,
  5. ExperimentStatus,
  6. autoMLEnsembleClassOptions,
  7. autoMLTaskTypeOptions,
  8. } from '@/enums';
  9. import { useComputingResource } from '@/hooks/useComputingResource';
  10. import {
  11. classificationAlgorithms,
  12. featureAlgorithms,
  13. regressorAlgorithms,
  14. } from '@/pages/AutoML/components/CreateForm/utils';
  15. import { AutoMLData } from '@/pages/AutoML/types';
  16. import { type NodeStatus } from '@/types';
  17. import { parseJsonText } from '@/utils';
  18. import {
  19. formatBoolean,
  20. formatDataset,
  21. formatDate,
  22. formatEnum,
  23. type EnumOptions,
  24. } from '@/utils/format';
  25. import classNames from 'classnames';
  26. import { useMemo } from 'react';
  27. import ExperimentRunBasic from '../ExperimentRunBasic';
  28. import styles from './index.less';
  29. // 格式化优化方向
  30. const formatOptimizeMode = (value: boolean) => {
  31. return value ? '越大越好' : '越小越好';
  32. };
  33. // 格式化权重
  34. const formatMetricsWeight = (value: string) => {
  35. if (!value) {
  36. return '--';
  37. }
  38. const json = parseJsonText(value);
  39. if (!json) {
  40. return '--';
  41. }
  42. return Object.entries(json)
  43. .map(([key, value]) => `${key}:${value}`)
  44. .join('\n');
  45. };
  46. // 格式化算法
  47. const formatAlgorithm = (algorithms: EnumOptions[]) => {
  48. return (value: string) => {
  49. if (!value) {
  50. return '--';
  51. }
  52. const list = value
  53. .split(',')
  54. .filter((v) => v !== '')
  55. .map((v) => v.trim());
  56. return list.map((v) => formatEnum(algorithms)(v)).join(',');
  57. };
  58. };
  59. type AutoMLBasicProps = {
  60. info?: AutoMLData;
  61. className?: string;
  62. isInstance?: boolean;
  63. workflowStatus?: NodeStatus;
  64. instanceStatus?: ExperimentStatus;
  65. instanceCreateTime?: string;
  66. };
  67. function AutoMLBasic({
  68. info,
  69. className,
  70. workflowStatus,
  71. instanceStatus,
  72. isInstance = false,
  73. }: AutoMLBasicProps) {
  74. const getResourceDescription = useComputingResource()[1];
  75. const basicDatas: BasicInfoData[] = useMemo(() => {
  76. if (!info) {
  77. return [];
  78. }
  79. return [
  80. {
  81. label: '实验名称',
  82. value: info.name,
  83. },
  84. {
  85. label: '实验描述',
  86. value: info.description,
  87. },
  88. {
  89. label: '创建人',
  90. value: info.create_by,
  91. },
  92. {
  93. label: '创建时间',
  94. value: info.create_time,
  95. format: formatDate,
  96. },
  97. {
  98. label: '更新时间',
  99. value: info.update_time,
  100. format: formatDate,
  101. },
  102. ];
  103. }, [info]);
  104. const configDatas: BasicInfoData[] = useMemo(() => {
  105. if (!info) {
  106. return [];
  107. }
  108. if (info.type === AutoMLType.Table) {
  109. return [
  110. {
  111. label: '任务类型',
  112. value: info.task_type,
  113. format: formatEnum(autoMLTaskTypeOptions),
  114. },
  115. {
  116. label: '特征预处理算法',
  117. value: info.include_feature_preprocessor,
  118. format: formatAlgorithm(featureAlgorithms),
  119. },
  120. {
  121. label: '排除的特征预处理算法',
  122. value: info.exclude_feature_preprocessor,
  123. format: formatAlgorithm(featureAlgorithms),
  124. },
  125. {
  126. label: info.task_type === AutoMLTaskType.Regression ? '回归算法' : '分类算法',
  127. value:
  128. info.task_type === AutoMLTaskType.Regression
  129. ? info.include_regressor
  130. : info.include_classifier,
  131. format: formatAlgorithm(
  132. info.task_type === AutoMLTaskType.Regression
  133. ? regressorAlgorithms
  134. : classificationAlgorithms,
  135. ),
  136. },
  137. {
  138. label: info.task_type === AutoMLTaskType.Regression ? '排除的回归算法' : '排除的分类算法',
  139. value:
  140. info.task_type === AutoMLTaskType.Regression
  141. ? info.exclude_regressor
  142. : info.exclude_classifier,
  143. format: formatAlgorithm(
  144. info.task_type === AutoMLTaskType.Regression
  145. ? regressorAlgorithms
  146. : classificationAlgorithms,
  147. ),
  148. },
  149. {
  150. label: '集成方式',
  151. value: info.ensemble_class,
  152. format: formatEnum(autoMLEnsembleClassOptions),
  153. },
  154. {
  155. label: '集成模型数量',
  156. value: info.ensemble_size,
  157. },
  158. {
  159. label: '集成最佳模型数量',
  160. value: info.ensemble_nbest,
  161. },
  162. {
  163. label: '最大数量',
  164. value: info.max_models_on_disc,
  165. },
  166. {
  167. label: '内存限制(MB)',
  168. value: info.memory_limit,
  169. },
  170. {
  171. label: '单次时间限制(秒)',
  172. value: info.per_run_time_limit,
  173. },
  174. {
  175. label: '搜索时间限制(秒)',
  176. value: info.time_left_for_this_task,
  177. },
  178. {
  179. label: '重采样策略',
  180. value: info.resampling_strategy,
  181. },
  182. {
  183. label: '交叉验证折数',
  184. value: info.folds,
  185. },
  186. {
  187. label: '是否打乱',
  188. value: info.shuffle,
  189. format: formatBoolean,
  190. },
  191. {
  192. label: '训练集比率',
  193. value: info.train_size,
  194. },
  195. {
  196. label: '测试集比率',
  197. value: info.test_size,
  198. },
  199. {
  200. label: '计算指标',
  201. value: info.scoring_functions,
  202. },
  203. {
  204. label: '随机种子',
  205. value: info.seed,
  206. },
  207. {
  208. label: '数据集',
  209. value: info.dataset,
  210. format: formatDataset,
  211. },
  212. {
  213. label: '预测目标列',
  214. value: info.target_columns,
  215. },
  216. ];
  217. } else if (info.type === AutoMLType.Text) {
  218. return [
  219. {
  220. label: '模型',
  221. value: info.model_type,
  222. },
  223. {
  224. label: '数据集',
  225. value: info.dataset,
  226. format: formatDataset,
  227. },
  228. {
  229. label: '资源规格',
  230. value: info.computing_resource_id,
  231. format: getResourceDescription,
  232. },
  233. {
  234. label: 'batch_size',
  235. value: info.batch_size,
  236. },
  237. {
  238. label: 'epochs',
  239. value: info.epochs,
  240. },
  241. {
  242. label: '学习率',
  243. value: info.lr,
  244. },
  245. ];
  246. } else {
  247. return [
  248. {
  249. label: '数据集',
  250. value: info.dataset,
  251. format: formatDataset,
  252. },
  253. {
  254. label: '资源规格',
  255. value: info.computing_resource_id,
  256. format: getResourceDescription,
  257. },
  258. {
  259. label: '类别数量',
  260. value: info.num_classes,
  261. },
  262. {
  263. label: 'batch_size',
  264. value: info.batch_size,
  265. },
  266. {
  267. label: 'epochs',
  268. value: info.epochs,
  269. },
  270. {
  271. label: '学习率',
  272. value: info.lr,
  273. },
  274. {
  275. label: '是否验证',
  276. value: info.is_validate,
  277. format: formatBoolean,
  278. },
  279. {
  280. label: '训练集路径',
  281. value: info.train_data_prefix,
  282. },
  283. {
  284. label: '训练集标注文件',
  285. value: info.train_file_path,
  286. },
  287. ...(info.is_validate
  288. ? [
  289. {
  290. label: '验证集路径',
  291. value: info.valid_data_prefix,
  292. },
  293. {
  294. label: '验证集标注文件',
  295. value: info.valid_file_path,
  296. },
  297. ]
  298. : []),
  299. ];
  300. }
  301. }, [info, getResourceDescription]);
  302. const metricsData = useMemo(() => {
  303. if (!info) {
  304. return [];
  305. }
  306. return [
  307. {
  308. label: '指标名称',
  309. value: info.metric_name,
  310. },
  311. {
  312. label: '优化方向',
  313. value: info.greater_is_better,
  314. format: formatOptimizeMode,
  315. },
  316. {
  317. label: '指标权重',
  318. value: info.metrics,
  319. format: formatMetricsWeight,
  320. },
  321. ];
  322. }, [info]);
  323. return (
  324. <div className={classNames(styles['auto-ml-basic'], className)}>
  325. {isInstance && workflowStatus && (
  326. <ExperimentRunBasic workflowStatus={workflowStatus} instanceStatus={instanceStatus} />
  327. )}
  328. {!isInstance && (
  329. <ConfigInfo
  330. title="基本信息"
  331. datas={basicDatas}
  332. labelWidth={70}
  333. style={{ marginBottom: '20px' }}
  334. />
  335. )}
  336. <ConfigInfo
  337. title="配置信息"
  338. datas={configDatas}
  339. labelWidth={150}
  340. style={{ marginBottom: '20px' }}
  341. />
  342. {info?.type === AutoMLType.Table && (
  343. <ConfigInfo title="优化指标" datas={metricsData} labelWidth={70} />
  344. )}
  345. </div>
  346. );
  347. }
  348. export default AutoMLBasic;