Soil Acid Reduction Iterative Evolution.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. import * as echarts from '../../components/ec-canvas/echarts';
  2. Page({
  3. data: {
  4. ecLine: {
  5. onInit: function (canvas, width, height, dpr) {
  6. const lineChart = echarts.init(canvas, null, {
  7. width: width,
  8. height: height,
  9. devicePixelRatio: dpr // new
  10. });
  11. canvas.setChart(lineChart);
  12. lineChart.setOption(getLineOption());
  13. return lineChart;
  14. }
  15. },
  16. ecInitScatter: {
  17. onInit: function (canvas, width, height, dpr) {
  18. const initScatter = echarts.init(canvas, null, {
  19. width: width,
  20. height: height,
  21. devicePixelRatio: dpr // new
  22. });
  23. canvas.setChart(initScatter);
  24. initScatter.setOption(getInitScatterOption());
  25. return initScatter;
  26. }
  27. },
  28. ecMidScatter: {
  29. onInit: function (canvas, width, height, dpr) {
  30. const midScatter = echarts.init(canvas, null, {
  31. width: width,
  32. height: height,
  33. devicePixelRatio: dpr // new
  34. });
  35. canvas.setChart(midScatter);
  36. midScatter.setOption(getMidScatterOption());
  37. return midScatter;
  38. }
  39. },
  40. ecFinalScatter: {
  41. onInit: function (canvas, width, height, dpr) {
  42. const finalScatter = echarts.init(canvas, null, {
  43. width: width,
  44. height: height,
  45. devicePixelRatio: dpr // new
  46. });
  47. canvas.setChart(finalScatter);
  48. finalScatter.setOption(getFinalScatterOption());
  49. return finalScatter;
  50. }
  51. },
  52. },
  53. onReady() {
  54. // You can add any additional logic here if needed
  55. }
  56. });
  57. // 降酸模型 初代 散点图
  58. function getInitScatterOption() {
  59. const calculateDataRange = (data) => {
  60. let xValues = data.map(item => item[0]);
  61. let yValues = data.map(item => item[1]);
  62. return {
  63. xMin: Math.min(...xValues),
  64. xMax: Math.max(...xValues),
  65. yMin: Math.min(...yValues),
  66. yMax: Math.max(...yValues)
  67. };
  68. };
  69. const scatterData = [[0.12931, 0.10315928999999999], [0.066298, 0.10226514000000003], [0.057692, 0.10226514000000003], [0.072464, 0.10339078000000003], [0.146414, 0.10000317000000003], [0.087263, 0.09199080000000004], [0.096983, 0.09947644], [0.070505, 0.10142657000000004], [0.052497, 0.09956722000000007], [0.166515, 0.10179712], [0.063291, 0.10339078000000003]];
  70. const range = calculateDataRange(scatterData);
  71. const padding = 0.1;
  72. const xMin = range.xMin - Math.abs(range.xMin * padding);
  73. const xMax = range.xMax + Math.abs(range.xMax * padding);
  74. const yMin = range.yMin - Math.abs(range.yMin * padding);
  75. const yMax = range.yMax + Math.abs(range.yMax * padding);
  76. const min = Math.min(xMin, yMin)
  77. const max = Math.max(xMax, yMax)
  78. return {
  79. tooltip: {
  80. trigger: 'axis',
  81. axisPointer: {
  82. type: 'cross'
  83. }
  84. },
  85. legend: {
  86. data: ['True vs Predicted']
  87. },
  88. grid: {
  89. left: '4%',
  90. right: '22%',
  91. bottom: '3%',
  92. containLabel: true
  93. },
  94. xAxis: {
  95. name: 'True Values',
  96. type: 'value',
  97. min: min,
  98. max: max
  99. },
  100. yAxis: {
  101. name: 'Predicted Values',
  102. type: 'value',
  103. min: parseFloat(min).toFixed(2),
  104. max: parseFloat(max).toFixed(2)
  105. },
  106. series: [
  107. {
  108. name: 'True vs Predicted',
  109. type: 'scatter',
  110. data: scatterData,
  111. symbolSize: 10,
  112. itemStyle: {
  113. color: '#1f77b4',
  114. opacity: 0.7
  115. }
  116. },
  117. {
  118. name: 'Trendline',
  119. type: 'line',
  120. data: [
  121. [min, min],
  122. [max, max]
  123. ],
  124. lineStyle: {
  125. type: 'dashed',
  126. color: '#ff7f0e',
  127. width: 2
  128. }
  129. }
  130. ]
  131. };
  132. }
  133. // 降酸模型 中间代 散点图
  134. function getMidScatterOption() {
  135. const calculateDataRange = (data) => {
  136. let xValues = data.map(item => item[0]);
  137. let yValues = data.map(item => item[1]);
  138. return {
  139. xMin: Math.min(...xValues),
  140. xMax: Math.max(...xValues),
  141. yMin: Math.min(...yValues),
  142. yMax: Math.max(...yValues)
  143. };
  144. };
  145. const scatterData = [[0.12931, 0.09595878000000002], [0.066298, 0.10344700000000003], [0.057692, 0.10344700000000003], [0.072464, 0.09011803], [0.146414, 0.0853504500000001], [0.087263, 0.07407179000000012], [0.096983, 0.10581049999999995], [0.070505, 0.09876380000000004], [0.052497, 0.08568465000000008], [0.166515, 0.13348440999999997], [0.063291, 0.09011803]];
  146. const range = calculateDataRange(scatterData);
  147. const padding = 0.1;
  148. const xMin = range.xMin - Math.abs(range.xMin * padding);
  149. const xMax = range.xMax + Math.abs(range.xMax * padding);
  150. const yMin = range.yMin - Math.abs(range.yMin * padding);
  151. const yMax = range.yMax + Math.abs(range.yMax * padding);
  152. const min = Math.min(xMin, yMin)
  153. const max = Math.max(xMax, yMax)
  154. return {
  155. tooltip: {
  156. trigger: 'axis',
  157. axisPointer: {
  158. type: 'cross'
  159. }
  160. },
  161. legend: {
  162. data: ['True vs Predicted']
  163. },
  164. grid: {
  165. left: '4%',
  166. right: '22%',
  167. bottom: '3%',
  168. containLabel: true
  169. },
  170. xAxis: {
  171. name: 'True Values',
  172. type: 'value',
  173. min: min,
  174. max: max
  175. },
  176. yAxis: {
  177. name: 'Predicted Values',
  178. type: 'value',
  179. min: parseFloat(min).toFixed(2),
  180. max: parseFloat(max).toFixed(2)
  181. },
  182. series: [
  183. {
  184. name: 'True vs Predicted',
  185. type: 'scatter',
  186. data: scatterData,
  187. symbolSize: 10,
  188. itemStyle: {
  189. color: '#1f77b4',
  190. opacity: 0.7
  191. }
  192. },
  193. {
  194. name: 'Trendline',
  195. type: 'line',
  196. data: [
  197. [min, min],
  198. [max, max]
  199. ],
  200. lineStyle: {
  201. type: 'dashed',
  202. color: '#ff7f0e',
  203. width: 2
  204. }
  205. }
  206. ]
  207. };
  208. }
  209. // 降酸模型散点图
  210. function getFinalScatterOption() {
  211. const calculateDataRange = (data) => {
  212. let xValues = data.map(item => item[0]);
  213. let yValues = data.map(item => item[1]);
  214. return {
  215. xMin: Math.min(...xValues),
  216. xMax: Math.max(...xValues),
  217. yMin: Math.min(...yValues),
  218. yMax: Math.max(...yValues)
  219. };
  220. };
  221. const scatterData = [[0.12931, 0.1144982841836412], [0.066298, 0.07733075000000009],
  222. [0.057692, 0.07784833000000009], [0.072464, 0.09429906104591025],
  223. [0.146414, 0.11774272000000004], [0.087263, 0.07587641627546172],
  224. [0.096983, 0.12344755999999983], [0.070505, 0.06424743000000006],
  225. [0.052497, 0.07665224568865422], [0.166515, 0.15591779999999988],
  226. [0.063291, 0.09275175104591024]];
  227. const range = calculateDataRange(scatterData);
  228. const padding = 0.1;
  229. const xMin = range.xMin - Math.abs(range.xMin * padding);
  230. const xMax = range.xMax + Math.abs(range.xMax * padding);
  231. const yMin = range.yMin - Math.abs(range.yMin * padding);
  232. const yMax = range.yMax + Math.abs(range.yMax * padding);
  233. const min = Math.min(xMin, yMin)
  234. const max = Math.max(xMax, yMax)
  235. return {
  236. tooltip: {
  237. trigger: 'axis',
  238. axisPointer: {
  239. type: 'cross'
  240. }
  241. },
  242. legend: {
  243. data: ['True vs Predicted']
  244. },
  245. grid: {
  246. left: '4%',
  247. right: '22%',
  248. bottom: '3%',
  249. containLabel: true
  250. },
  251. xAxis: {
  252. name: 'True Values',
  253. type: 'value',
  254. min: min,
  255. max: max
  256. },
  257. yAxis: {
  258. name: 'Predicted Values',
  259. type: 'value',
  260. min: parseFloat(min).toFixed(2),
  261. max: parseFloat(max).toFixed(2)
  262. },
  263. series: [
  264. {
  265. name: 'True vs Predicted',
  266. type: 'scatter',
  267. data: scatterData,
  268. symbolSize: 10,
  269. itemStyle: {
  270. color: '#1f77b4',
  271. opacity: 0.7
  272. }
  273. },
  274. {
  275. name: 'Trendline',
  276. type: 'line',
  277. data: [
  278. [min, min],
  279. [max, max]
  280. ],
  281. lineStyle: {
  282. type: 'dashed',
  283. color: '#ff7f0e',
  284. width: 2
  285. }
  286. }
  287. ]
  288. };
  289. }
  290. // 降酸模型折线图
  291. function getLineOption() {
  292. return {
  293. tooltip: {
  294. trigger: 'axis'
  295. },
  296. legend: {
  297. data: ['Random Forest', 'XGBoost', 'Gradient Boosting'] // 模型名称
  298. },
  299. grid: {
  300. left: '3%',
  301. right: '17%',
  302. bottom: '3%',
  303. containLabel: true
  304. },
  305. xAxis: {
  306. name: '模型迭代',
  307. type: 'category',
  308. boundaryGap: false,
  309. data: ['1代','2代','3代','4代','5代','6代','7代','8代','9代'] // train_sizes按10%递增
  310. },
  311. yAxis: {
  312. name: 'Score (R^2)',
  313. type: 'value'
  314. },
  315. series: [
  316. {
  317. name: 'Random Forest',
  318. type: 'line',
  319. data: [-0.07014332070467688, 0.16174446067644666, 0.45539363923645115, 0.42496898634299696, 0.4538427686692541, 0.418902219699232, 0.3944331740214546, 0.5036773554206873, 0.6231911298905934, 0.7017514238881619]
  320. },
  321. {
  322. name: 'XGBoost',
  323. type: 'line',
  324. data: [-0.5854699949971149, 0.12632204933742897, 0.5552415957727412, 0.36024885147666674, 0.3983302490476677, 0.11693728875627551, 0.41317321044147026, 0.7833174829404705, 0.6626050730438451, 0.8168196535959388]
  325. },
  326. {
  327. name: 'Gradient Boosting',
  328. type: 'line',
  329. data: [-0.2099996080229254, 0.2604127444757308, 0.5544068626708099, 0.37487088504748367, 0.32309657868722486, 0.24740671740183884, 0.4949107161199925, 0.694806526591159, 0.6719430144475025, 0.7889677514137288]
  330. }
  331. ]
  332. };
  333. }