Soil Acidification Iterative Evolution.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. import * as echarts from '../../components/ec-canvas/echarts';
  2. Page({
  3. data: {
  4. ecBox: {
  5. onInit: function (canvas, width, height, dpr) {
  6. const boxChart = echarts.init(canvas, null, {
  7. width: width,
  8. height: height,
  9. devicePixelRatio: dpr // new
  10. });
  11. canvas.setChart(boxChart);
  12. boxChart.setOption(getBoxOption());
  13. return boxChart;
  14. }
  15. },
  16. ecLine: {
  17. onInit: function (canvas, width, height, dpr) {
  18. const lineChart = echarts.init(canvas, null, {
  19. width: width,
  20. height: height,
  21. devicePixelRatio: dpr // new
  22. });
  23. canvas.setChart(lineChart);
  24. lineChart.setOption(getLineOption());
  25. return lineChart;
  26. }
  27. },
  28. ecScatter: {
  29. onInit: function (canvas, width, height, dpr) {
  30. const scatterChart = echarts.init(canvas, null, {
  31. width: width,
  32. height: height,
  33. devicePixelRatio: dpr // new
  34. });
  35. canvas.setChart(scatterChart);
  36. scatterChart.setOption(getScatterOption());
  37. return scatterChart;
  38. }
  39. },
  40. ecBar: {
  41. onInit: function (canvas, width, height, dpr) {
  42. const barChart = echarts.init(canvas, null, {
  43. width: width,
  44. height: height,
  45. devicePixelRatio: dpr
  46. });
  47. canvas.setChart(barChart);
  48. barChart.setOption(getBarOption());
  49. return barChart;
  50. }
  51. },
  52. ecPie: {
  53. onInit: function (canvas, width, height, dpr) {
  54. const pieChart = echarts.init(canvas, null, {
  55. width: width,
  56. height: height,
  57. devicePixelRatio: dpr // new
  58. });
  59. canvas.setChart(pieChart);
  60. pieChart.setOption(getPieOption());
  61. return pieChart;
  62. }
  63. }
  64. },
  65. onReady() {
  66. // You can add any additional logic here if needed
  67. }
  68. });
  69. function getBarOption() {
  70. return {
  71. title: {
  72. text: 'Basic Bar Chart'
  73. },
  74. tooltip: {
  75. trigger: 'axis',
  76. axisPointer: {
  77. type: 'shadow'
  78. }
  79. },
  80. legend: {
  81. data: ['Sales']
  82. },
  83. grid: {
  84. left: '3%',
  85. right: '4%',
  86. bottom: '3%',
  87. containLabel: true
  88. },
  89. xAxis: {
  90. type: 'category',
  91. data: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul']
  92. },
  93. yAxis: {
  94. type: 'value'
  95. },
  96. series: [
  97. {
  98. name: 'Sales',
  99. type: 'bar',
  100. data: [5, 20, 36, 10, 10, 20, 30],
  101. itemStyle: {
  102. color: '#c23531'
  103. }
  104. }
  105. ]
  106. }
  107. }
  108. function getBoxOption() {
  109. return {
  110. title: {
  111. text: 'Sample ΔpH'
  112. },
  113. tooltip: {
  114. trigger: 'item',
  115. axisPointer: {
  116. type: 'shadow'
  117. }
  118. },
  119. grid: {
  120. left: '3%',
  121. right: '4%',
  122. bottom: '3%',
  123. containLabel: true
  124. },
  125. xAxis: {
  126. type: 'category',
  127. data: Array.from({length: 27}, (_, i) => i + 1) // 生成 1 到 27 的样本编号
  128. },
  129. yAxis: {
  130. type: 'value',
  131. name: 'ΔpH',
  132. min: -1.5,
  133. max: 0.5
  134. },
  135. series: [
  136. {
  137. name: 'ΔpH',
  138. type: 'boxplot',
  139. data: [
  140. // 每个数组代表一个样本的箱型图数据
  141. // 格式为 [min, Q1, median, Q3, max],可以包含异常值作为单独的数组元素
  142. [-0.8, -0.6, -0.5, -0.3, 0.0],
  143. [-0.7, -0.5, -0.4, -0.2, 0.1],
  144. [-0.9, -0.7, -0.6, -0.4, -0.1],
  145. [-1.0, -0.8, -0.7, -0.5, -0.3],
  146. [-1.1, -0.9, -0.8, -0.6, -0.4],
  147. [-1.2, -1.0, -0.9, -0.7, -0.5],
  148. [-1.3, -1.1, -1.0, -0.8, -0.6],
  149. [-1.4, -1.2, -1.1, -0.9, -0.7],
  150. [-1.5, -1.3, -1.2, -1.0, -0.8],
  151. [-1.4, -1.2, -1.1, -0.9, -0.7],
  152. [-1.3, -1.1, -1.0, -0.8, -0.6],
  153. [-1.2, -1.0, -0.9, -0.7, -0.5],
  154. [-1.1, -0.9, -0.8, -0.6, -0.4],
  155. [-1.0, -0.8, -0.7, -0.5, -0.3],
  156. [-0.9, -0.7, -0.6, -0.4, -0.1],
  157. [-0.8, -0.6, -0.5, -0.3, 0.0],
  158. [-0.7, -0.5, -0.4, -0.2, 0.1],
  159. [-0.6, -0.4, -0.3, -0.1, 0.2],
  160. [-0.5, -0.3, -0.2, 0.0, 0.3],
  161. [-0.4, -0.2, -0.1, 0.1, 0.4],
  162. [-0.3, -0.1, 0.0, 0.2, 0.5],
  163. [-0.2, 0.0, 0.1, 0.3, 0.6],
  164. [-0.1, 0.1, 0.2, 0.4, 0.7],
  165. [0.0, 0.2, -0.3, 0.5, 0.8],
  166. [-0.1, 0.3, -0.4, 0.6, 0.9],
  167. [-0.2, 0.4, -0.5, 0.7, 1.0],
  168. [-0.3, 0.5, -0.6, 0.8, 1.1]
  169. ],
  170. tooltip: {
  171. formatter: function (param) {
  172. return [
  173. 'Experiment ' + param.name + ': ',
  174. 'upper: ' + param.data[5],
  175. 'Q3: ' + param.data[4],
  176. 'median: ' + param.data[3],
  177. 'Q1: ' + param.data[2],
  178. 'lower: ' + param.data[1]
  179. ].join(' ');
  180. }
  181. }
  182. }
  183. ]
  184. };
  185. }
  186. function getScatterOption() {
  187. return {
  188.     tooltip: {
  189.       trigger: 'axis',
  190.       axisPointer: {
  191.         type: 'cross'
  192.       }
  193.     },
  194.     legend: {
  195.       data: ['True vs Predicted']
  196.     },
  197.     grid: {
  198.       left: '3%',
  199.       right: '4%',
  200.       bottom: '3%',
  201.       containLabel: true
  202.     },
  203.     xAxis: {
  204.       name: 'True Values',  // 对应 Python 中的 Ytest
  205.       type: 'value',
  206.       boundaryGap: [0, 0.01]
  207.     },
  208.     yAxis: {
  209.       name: 'Predicted Values',  // 对应 Python 中的 y_pred
  210.       type: 'value',
  211.       boundaryGap: [0, 0.01]
  212.     },
  213.     series: [
  214.       {
  215.         name: 'True vs Predicted',
  216.         type: 'scatter',
  217.         data: [
  218.           [-0.003333333333333854, -0.45726666666666654], [-0.1733333333333329, -0.1726333333333331],
  219.           [-0.6233333333333331, -0.5226666666666667], [-0.7088888888888892, -0.4791888888888889],
  220.           [-0.3366666666666669, -0.3630666666666673], [-0.8888888888888887, -0.48272222222222183],
  221.           [-0.5633333333333326, -0.7492444444444444], [-0.7333333333333325, -0.5572666666666672],
  222.           [-0.3366666666666663, -0.29379999999999984], [-1.176666666666666, -0.8544111111111106],
  223.           [-0.7122222222222225, -0.4959777777777775], [-0.7699999999999996, -0.6149666666666669]
  224.         ],
  225.         symbolSize: 10,
  226.         itemStyle: {
  227.          
  228.         }
  229.       },
  230.       {
  231.         name: 'Trendline',
  232.         type: 'line',
  233.         data: [
  234.           // 绘制对角线 y = x (这就是理想情况下 True 和 Predicted 的值相等)
  235.           [-1.2,-1.2],  // 最小值
  236.           [-0.0034, -0.0034]   // 最大值
  237.         ],
  238.         lineStyle: {
  239.           type: 'dashed',
  240.          
  241.         }
  242.       }
  243.     ]
  244.   };
  245. }
  246. function getLineOption() {
  247. return {
  248. tooltip: {
  249. trigger: 'axis'
  250. },
  251. legend: {
  252. data: ['Random Forest', 'XGBoost', 'Gradient Boosting'] // 模型名称
  253. },
  254. grid: {
  255. left: '3%',
  256. right: '4%',
  257. bottom: '3%',
  258. containLabel: true
  259. },
  260. xAxis: {
  261. type: 'category',
  262. boundaryGap: false,
  263. data: ['10%', '20%', '30%', '40%', '50%', '60%', '70%', '80%', '90%', '100%'] // train_sizes按10%递增
  264. },
  265. yAxis: {
  266. type: 'value'
  267. },
  268. series: [
  269. {
  270. name: 'Random Forest',
  271. type: 'line',
  272. data: [-0.17101591951095463, -0.556719360354051, -0.04083550751401055, -0.20858221504075436, 0.07297292282221035, 0.19857845644421734, 0.28407131176770184, 0.27979356883596496, 0.36904808817286416, 0.4183018571701477] // 使用您的实际R2分数数据
  273. },
  274. {
  275. name: 'XGBoost',
  276. type: 'line',
  277. data: [-1.1811781145886937, -1.5645641005612534, -0.12619079632263497, 0.03324096120721032, 0.06969290639267578, 0.12375262461601955, 0.5331670468884062, 0.49454793164801647, 0.31904329339597803, 0.2712670704381914]
  278. },
  279. {
  280. name: 'Gradient Boosting',
  281. type: 'line',
  282. data: [-0.8583039298789095, -1.073316171952042, 0.09659300885027666, 0.06097833957434784, 0.191975498544109, 0.3718334600546489, 0.3948098332187753, 0.4398778520728397, 0.452609022210963, 0.41484634172723023]
  283. }
  284. ]
  285. };
  286. }
  287. function getPieOption() {
  288. return {
  289. tooltip: {
  290. trigger: 'item',
  291. formatter: '{a} <br/>{b} : {c} ({d}%)'
  292. },
  293. legend: {
  294. orient: 'vertical',
  295. left: 'left',
  296. data: ['示例1', '示例2', '示例3']
  297. },
  298. series: [
  299. {
  300. name: '访问来源',
  301. type: 'pie',
  302. radius: '55%',
  303. center: ['50%', '60%'],
  304. data: [
  305. { value: 335, name: '示例1' },
  306. { value: 310, name: '示例2' },
  307. { value: 234, name: '示例3' },
  308. ],
  309. emphasis: {
  310. itemStyle: {
  311. shadowBlur: 10,
  312. shadowOffsetX: 0,
  313. shadowColor: 'rgba(0, 0, 0, 0.5)'
  314. }
  315. }
  316. }
  317. ]
  318. };
  319. }