|
13 | 13 | // [CLASS] Data split |
14 | 14 | //============================================================================ |
15 | 15 | define([ |
| 16 | + 'text!vp_base/html/m_ml/dataSplit.html!strip', |
| 17 | + 'css!vp_base/css/m_ml/dataSplit.css', |
16 | 18 | 'vp_base/js/com/com_util', |
| 19 | + 'vp_base/js/com/com_interface', |
17 | 20 | 'vp_base/js/com/com_Const', |
18 | 21 | 'vp_base/js/com/com_String', |
19 | 22 | 'vp_base/js/com/component/PopupComponent' |
20 | | -], function(com_util, com_Const, com_String, PopupComponent) { |
| 23 | +], function(dsHtml, dsCss, com_util, com_interface, com_Const, com_String, PopupComponent) { |
21 | 24 |
|
22 | 25 | /** |
23 | 26 | * Data split |
24 | 27 | */ |
25 | 28 | class DataSplit extends PopupComponent { |
26 | 29 | _init() { |
27 | 30 | super._init(); |
28 | | - /** Write codes executed before rendering */ |
| 31 | + this.config.sizeLevel = 2; |
| 32 | + this.config.dataview = false; |
| 33 | + |
| 34 | + this.state = { |
| 35 | + testSize: 0.25, |
| 36 | + trainFeatures: 'X_train', |
| 37 | + trainTarget: 'y_train', |
| 38 | + testFeatures: 'X_test', |
| 39 | + testTarget: 'y_test', |
| 40 | + ...this.state |
| 41 | + } |
29 | 42 | } |
30 | 43 |
|
31 | 44 | _bindEvent() { |
32 | 45 | super._bindEvent(); |
33 | | - /** Implement binding events */ |
34 | 46 | var that = this; |
35 | | - this.$target.on('click', function(evt) { |
36 | | - var target = evt.target; |
37 | | - if ($(that.wrapSelector()).find(target).length > 0) { |
38 | | - // Sample : getDataList from Kernel |
39 | | - vpKernel.getDataList().then(function(resultObj) { |
40 | | - vpLog.display(VP_LOG_TYPE.DEVELOP, resultObj); |
41 | | - }).catch(function(err) { |
42 | | - vpLog.display(VP_LOG_TYPE.DEVELOP, err); |
43 | | - }); |
44 | | - } |
| 47 | + |
| 48 | + // import library |
| 49 | + $(this.wrapSelector('#vp_libaryImport')).on('click', function() { |
| 50 | + com_interface.insertCell('code', 'from sklearn.model_selection import train_test_split'); |
45 | 51 | }); |
46 | 52 | } |
47 | 53 |
|
48 | 54 | templateForBody() { |
49 | | - /** Implement generating template */ |
50 | | - return 'This is sample.'; |
| 55 | + let page = $(dsHtml); |
| 56 | + |
| 57 | + // test size generating |
| 58 | + let sizeOptions = ''; |
| 59 | + for (let i=5; i<95; i+=5) { |
| 60 | + sizeOptions += `<option value="0.${i}" ${this.state.testSize==('0.'+i)?'selected':''}>${i}%</option>`; |
| 61 | + } |
| 62 | + $(page).find('#testSize').html(sizeOptions); |
| 63 | + return page; |
| 64 | + } |
| 65 | + |
| 66 | + render() { |
| 67 | + super.render(); |
| 68 | + |
| 69 | + |
| 70 | + |
51 | 71 | } |
52 | 72 |
|
53 | 73 | generateCode() { |
54 | | - return "print('sample code')"; |
| 74 | + let { |
| 75 | + trainFeatures, trainTarget, testFeatures, testTarget, |
| 76 | + dataType, featureData, targetData, |
| 77 | + testSize, randomState, shuffle, startify |
| 78 | + } = this.state; |
| 79 | + |
| 80 | + let options = new com_String(); |
| 81 | + if (testSize != '0.25') { |
| 82 | + options.appendFormat(', test_size={0}', testSize); |
| 83 | + } |
| 84 | + if (randomState && randomState != '') { |
| 85 | + options.appendFormat(', random_state={0}', randomState); |
| 86 | + } |
| 87 | + if (shuffle && shuffle != '') { |
| 88 | + options.appendFormat(', shuffle={0}', shuffle); |
| 89 | + } |
| 90 | + if (startify && startify != '') { |
| 91 | + options.appendFormat(', startify={0}', startify); |
| 92 | + } |
| 93 | + |
| 94 | + let code = new com_String(); |
| 95 | + code.appendFormat('{0}, {1}, {2}, {3} = train_test_split({4}, {5}{6})', |
| 96 | + trainFeatures, testFeatures, trainTarget, testTarget, |
| 97 | + featureData, targetData, options.toString()); |
| 98 | + return code.toString(); |
55 | 99 | } |
56 | 100 |
|
57 | 101 | } |
|
0 commit comments