Model Classification Tuning

描述:当前是关于Echarts图表中的 示例。
 
             var rawData = [
     [0.0, 1.0, 0.0, 0.0, 726.0, 0.0, 274.0, 0.43, 0.27, 1.0, 1.0, 0.27],
     [0.01, 16.0, 0.0, 11.0, 715.0, 0.0, 274.0, 0.43, 0.28, 0.98, 1.0, 0.28],
     [0.02, 42.0, 0.0, 35.0, 691.0, 0.0, 274.0, 0.44, 0.28, 0.95, 1.0, 0.31],
     [0.03, 42.0, 2.0, 77.0, 649.0, 0.0, 274.0, 0.46, 0.3, 0.89, 1.0, 0.35],
     [0.04, 31.0, 2.0, 119.0, 607.0, 2.0, 272.0, 0.47, 0.31, 0.84, 0.99, 0.39],
     [0.05, 42.0, 2.0, 158.0, 568.0, 4.0, 270.0, 0.49, 0.32, 0.78, 0.99, 0.43],
     [0.06, 27.0, 5.0, 190.0, 536.0, 6.0, 268.0, 0.5, 0.33, 0.74, 0.98, 0.46],
     [0.07, 26.0, 2.0, 216.0, 510.0, 11.0, 263.0, 0.5, 0.34, 0.7, 0.96, 0.48],
     [0.08, 21.0, 2.0, 241.0, 485.0, 13.0, 261.0, 0.51, 0.35, 0.67, 0.95, 0.5],
     [0.09, 20.0, 4.0, 258.0, 468.0, 16.0, 258.0, 0.52, 0.36, 0.64, 0.94, 0.52],
     [0.1, 25.0, 3.0, 283.0, 443.0, 20.0, 254.0, 0.52, 0.36, 0.61, 0.93, 0.54],
     [0.11, 16.0, 1.0, 299.0, 427.0, 22.0, 252.0, 0.53, 0.37, 0.59, 0.92, 0.55],
     [0.12, 23.0, 3.0, 322.0, 404.0, 23.0, 251.0, 0.54, 0.38, 0.56, 0.92, 0.57],
     [0.13, 17.0, 0.0, 343.0, 383.0, 26.0, 248.0, 0.55, 0.39, 0.53, 0.91, 0.59],
     [0.14, 11.0, 2.0, 353.0, 373.0, 26.0, 248.0, 0.55, 0.4, 0.51, 0.91, 0.6],
     [0.15, 14.0, 2.0, 364.0, 362.0, 28.0, 246.0, 0.56, 0.4, 0.5, 0.9, 0.61],
     [0.16, 21.0, 2.0, 387.0, 339.0, 30.0, 244.0, 0.57, 0.42, 0.47, 0.89, 0.63],
     [0.17, 17.0, 3.0, 404.0, 322.0, 33.0, 241.0, 0.58, 0.43, 0.44, 0.88, 0.64],
     [0.18, 15.0, 2.0, 418.0, 308.0, 36.0, 238.0, 0.58, 0.44, 0.42, 0.87, 0.66],
     [0.19, 10.0, 1.0, 431.0, 295.0, 38.0, 236.0, 0.59, 0.44, 0.41, 0.86, 0.67],
     [0.2, 12.0, 3.0, 443.0, 283.0, 38.0, 236.0, 0.6, 0.45, 0.39, 0.86, 0.68],
     [0.21, 14.0, 5.0, 460.0, 266.0, 42.0, 232.0, 0.6, 0.47, 0.37, 0.85, 0.69],
     [0.22, 8.0, 4.0, 467.0, 259.0, 46.0, 228.0, 0.6, 0.47, 0.36, 0.83, 0.7],
     [0.23, 9.0, 4.0, 475.0, 251.0, 50.0, 224.0, 0.6, 0.47, 0.35, 0.82, 0.7],
     [0.24, 10.0, 4.0, 486.0, 240.0, 54.0, 220.0, 0.6, 0.48, 0.33, 0.8, 0.71],
     [0.25, 14.0, 3.0, 498.0, 228.0, 59.0, 215.0, 0.6, 0.49, 0.31, 0.78, 0.71],
     [0.26, 10.0, 4.0, 510.0, 216.0, 61.0, 213.0, 0.61, 0.5, 0.3, 0.78, 0.72],
     [0.27, 6.0, 3.0, 517.0, 209.0, 65.0, 209.0, 0.6, 0.5, 0.29, 0.76, 0.73],
     [0.28, 11.0, 3.0, 525.0, 201.0, 68.0, 206.0, 0.6, 0.51, 0.28, 0.75, 0.73],
     [0.29, 8.0, 4.0, 535.0, 191.0, 73.0, 201.0, 0.6, 0.51, 0.26, 0.73, 0.74],
     [0.3, 10.0, 6.0, 544.0, 182.0, 75.0, 199.0, 0.61, 0.52, 0.25, 0.73, 0.74],
     [0.31, 8.0, 3.0, 555.0, 171.0, 82.0, 192.0, 0.6, 0.53, 0.24, 0.7, 0.75],
     [0.32, 10.0, 6.0, 563.0, 163.0, 84.0, 190.0, 0.61, 0.54, 0.22, 0.69, 0.75],
     [0.33, 9.0, 4.0, 572.0, 154.0, 90.0, 184.0, 0.6, 0.54, 0.21, 0.67, 0.76],
     [0.34, 13.0, 2.0, 581.0, 145.0, 94.0, 180.0, 0.6, 0.55, 0.2, 0.66, 0.76],
     [0.35, 0.0, 1.0, 587.0, 139.0, 96.0, 178.0, 0.6, 0.56, 0.19, 0.65, 0.76],
     [0.36, 6.0, 1.0, 593.0, 133.0, 97.0, 177.0, 0.61, 0.57, 0.18, 0.65, 0.77],
     [0.37, 6.0, 3.0, 598.0, 128.0, 99.0, 175.0, 0.61, 0.58, 0.18, 0.64, 0.77],
     [0.38, 8.0, 7.0, 604.0, 122.0, 101.0, 173.0, 0.61, 0.59, 0.17, 0.63, 0.78],
     [0.39, 5.0, 6.0, 612.0, 114.0, 109.0, 165.0, 0.6, 0.59, 0.16, 0.6, 0.78],
     [0.4, 11.0, 2.0, 622.0, 104.0, 114.0, 160.0, 0.59, 0.61, 0.14, 0.58, 0.78],
     [0.41, 0.0, 2.0, 623.0, 103.0, 116.0, 158.0, 0.59, 0.61, 0.14, 0.58, 0.78],
     [0.42, 2.0, 4.0, 626.0, 100.0, 118.0, 156.0, 0.59, 0.61, 0.14, 0.57, 0.78],
     [0.43, 2.0, 2.0, 629.0, 97.0, 122.0, 152.0, 0.58, 0.61, 0.13, 0.55, 0.78],
     [0.44, 9.0, 2.0, 634.0, 92.0, 124.0, 150.0, 0.58, 0.62, 0.13, 0.55, 0.78],
     [0.45, 6.0, 4.0, 642.0, 84.0, 127.0, 147.0, 0.58, 0.64, 0.12, 0.54, 0.79],
     [0.46, 7.0, 6.0, 646.0, 80.0, 131.0, 143.0, 0.58, 0.64, 0.11, 0.52, 0.79],
     [0.47, 0.0, 3.0, 650.0, 76.0, 136.0, 138.0, 0.57, 0.64, 0.1, 0.5, 0.79],
     [0.48, 5.0, 3.0, 652.0, 74.0, 139.0, 135.0, 0.56, 0.65, 0.1, 0.49, 0.79],
     [0.49, 2.0, 2.0, 658.0, 68.0, 142.0, 132.0, 0.56, 0.66, 0.09, 0.48, 0.79],
     [0.5, 5.0, 5.0, 662.0, 64.0, 145.0, 129.0, 0.55, 0.67, 0.09, 0.47, 0.79],
     [0.51, 1.0, 3.0, 664.0, 62.0, 149.0, 125.0, 0.54, 0.67, 0.09, 0.46, 0.79],
     [0.52, 3.0, 2.0, 666.0, 60.0, 152.0, 122.0, 0.54, 0.67, 0.08, 0.45, 0.79],
     [0.53, 5.0, 5.0, 669.0, 57.0, 154.0, 120.0, 0.53, 0.68, 0.08, 0.44, 0.79],
     [0.54, 3.0, 8.0, 674.0, 52.0, 159.0, 115.0, 0.52, 0.69, 0.07, 0.42, 0.79],
     [0.55, 1.0, 2.0, 675.0, 51.0, 167.0, 107.0, 0.5, 0.68, 0.07, 0.39, 0.78],
     [0.56, 12.0, 3.0, 680.0, 46.0, 169.0, 105.0, 0.49, 0.7, 0.06, 0.38, 0.78],
     [0.57, 0.0, 6.0, 687.0, 39.0, 172.0, 102.0, 0.49, 0.72, 0.05, 0.37, 0.79],
     [0.58, 2.0, 7.0, 688.0, 38.0, 180.0, 94.0, 0.46, 0.71, 0.05, 0.34, 0.78],
     [0.59, 0.0, 2.0, 690.0, 36.0, 185.0, 89.0, 0.45, 0.71, 0.05, 0.32, 0.78],
     [0.6, 5.0, 2.0, 694.0, 32.0, 188.0, 86.0, 0.44, 0.73, 0.04, 0.31, 0.78],
     [0.61, 1.0, 1.0, 696.0, 30.0, 189.0, 85.0, 0.44, 0.74, 0.04, 0.31, 0.78],
     [0.62, 1.0, 6.0, 696.0, 30.0, 190.0, 84.0, 0.43, 0.74, 0.04, 0.31, 0.78],
     [0.63, 1.0, 5.0, 698.0, 28.0, 196.0, 78.0, 0.41, 0.74, 0.04, 0.28, 0.78],
     [0.64, 1.0, 10.0, 698.0, 28.0, 201.0, 73.0, 0.39, 0.72, 0.04, 0.27, 0.77],
     [0.65, 1.0, 3.0, 700.0, 26.0, 212.0, 62.0, 0.34, 0.7, 0.04, 0.23, 0.76],
     [0.66, 3.0, 5.0, 703.0, 23.0, 215.0, 59.0, 0.33, 0.72, 0.03, 0.22, 0.76],
     [0.67, 1.0, 4.0, 703.0, 23.0, 220.0, 54.0, 0.31, 0.7, 0.03, 0.2, 0.76],
     [0.68, 5.0, 3.0, 706.0, 20.0, 223.0, 51.0, 0.3, 0.72, 0.03, 0.19, 0.76],
     [0.69, 1.0, 3.0, 707.0, 19.0, 226.0, 48.0, 0.28, 0.72, 0.03, 0.18, 0.76],
     [0.7, 0.0, 6.0, 710.0, 16.0, 229.0, 45.0, 0.27, 0.74, 0.02, 0.16, 0.76],
     [0.71, 1.0, 4.0, 711.0, 15.0, 235.0, 39.0, 0.24, 0.72, 0.02, 0.14, 0.75],
     [0.72, 1.0, 2.0, 711.0, 15.0, 239.0, 35.0, 0.22, 0.7, 0.02, 0.13, 0.75],
     [0.73, 1.0, 5.0, 712.0, 14.0, 241.0, 33.0, 0.21, 0.7, 0.02, 0.12, 0.74],
     [0.74, 0.0, 6.0, 713.0, 13.0, 247.0, 27.0, 0.17, 0.68, 0.02, 0.1, 0.74],
     [0.75, 6.0, 2.0, 715.0, 11.0, 252.0, 22.0, 0.14, 0.67, 0.02, 0.08, 0.74],
     [0.76, 1.0, 5.0, 720.0, 6.0, 256.0, 18.0, 0.12, 0.75, 0.01, 0.07, 0.74],
     [0.77, 1.0, 2.0, 721.0, 5.0, 259.0, 15.0, 0.1, 0.75, 0.01, 0.05, 0.74],
     [0.78, 0.0, 1.0, 721.0, 5.0, 261.0, 13.0, 0.09, 0.72, 0.01, 0.05, 0.73],
     [0.79, 0.0, 2.0, 721.0, 5.0, 262.0, 12.0, 0.08, 0.71, 0.01, 0.04, 0.73],
     [0.8, 2.0, 4.0, 722.0, 4.0, 264.0, 10.0, 0.07, 0.71, 0.01, 0.04, 0.73],
     [0.81, 1.0, 2.0, 723.0, 3.0, 268.0, 6.0, 0.04, 0.67, 0.0, 0.02, 0.73],
     [0.82, 1.0, 0.0, 723.0, 3.0, 270.0, 4.0, 0.03, 0.57, 0.0, 0.01, 0.73],
     [0.83, 0.0, 1.0, 724.0, 2.0, 270.0, 4.0, 0.03, 0.67, 0.0, 0.01, 0.73],
     [0.84, 0.0, 2.0, 725.0, 1.0, 271.0, 3.0, 0.02, 0.75, 0.0, 0.01, 0.73],
     [0.85, 0.0, 0.0, 725.0, 1.0, 273.0, 1.0, 0.01, 0.5, 0.0, 0.0, 0.73],
     [0.86, 1.0, 0.0, 726.0, 0.0, 273.0, 1.0, 0.01, 1.0, 0.0, 0.0, 0.73],
     [0.87, 0.0, 1.0, 726.0, 0.0, 274.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.73],
     [0.88, 0.0, 0.0, 726.0, 0.0, 274.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.73],
     [0.89, 0.0, 0.0, 726.0, 0.0, 274.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.73],
     [0.9, 0.0, 0.0, 726.0, 0.0, 274.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.73],
     [0.91, 0.0, 0.0, 726.0, 0.0, 274.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.73],
     [0.92, 0.0, 0.0, 726.0, 0.0, 274.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.73],
     [0.93, 0.0, 0.0, 726.0, 0.0, 274.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.73],
     [0.94, 0.0, 0.0, 726.0, 0.0, 274.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.73],
     [0.95, 0.0, 0.0, 726.0, 0.0, 274.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.73],
     [0.96, 0.0, 0.0, 726.0, 0.0, 274.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.73],
     [0.97, 0.0, 0.0, 726.0, 0.0, 274.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.73],
     [0.98, 0.0, 0.0, 726.0, 0.0, 274.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.73],
     [0.99, 0.0, 0.0, 726.0, 0.0, 274.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.73],
     [1.0, 0.0, 0.0, 726.0, 0.0, 274.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.73]
 ];
 var cost = [220.0, 308.0, 500.0, 836.0, 1068.0, 1276.0, 1428.0, 1376.0, 1472.0, 1452.0, 1444.0, 1468.0, 1600.0, 1612.0, 1692.0, 1676.0, 1756.0, 1736.0, 1692.0, 1692.0, 1788.0, 1716.0, 1564.0, 1420.0, 1300.0, 1136.0, 1128.0, 976.0, 884.0, 704.0, 672.0, 396.0, 356.0, 116.0, -20.0, -76.0, -80.0, -144.0, -200.0, -552.0, -732.0, -828.0, -908.0, -1092.0, -1156.0, -1248.0, -1424.0, -1652.0, -1792.0, -1900.0, -2024.0, -2216.0, -2356.0, -2436.0, -2656.0, -3064.0, -3128.0, -3228.0, -3636.0, -3880.0, -4004.0, -4040.0, -4092.0, -4388.0, -4648.0, -5204.0, -5336.0, -5596.0, -5728.0, -5876.0, -6008.0, -6312.0, -6520.0, -6616.0, -6920.0, -7164.0, -7332.0, -7480.0, -7584.0, -7636.0, -7732.0, -7932.0, -8036.0, -8028.0, -8072.0, -8176.0, -8168.0, -8220.0, -8220.0, -8220.0, -8220.0, -8220.0, -8220.0, -8220.0, -8220.0, -8220.0, -8220.0, -8220.0, -8220.0, -8220.0, -8220.0];
 var m = {
     tnw: 0,
     fpw:-8,
     fnw:-30,
     tpw:22,
 }

 function splitData(rawData,m) {
     var cutoffs = [];
     var freq_0 = [];
     var freq_1 = [];
     var cm = [];
     var measures = [];
     var cost = [];


     for (var i = 0; i < rawData.length; i++) {
         cutoffs.push(rawData[i][0]);
         freq_0.push(rawData[i][1]);
         freq_1.push(rawData[i][2]);
         var cm_rec = {
             tn: rawData[i][3],
             fp: rawData[i][4],
             fn: rawData[i][5],
             tp: rawData[i][6],
         }
         cm.push(cm_rec);

        cost.push(cm_rec.tn * m.tnw + cm_rec.fp * m.fpw + cm_rec.fn * m.fnw + cm_rec.tp * m.tpw);

         measures.push({
                 fscore: rawData[i][7],
                 precision: rawData[i][8],
                 fpr: rawData[i][9],
                 recall: rawData[i][10],
                 accuracy: rawData[i][11],
             }

         );
     }

     return {
         cutoffs: cutoffs,
         freq_0: freq_0,
         freq_1: freq_1,
         cm: cm,
         measures: measures,
         cost:cost,
     };
 }

 var data = splitData(rawData,m);
 var cutoffs = data.cutoffs;
 var freq_0 = data.freq_0;
 var freq_1 = data.freq_1;
 var cm = data.cm;
 var measures = data.measures;
 var cost = data.cost;
//  var optiamlCutoff = ;
 option = {
     backgroundColor: 'rgba(245, 245, 245, 0.8)',
     title: [{
         x: 0,
         y: 0,
         text: 'Predictive Probability distrubition',
         textStyle: {
             fontWeight: 'normal',
             fontSize: 16,
             color: '#F1F1F3'
         },
         left: '6%'
     }, {
         x: 1,
         y2: 1,
         text: 'Revenue Chart',
         textStyle: {
             fontWeight: 'normal',
             fontSize: 16,
             color: '#F1F1F3'
         },
         left: '6%',
         position: 'top',
     }],
     tooltip: {
         axisPointer:{
         lineStyle:{
             
                 opacity: 0.5,
                 width: 4,
            
         }
             
         },
         trigger: 'axis',
         triggerOn: 'mousemove | click',
         backgroundColor: 'rgba(245, 245, 245, 0.8)',
         borderWidth: 1,
         borderColor: '#ccc',
         padding: 10,
         textStyle: {
             color: '#000'
         },
         formatter: function(params) {
             index = params[0].dataIndex;
             console.log(index);
             return "Cutoff :" + index / 100 +
                "<br/>"+ "Profit :" + cost[index];

         },
     },
     legend: {
         icon: 'rect',
         itemWidth: 14,
         itemHeight: 5,
         itemGap: 13,
         data: ['0', '1'],
         right: '4%',
         textStyle: {
             fontSize: 12,
             color: '#F1F1F3'
         },
     },
     grid: [{
             left: '7%',
             right: '7%',
             width: '86%',
             height: '38%'
         },
         {
             left: '7%',
             right: '7%',
             width: '86%',
             top: '57%'
         },
     ],

     axisPointer: {
         link: {
             xAxisIndex: 'all'
         },
         label: {
             backgroundColor: '#777'
         }
     },

     // {
     //     left: '3%',
     //     right: '4%',
     //     bottom: '3%',
     //     containLabel: true
     // },
     xAxis: [{
         gridIndex: 0,
         type: 'category',
         boundaryGap: false,
         axisLine: {
             oneZero: false,
             // lineStyle: {
             //     color: '#57617B'
             // }
         },
         data: cutoffs
     }, {
         gridIndex: 1,
         type: 'category',
         boundaryGap: false,
         axisLine: {
             oneZero: false,
             // lineStyle: {
             //     color: '#57617B'
             // }
         },
         axisLabel: {
           show:false,  
         },
         data: cutoffs
     }, ],
     yAxis: [{
             gridIndex: 0,
             type: 'value',
             name: 'Observations',
             axisTick: {
                 show: false
             },
             axisLine: {
                 lineStyle: {
                     color: '#57617B'
                 }
             },
             axisLabel: {
                 // show: false,
                 margin: 10,
                 textStyle: {
                     fontSize: 14
                 }
             },
             splitLine: {
                 // show: false,
                 lineStyle: {
                     color: '#57617B'
                 }
             }
         },
         {
             gridIndex: 1,
             type: 'value',
             name: 'Revenue',
             axisTick: {
                 show: false,
             },
             axisLine: {
                 oneZero: false,
                //  lineStyle: {
                //      color: '#57617B'
                //  }
             },
             axisLabel: {
                 show: true,
                 margin: 10,
                 textStyle: {
                     fontSize: 14
                 }
             },
             splitLine: {
                 show: false,
                //  lineStyle: {
                //      color: '#57617B'
                //  }
             }
         }
     ],
     series: [{
         xAxisIndex: 0,
         yAxisIndex: 0,
         name: '0',
         type: 'line',
         smooth: true,
         symbol: 'circle',
         symbolSize: 0.1,
         showAllSymbol: true,
         lineStyle: {
             normal: {
                 opacity: 0.5,
                //  width: 1
             }
         },
         data: freq_0
     }, {
         xAxisIndex: 0,
         yAxisIndex: 0,
         name: '1',
         type: 'line',
         smooth: true,
         symbol: 'circle',
         symbolSize: 0.1,
         showAllSymbol: true,
         lineStyle: {
             normal: {
                  opacity: 0.5,
                //  width: 1
             }
         },
         data: freq_1,
          markLine: {
                    silent: true,
                    // position:'bottom',
                    symbol:['none','arrow'],
                    label: {
                                normal: {
                                    formatter: 'Optimal cut-off for Revenue'
                                }
                            },
                    lineStyle: {
                        normal:{
                          
                            type: 'solid',
                            opacity: 0.5,
                            width:2,
                        }
                    },
                    data: [
                         {name: 'Best', xAxis: 20}
                    ]
         },

     }, {
         xAxisIndex: 1,
         yAxisIndex: 1,
         name: 'Revene',
         type: 'bar',
         smooth: true,
         // symbol: 'circle',
         // symbolSize: 0.1,
         showAllSymbol: true,
         itemStyle: {
             normal: {
                 // color:'#00da3c',
                 color: function(params) {
		              var colorList;
		              if (cost[params.dataIndex]>0) {
		                  colorList = '#ef232a';
		              } else {
		                  colorList = '#14b143';
		              }
		              return colorList;
		          },
                 width: 1
             }
         },
         data: cost,
         markLine: {
                    silent: true,
                    position:'bottom',
                    symbol:['none','none'],
                    label: {
                                normal: {
                                    formatter: ''
                                }
                            },
                    lineStyle: {
                        normal:{
                            type: 'solid',
                            opacity: 0.5,
                            width:2,
                        }
                    },
                    data: [
                         {name: 'Best', xAxis: 20}
                    ]
         },
     }]
 };