Skip to content

Commit 89af041

Browse files
author
minjk-bl
committed
SVR, SVC - model option changes on kernel selection
1 parent 3741bc5 commit 89af041

File tree

3 files changed

+141
-18
lines changed

3 files changed

+141
-18
lines changed

data/m_ml/mlLibrary.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -269,37 +269,40 @@ define([
269269
'ridge': {
270270
name: 'Ridge',
271271
import: 'from sklearn.linear_model import Ridge',
272-
code: 'Ridge(${etc})',
272+
code: 'Ridge(${alpha}${etc})',
273273
options: [
274-
//TODO:
274+
{ name: 'alpha', component: ['input_number'], default: 1.0, usePair: true }
275275
]
276276
},
277277
'lasso': {
278278
name: 'Lasso',
279279
import: 'from sklearn.linear_model import Lasso',
280-
code: 'Lasso(${etc})',
280+
code: 'Lasso(${alpha}${etc})',
281281
options: [
282-
//TODO:
282+
{ name: 'alpha', component: ['input_number'], default: 1.0, usePair: true }
283283
]
284284
},
285285
'elasticnet': {
286286
name: 'ElasticNet',
287287
import: 'from sklearn.linear_model import ElasticNet',
288-
code: 'ElasticNet(${etc})',
288+
code: 'ElasticNet(${alpha}${l1_ratio}${etc})',
289289
options: [
290-
//TODO:
290+
{ name: 'alpha', component: ['input_number'], default: 1.0, usePair: true },
291+
{ name: 'l1_ratio', component: ['input_number'], default: 0.5, usePair: true }
291292
]
292293
},
293294
'sv-rgs': {
294295
name: 'SVR',
295296
import: 'from sklearn.svm import SVR',
296-
code: 'SVR(${C}${kernel}${gamma}${random_state}${etc})',
297+
code: 'SVR(${C}${kernel}${degree}${gamma}${coef0}${random_state}${etc})',
297298
options: [
298299
{ name: 'C', component: ['input_number'], placeholder: '1.0', usePair: true },
299-
{ name: 'kernel', component: ['option_select'], type: 'text', default: 'rbf', type:'text', usePair: true,
300-
options: ['linear', 'poly', 'rbf', 'sigmoid', 'precomputed'] },
301-
{ name: 'gamma', component: ['option_suggest'], default: 'scale', type:'text', usePair: true,
302-
options: ['scale', 'auto'] },
300+
{ name: 'kernel', component: ['option_select'], type: 'text', usePair: true,
301+
options: ['linear', 'poly', 'rbf', 'sigmoid', 'precomputed'], default: 'rbf' },
302+
{ name: 'degree', component: ['input_number'], placeholder: '3', usePair: true },
303+
{ name: 'gamma', component: ['option_suggest'], usePair: true,
304+
options: ["'scale'", "'auto'"], default: "'scale'" },
305+
{ name: 'coef0', component: ['input_number'], placeholder: '0.0', usePair: true },
303306
{ name: 'random_state', component: ['input_number'], placeholder: '123', usePair: true }
304307
]
305308
},
@@ -422,15 +425,17 @@ define([
422425
]
423426
},
424427
'sv-clf': {
425-
name: 'SupportVectorClassifier',
428+
name: 'SVC',
426429
import: 'from sklearn.svm import SVC',
427-
code: 'SVC(${C}${kernel}${gamma}${random_state}${etc})',
430+
code: 'SVC(${C}${kernel}${degree}${gamma}${coef0}${random_state}${etc})',
428431
options: [
429432
{ name: 'C', component: ['input_number'], placeholder: '1.0', usePair: true },
430433
{ name: 'kernel', component: ['option_select'], type: 'text', usePair: true,
431434
options: ['linear', 'poly', 'rbf', 'sigmoid', 'precomputed'], default: 'rbf' },
432-
{ name: 'gamma', component: ['option_suggest'], usePair: true,
433-
options: ['scale', 'auto'], default: 'scale' },
435+
{ name: 'degree', component: ['input_number'], placeholder: '3', usePair: true },
436+
{ name: 'gamma', component: ['option_suggest'], usePair: true,
437+
options: ["'scale'", "'auto'"], default: "'scale'" },
438+
{ name: 'coef0', component: ['input_number'], placeholder: '0.0', usePair: true },
434439
{ name: 'random_state', component: ['input_number'], placeholder: '123', usePair: true }
435440
]
436441
},

js/m_ml/Classification.js

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ define([
6868
$(that.wrapSelector(`.vp-model-box[data-type="${modelControlType}"]`)).show();
6969
});
7070

71-
// select model
71+
// select model type
7272
$(this.wrapSelector('#modelType')).on('change', function() {
7373
let modelType = $(this).val();
7474
that.state.modelType = modelType;
7575
$(that.wrapSelector('.vp-model-option-box')).html(that.templateForOption(modelType));
76+
that.viewOption();
7677

7778
// show install button
7879
if (that.modelConfig[modelType].install != undefined) {
@@ -94,7 +95,7 @@ define([
9495
// change model
9596
$(this.wrapSelector('#model')).on('change', function() {
9697
that.modelEditor.reload();
97-
})
98+
});
9899
}
99100

100101
templateForBody() {
@@ -227,9 +228,67 @@ define([
227228
return optBox.toString();
228229
}
229230

231+
viewOption() {
232+
// SVC - kernel selection
233+
if (this.state.modelType == 'sv-clf') {
234+
let kernelType = this.state.kernel;
235+
switch (kernelType) {
236+
case undefined: // default = rbf
237+
case '':
238+
case 'rbf': // gamma
239+
$(this.wrapSelector('label[for="gamma"]')).show();
240+
$(this.wrapSelector('#gamma')).show();
241+
// hide others
242+
$(this.wrapSelector('label[for="degree"]')).hide();
243+
$(this.wrapSelector('#degree')).hide();
244+
$(this.wrapSelector('label[for="coef0"]')).hide();
245+
$(this.wrapSelector('#coef0')).hide();
246+
break;
247+
case 'poly': // gamma / degree / coef0
248+
$(this.wrapSelector('label[for="gamma"]')).show();
249+
$(this.wrapSelector('#gamma')).show();
250+
$(this.wrapSelector('label[for="degree"]')).show();
251+
$(this.wrapSelector('#degree')).show();
252+
$(this.wrapSelector('label[for="coef0"]')).show();
253+
$(this.wrapSelector('#coef0')).show();
254+
break;
255+
case 'sigmoid': // gamma / coef0
256+
$(this.wrapSelector('label[for="gamma"]')).show();
257+
$(this.wrapSelector('#gamma')).show();
258+
$(this.wrapSelector('label[for="coef0"]')).show();
259+
$(this.wrapSelector('#coef0')).show();
260+
// hide others
261+
$(this.wrapSelector('label[for="degree"]')).hide();
262+
$(this.wrapSelector('#degree')).hide();
263+
break;
264+
default:
265+
// hide others
266+
$(this.wrapSelector('label[for="gamma"]')).hide();
267+
$(this.wrapSelector('#gamma')).hide();
268+
$(this.wrapSelector('label[for="degree"]')).hide();
269+
$(this.wrapSelector('#degree')).hide();
270+
$(this.wrapSelector('label[for="coef0"]')).hide();
271+
$(this.wrapSelector('#coef0')).hide();
272+
break;
273+
}
274+
275+
// Model Creation - SVC kernel selection
276+
let that = this;
277+
$(this.wrapSelector('#kernel')).off('change');
278+
$(this.wrapSelector('#kernel')).change(function() {
279+
that.state.kernel = $(this).val();
280+
that.viewOption();
281+
});
282+
}
283+
284+
}
285+
230286
render() {
231287
super.render();
232288

289+
// Model Creation - dynamically view options
290+
this.viewOption();
291+
233292
// Model Editor
234293
this.modelEditor = new ModelEditor(this, "model", "instanceEditor");
235294
}

js/m_ml/Regression.js

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ define([
6868
$(that.wrapSelector(`.vp-model-box[data-type="${modelControlType}"]`)).show();
6969
});
7070

71-
// select model
71+
// select model type
7272
$(this.wrapSelector('#modelType')).on('change', function() {
7373
let modelType = $(this).val();
7474
that.state.modelType = modelType;
7575
$(that.wrapSelector('.vp-model-option-box')).html(that.templateForOption(modelType));
76+
that.viewOption();
7677

7778
// show install button
7879
if (that.modelConfig[modelType].install != undefined) {
@@ -227,9 +228,67 @@ define([
227228
return optBox.toString();
228229
}
229230

231+
viewOption() {
232+
// SVR - kernel selection
233+
if (this.state.modelType == 'sv-rgs') {
234+
let kernelType = this.state.kernel;
235+
switch (kernelType) {
236+
case undefined: // default = rbf
237+
case '':
238+
case 'rbf': // gamma
239+
$(this.wrapSelector('label[for="gamma"]')).show();
240+
$(this.wrapSelector('#gamma')).show();
241+
// hide others
242+
$(this.wrapSelector('label[for="degree"]')).hide();
243+
$(this.wrapSelector('#degree')).hide();
244+
$(this.wrapSelector('label[for="coef0"]')).hide();
245+
$(this.wrapSelector('#coef0')).hide();
246+
break;
247+
case 'poly': // gamma / degree / coef0
248+
$(this.wrapSelector('label[for="gamma"]')).show();
249+
$(this.wrapSelector('#gamma')).show();
250+
$(this.wrapSelector('label[for="degree"]')).show();
251+
$(this.wrapSelector('#degree')).show();
252+
$(this.wrapSelector('label[for="coef0"]')).show();
253+
$(this.wrapSelector('#coef0')).show();
254+
break;
255+
case 'sigmoid': // gamma / coef0
256+
$(this.wrapSelector('label[for="gamma"]')).show();
257+
$(this.wrapSelector('#gamma')).show();
258+
$(this.wrapSelector('label[for="coef0"]')).show();
259+
$(this.wrapSelector('#coef0')).show();
260+
// hide others
261+
$(this.wrapSelector('label[for="degree"]')).hide();
262+
$(this.wrapSelector('#degree')).hide();
263+
break;
264+
default:
265+
// hide others
266+
$(this.wrapSelector('label[for="gamma"]')).hide();
267+
$(this.wrapSelector('#gamma')).hide();
268+
$(this.wrapSelector('label[for="degree"]')).hide();
269+
$(this.wrapSelector('#degree')).hide();
270+
$(this.wrapSelector('label[for="coef0"]')).hide();
271+
$(this.wrapSelector('#coef0')).hide();
272+
break;
273+
}
274+
275+
// Model Creation - SVC kernel selection
276+
let that = this;
277+
$(this.wrapSelector('#kernel')).off('change');
278+
$(this.wrapSelector('#kernel')).change(function() {
279+
that.state.kernel = $(this).val();
280+
that.viewOption();
281+
});
282+
}
283+
284+
}
285+
230286
render() {
231287
super.render();
232288

289+
// Model Creation - dynamically view options
290+
this.viewOption();
291+
233292
// Model Editor
234293
this.modelEditor = new ModelEditor(this, "model", "instanceEditor");
235294
}

0 commit comments

Comments
 (0)