1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
import { Component, OnInit } from '@angular/core';
import Experiment, { NullValReplacer, NullValueOptions, ReplaceWith } from '../_data/Experiment';
import Model from '../_data/Model';
import Dataset, { ColumnInfo } from '../_data/Dataset';
import { ModelsService } from '../_services/models.service';
import Shared from '../Shared';
@Component({
selector: 'app-experiment',
templateUrl: './experiment.component.html',
styleUrls: ['./experiment.component.css']
})
export class ExperimentComponent implements OnInit {
experiment: Experiment = new Experiment();
selectedModel?: Model;
selectedDataset?: Dataset;
trainingResult: any; // any za sad, promeni kasnije
NullValueOptions = NullValueOptions;
ReplaceWith = ReplaceWith;
Object = Object;
selectedOutputColumnVal: string = '';
constructor(private models: ModelsService) { }
ngOnInit(): void {
}
updateDataset(dataset: Dataset) {
//console.log(dataset);
this.selectedDataset = dataset;
}
updateModel(model: Model) {
//console.log(model);
this.selectedModel = model;
}
getInputById(id: string): HTMLInputElement {
return document.getElementById(id) as HTMLInputElement;
}
arrayColumn = (arr: any[][], n: number) => [...this.dropEmptyString(new Set(arr.map(x => x[n])))];
dropEmptyString(set: Set<any>): Set<string> {
if (set.has(""))
set.delete("");
if (set.has(null))
set.delete(null);
if (set.has(undefined))
set.delete(undefined);
return set;
}
emptyFillTextInput(colName: string) {
(<HTMLInputElement>document.getElementById("fillText_" + colName)).value = "";
}
checkFillColRadio(colName: string) {
(<HTMLInputElement>document.getElementById("fillCol_" + colName)).checked = true;
}
replace(event: Event, column: ColumnInfo) {
let option = (<HTMLInputElement>event.target).value;
const input = (<HTMLInputElement>document.getElementById("fillText_" + column.columnName));
if (column.isNumber) {
switch (option) {
case ReplaceWith.Max:
input.value = "" + column.max;
break;
case ReplaceWith.Min:
input.value = "" + column.min;
break;
case ReplaceWith.Mean:
input.value = "" + column.mean;
break;
case ReplaceWith.Median:
input.value = "" + column.median;
break;
case ReplaceWith.None:
break;
}
} else {
input.value = option;
}
}
getNullValuesReplacersArray()/*: NullValReplacer[]*/ {
let array: NullValReplacer[] = [];
// TODO ispravi
/*if (this.datasetFile) {
if (this.newModel.nullValues == NullValueOptions.Replace) {
for (let i = 0; i < this.datasetFile[0].length; i++) {
let column = this.datasetFile[0][i];
if (this.calculateSumOfNullValuesInCol(column) > 0) { //ako kolona nema null vrednosti, ne dodajemo je u niz
if ((<HTMLInputElement>document.getElementById("delCol_" + column)).checked) {
array.push({
column: column,
option: NullValueOptions.DeleteColumns,
value: ""
});
}
else if ((<HTMLInputElement>document.getElementById("delRows_" + column)).checked) {
array.push({
column: column,
option: NullValueOptions.DeleteRows,
value: ""
});
}
else if (((<HTMLInputElement>document.getElementById("fillCol_" + column)).checked)) {
array.push({
column: column,
option: NullValueOptions.Replace,
value: (<HTMLInputElement>document.getElementById("fillText_" + column)).value
});
}
}
}
}
}
//console.log(array);
return array;*/
}
trainModel() {
this.trainingResult = undefined;
console.log('Training model...', this.selectedModel);
if (!this.selectedDataset) {
Shared.openDialog('Greška', 'Izvor podataka nije izabran!');
return;
}
// TODO proveri nullValues
if (!this.selectedModel) {
Shared.openDialog('Greška', 'Model nije izabran!');
return;
}
this.models.trainModel(this.selectedModel).subscribe((response: any) => {
console.log('Train model complete!', response);
this.trainingResult = response;
});
}
}
|