Skip to content

Commit 5e2bda3

Browse files
committed
Merge branch 'develop' into develop-hw
2 parents 7890002 + 6c49429 commit 5e2bda3

18 files changed

+189
-122
lines changed
Lines changed: 8 additions & 0 deletions
Loading

src/class/learning/Classification.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import InputPopup from './InputPopup';
22

3-
export const classes = [
4-
'ai_learning_speech'
5-
];
3+
export const classes = ['ai_learning_speech'];
64

75
class Classification {
86
#type = null;
@@ -20,9 +18,11 @@ class Classification {
2018

2119
getResult(index) {
2220
const result = this.#popup?.result || [];
23-
const defaultResult = {probability: 0, className: ''};
24-
if(index !== undefined && index > -1) {
25-
return result.find(({className}) => className === this.#labels[index]) || defaultResult;
21+
const defaultResult = { probability: 0, className: '' };
22+
if (index !== undefined && index > -1) {
23+
return (
24+
result.find(({ className }) => className === this.#labels[index]) || defaultResult
25+
);
2626
}
2727
return result[0] || defaultResult;
2828
}
@@ -36,10 +36,10 @@ class Classification {
3636

3737
openInputPopup() {
3838
this.#popup = new InputPopup({
39-
url: this.#url,
39+
url: this.#url,
4040
labels: this.#labels,
4141
type: this.#type,
42-
recordTime: this.#recordTime
42+
recordTime: this.#recordTime,
4343
});
4444
this.#popup.open();
4545
}

src/class/learning/Cluster.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { kmpp } from 'skmeans/kinit';
22
// import { kmpp } from 'skmeans/dist/node/kinit';
33
import floor from 'lodash/floor';
4+
import _toNumber from 'lodash/toNumber';
5+
import _isNaN from 'lodash/isNaN';
46
import LearningView from './LearningView';
57
import Chart from './Chart';
68
import DataTable from '../DataTable';
@@ -153,14 +155,17 @@ class Cluster {
153155
this.#trainCallback(1);
154156
this.#isTrained = false;
155157
const { data, select } = this.#table;
158+
const filtered = data.filter(
159+
(row) => !select.flat().some((selected) => _isNaN(_toNumber(row[selected])))
160+
);
156161
const [attr] = select;
157162

158163
const { centroids, indexes } = kmeans(
159-
data.map((row) => attr.map((i) => parseFloat(row[i]) || 0)),
164+
filtered.map((row) => attr.map((i) => parseFloat(row[i]) || 0)),
160165
this.#trainParam
161166
);
162167
this.#result = {
163-
graphData: convertGraphData(data, centroids, indexes, attr),
168+
graphData: convertGraphData(filtered, centroids, indexes, attr),
164169
centroids,
165170
};
166171
this.#isTrained = true;

src/class/learning/DecisionTree.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import _floor from 'lodash/floor';
33
import _max from 'lodash/max';
44
import _sum from 'lodash/sum';
55
import _mean from 'lodash/mean';
6+
import _toNumber from 'lodash/toNumber';
7+
import _isNaN from 'lodash/isNaN';
68
import LearningBase from './LearningBase';
79
import { DecisionTreeClassifier as DTClassifier } from 'ml-cart';
810
import Utils from './Utils';
@@ -24,7 +26,7 @@ class DecisionTree extends LearningBase {
2426
type = 'decisiontree';
2527

2628
init({ name, url, result, table, trainParam }) {
27-
this.name = name;
29+
this.name = name;
2830
this.trainParam = trainParam;
2931
this.result = result;
3032
this.table = table;
@@ -157,8 +159,10 @@ function getData(testRate = 0.2, data) {
157159
const tempMapCount = {};
158160
const { select = [[0], [1]], data: table, fields } = data;
159161
const [attr, predict] = select;
160-
161-
const dataArray = table
162+
const filtered = table.filter(
163+
(row) => !select[0].some((selected) => _isNaN(_toNumber(row[selected])))
164+
);
165+
const dataArray = filtered
162166
.map((row) => ({
163167
x: attr.map((i) => Utils.stringToNumber(i, row[i], tempMap, tempMapCount)),
164168
y: Utils.stringToNumber(predict[0], row[predict[0]], tempMap, tempMapCount),
@@ -176,7 +180,7 @@ function getData(testRate = 0.2, data) {
176180
select,
177181
fields,
178182
valueMap: { ...tempMap[predict[0]] },
179-
numClass: tempMapCount[predict[0]],
183+
numClass: tempMapCount[predict[0]] || 1,
180184
};
181185
}
182186

src/class/learning/LearningView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const STATUS = {
1515

1616
export default class LearningView {
1717
constructor({ name = 'model name', status = STATUS.NO_MODEL, value = 0} = {}) {
18-
this.id = Entry.generateHash();
18+
this.id = Entry.generateHash();
1919
this.visible = true;
2020
this.value = value;
2121
const fontFamily = EntryStatic.fontFamily || 'NanumGothic';

src/class/learning/LogisticRegression.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import _floor from 'lodash/floor';
33
import _max from 'lodash/max';
44
import _sum from 'lodash/sum';
55
import _mean from 'lodash/mean';
6+
import _toNumber from 'lodash/toNumber';
7+
import _isNaN from 'lodash/isNaN';
68
import LearningBase from './LearningBase';
79
import Utils from './Utils';
810

@@ -182,8 +184,10 @@ function getData(validationRate, testRate, data, trainParam) {
182184
const tempMapCount = {};
183185
const { select = [[0], [1]], data: table, fields } = data;
184186
const [attr, predict] = select;
185-
186-
const dataArray = table
187+
const filtered = table.filter(
188+
(row) => !select[0].some((selected) => _isNaN(_toNumber(row[selected])))
189+
);
190+
const dataArray = filtered
187191
.map((row) => ({
188192
x: attr.map((i) => Utils.stringToNumber(i, row[i], tempMap, tempMapCount)),
189193
y: Utils.stringToNumber(predict[0], row[predict[0]], tempMap, tempMapCount),

0 commit comments

Comments
 (0)