SoilAcidReductionIterativeEvolution.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <template>
  2. <div class="container">
  3. <div class="chart-container">
  4. <VueEcharts :option="ecLineOption" ref="ecLineOptionRef" />
  5. </div>
  6. <p class="sub-title">初代散点图</p>
  7. <div class="chart-container">
  8. <VueEcharts :option="ecInitScatterOption" ref="ecInitScatterOptionRef" />
  9. </div>
  10. <p class="sub-title">中间代散点图</p>
  11. <div class="chart-container">
  12. <VueEcharts :option="ecMidScatterOption" ref="ecMidScatterOptionRef" />
  13. </div>
  14. <p class="sub-title">最终代散点图</p>
  15. <div class="chart-container">
  16. <VueEcharts :option="ecFinalScatterOption" ref="ecFinalScatterOptionRef" />
  17. </div>
  18. </div>
  19. </template>
  20. <script setup lang='ts' name=''>
  21. import {ref} from 'vue'
  22. import VueEcharts from 'vue-echarts';
  23. import 'echarts';
  24. const ecLineOptionRef = ref<InstanceType<typeof VueEcharts> | null>(null);
  25. const ecInitScatterOptionRef = ref<InstanceType<typeof VueEcharts> | null>(null);
  26. const ecMidScatterOptionRef = ref<InstanceType<typeof VueEcharts> | null>(null);
  27. const ecFinalScatterOptionRef = ref<InstanceType<typeof VueEcharts> | null>(null);
  28. // 计算数据范围的函数
  29. const calculateDataRange = (data: any[]) => {
  30. const xValues = data.map((item: any[]) => item[0]);
  31. const yValues = data.map((item: any[]) => item[1]);
  32. return {
  33. xMin: Math.min(...xValues),
  34. xMax: Math.max(...xValues),
  35. yMin: Math.min(...yValues),
  36. yMax: Math.max(...yValues)
  37. };
  38. };
  39. // 反酸模型 初代 散点图
  40. const getInitScatterOption=()=>{
  41. 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]];
  42. const range = calculateDataRange(scatterData);
  43. const padding = 0.1;
  44. const xMin = range.xMin - Math.abs(range.xMin * padding);
  45. const xMax = range.xMax + Math.abs(range.xMax * padding);
  46. const yMin = range.yMin - Math.abs(range.yMin * padding);
  47. const yMax = range.yMax + Math.abs(range.yMax * padding);
  48. const min = Math.min(xMin, yMin)
  49. const max = Math.max(xMax, yMax)
  50. return {
  51. tooltip: {
  52. trigger: 'axis',
  53. axisPointer: {
  54. type: 'cross'
  55. }
  56. },
  57. legend: {
  58. data: ['True vs Predicted']
  59. },
  60. grid: {
  61. left: '4%',
  62. right: '22%',
  63. bottom: '3%',
  64. containLabel: true
  65. },
  66. xAxis: {
  67. name: 'True Values',
  68. type: 'value',
  69. min: min,
  70. max: max
  71. },
  72. yAxis: {
  73. name: 'Predicted Values',
  74. type: 'value',
  75. min: parseFloat(min.toFixed(2)),
  76. max: parseFloat(max.toFixed(2))
  77. },
  78. series: [
  79. {
  80. name: 'True vs Predicted',
  81. type: 'scatter',
  82. data: scatterData,
  83. symbolSize: 10,
  84. itemStyle: {
  85. color: '#1f77b4',
  86. opacity: 0.7
  87. }
  88. },
  89. {
  90. name: 'Trendline',
  91. type: 'line',
  92. data: [
  93. [min, min],
  94. [max, max]
  95. ],
  96. lineStyle: {
  97. type: 'dashed',
  98. color: '#ff7f0e',
  99. width: 2
  100. }
  101. }
  102. ]
  103. };
  104. }
  105. // 反酸模型 中间代 散点图
  106. const getMidScatterOption=()=>{
  107. 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]];
  108. const range = calculateDataRange(scatterData);
  109. const padding = 0.1;
  110. const xMin = range.xMin - Math.abs(range.xMin * padding);
  111. const xMax = range.xMax + Math.abs(range.xMax * padding);
  112. const yMin = range.yMin - Math.abs(range.yMin * padding);
  113. const yMax = range.yMax + Math.abs(range.yMax * padding);
  114. const min = Math.min(xMin, yMin)
  115. const max = Math.max(xMax, yMax)
  116. return {
  117. tooltip: {
  118. trigger: 'axis',
  119. axisPointer: {
  120. type: 'cross'
  121. }
  122. },
  123. legend: {
  124. data: ['True vs Predicted']
  125. },
  126. grid: {
  127. left: '4%',
  128. right: '22%',
  129. bottom: '3%',
  130. containLabel: true
  131. },
  132. xAxis: {
  133. name: 'True Values',
  134. type: 'value',
  135. min: min,
  136. max: max
  137. },
  138. yAxis: {
  139. name: 'Predicted Values',
  140. type: 'value',
  141. min: parseFloat(min.toFixed(2)),
  142. max: parseFloat(max.toFixed(2))
  143. },
  144. series: [
  145. {
  146. name: 'True vs Predicted',
  147. type: 'scatter',
  148. data: scatterData,
  149. symbolSize: 10,
  150. itemStyle: {
  151. color: '#1f77b4',
  152. opacity: 0.7
  153. }
  154. },
  155. {
  156. name: 'Trendline',
  157. type: 'line',
  158. data: [
  159. [min, min],
  160. [max, max]
  161. ],
  162. lineStyle: {
  163. type: 'dashed',
  164. color: '#ff7f0e',
  165. width: 2
  166. }
  167. }
  168. ]
  169. };
  170. }
  171. // 反酸模型 最终代 散点图
  172. const getFinalScatterOption=() => {
  173. const scatterData = [[0.12931, 0.1144982841836412], [0.066298, 0.07733075000000009],
  174. [0.057692, 0.07784833000000009], [0.072464, 0.09429906104591025],
  175. [0.146414, 0.11774272000000004], [0.087263, 0.07587641627546172],
  176. [0.096983, 0.12344755999999983], [0.070505, 0.06424743000000006],
  177. [0.052497, 0.07665224568865422], [0.166515, 0.15591779999999988],
  178. [0.063291, 0.09275175104591024]];
  179. const range = calculateDataRange(scatterData);
  180. const padding = 0.1;
  181. const xMin = range.xMin - Math.abs(range.xMin * padding);
  182. const xMax = range.xMax + Math.abs(range.xMax * padding);
  183. const yMin = range.yMin - Math.abs(range.yMin * padding);
  184. const yMax = range.yMax + Math.abs(range.yMax * padding);
  185. const min = Math.min(xMin, yMin)
  186. const max = Math.max(xMax, yMax)
  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: '4%',
  199. right: '22%',
  200. bottom: '3%',
  201. containLabel: true
  202. },
  203. xAxis: {
  204. name: 'True Values',
  205. type: 'value',
  206. min: min,
  207. max: max
  208. },
  209. yAxis: {
  210. name: 'Predicted Values',
  211. type: 'value',
  212. min: parseFloat(min.toFixed(2)),
  213. max: parseFloat(max.toFixed(2))
  214. },
  215. series: [
  216. {
  217. name: 'True vs Predicted',
  218. type: 'scatter',
  219. data: scatterData,
  220. symbolSize: 10,
  221. itemStyle: {
  222. color: '#1f77b4',
  223. opacity: 0.7
  224. }
  225. },
  226. {
  227. name: 'Trendline',
  228. type: 'line',
  229. data: [
  230. [min, min],
  231. [max, max]
  232. ],
  233. lineStyle: {
  234. type: 'dashed',
  235. color: '#ff7f0e',
  236. width: 2
  237. }
  238. }
  239. ]
  240. };
  241. }
  242. //获取折线图配置
  243. const getLineOption=()=>{
  244. return{
  245. tooltip:{
  246. trigger:'axis'
  247. },
  248. legend:{
  249. data:['Random Forest', 'XGBoost', 'Gradient Boosting'] // 模型名称
  250. },
  251. grid: {
  252. left: '3%',
  253. right: '17%',
  254. bottom: '3%',
  255. containLabel: true
  256. },
  257. xAxis: {
  258. name: '模型迭代',
  259. type: 'category',
  260. boundaryGap: false,
  261. data: ['1代','2代','3代','4代','5代','6代','7代','8代','9代'] // train_sizes按10%递增
  262. },
  263. yAxis: {
  264. name: 'Score (R^2)',
  265. type: 'value'
  266. },
  267. series: [
  268. {
  269. name: 'Random Forest',
  270. type: 'line',
  271. data: [-0.07014332070467688, 0.16174446067644666, 0.45539363923645115, 0.42496898634299696, 0.4538427686692541, 0.418902219699232, 0.3944331740214546, 0.5036773554206873, 0.6231911298905934, 0.7017514238881619]
  272. },
  273. {
  274. name: 'XGBoost',
  275. type: 'line',
  276. data: [-0.5854699949971149, 0.12632204933742897, 0.5552415957727412, 0.36024885147666674, 0.3983302490476677, 0.11693728875627551, 0.41317321044147026, 0.7833174829404705, 0.6626050730438451, 0.8168196535959388]
  277. },
  278. {
  279. name: 'Gradient Boosting',
  280. type: 'line',
  281. data: [-0.2099996080229254, 0.2604127444757308, 0.5544068626708099, 0.37487088504748367, 0.32309657868722486, 0.24740671740183884, 0.4949107161199925, 0.694806526591159, 0.6719430144475025, 0.7889677514137288]
  282. }
  283. ]
  284. }
  285. }
  286. const ecLineOption=ref(getLineOption());
  287. const ecInitScatterOption = ref(getInitScatterOption());
  288. const ecMidScatterOption = ref(getMidScatterOption());
  289. const ecFinalScatterOption = ref(getFinalScatterOption());
  290. </script>
  291. <style scoped>
  292. .container {
  293. display: flex;
  294. flex-direction: column;
  295. align-items: center;
  296. justify-content: center;
  297. width: 100%;
  298. height: 100%;
  299. gap: 20px;
  300. }
  301. .sub-title {
  302. font-size: 14px;
  303. font-weight: 700;
  304. }
  305. .chart-container {
  306. width: 75%;
  307. height: 450px;
  308. margin-bottom: 20px;
  309. }
  310. .VueEcharts {
  311. width: 100%;
  312. height: 100%;
  313. margin: 0 10px;
  314. }
  315. </style>