Skip to content

Commit 9d48a52

Browse files
author
minjk-bl
committed
Edit evaluation display codes
1 parent 5844de4 commit 9d48a52

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

visualpython/js/m_ml/evaluation.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ define([
199199
sizeOfClusters, silhouetteScore, ari, nmi,
200200
clusteredIndex, featureData2, targetData2
201201
} = this.state;
202+
// add import code for display and Markdown
202203
let needDisplay = false;
204+
let needMarkdown = false;
203205

204206
//====================================================================
205207
// Classfication
@@ -208,8 +210,9 @@ define([
208210
if (confusion_matrix) {
209211
code = new com_String();
210212
code.appendLine("# Confusion Matrix");
213+
code.appendLine("display(Markdown('### Confusion Matrix'))");
211214
code.appendFormat('display(pd.crosstab({0}, {1}, margins=True))', targetData, predictData);
212-
needDisplay = true;
215+
needMarkdown = true;
213216
codeCells.push(code.toString());
214217
}
215218
if (report) {
@@ -221,29 +224,25 @@ define([
221224
if (accuracy) {
222225
code = new com_String();
223226
code.appendLine("# Accuracy");
224-
code.appendFormat('display(metrics.accuracy_score({0}, {1}))', targetData, predictData);
225-
needDisplay = true;
227+
code.appendFormat("print('Accuracy: {}'.format(metrics.accuracy_score({0}, {1})))", targetData, predictData);
226228
codeCells.push(code.toString());
227229
}
228230
if (precision) {
229231
code = new com_String();
230232
code.appendLine("# Precision");
231-
code.appendFormat("display(metrics.precision_score({0}, {1}, average='weighted'))", targetData, predictData);
232-
needDisplay = true;
233+
code.appendFormat("print('Precision: {}'.format(metrics.precision_score({0}, {1}, average='weighted')))", targetData, predictData);
233234
codeCells.push(code.toString());
234235
}
235236
if (recall) {
236237
code = new com_String();
237238
code.appendLine("# Recall");
238-
code.appendFormat("display(metrics.recall_score({0}, {1}, average='weighted'))", targetData, predictData);
239-
needDisplay = true;
239+
code.appendFormat("print('Recall: {}'.format(metrics.recall_score({0}, {1}, average='weighted')))", targetData, predictData);
240240
codeCells.push(code.toString());
241241
}
242242
if (f1_score) {
243243
code = new com_String();
244244
code.appendLine("# F1-score");
245-
code.appendFormat("display(metrics.f1_score({0}, {1}, average='weighted'))", targetData, predictData);
246-
needDisplay = true;
245+
code.appendFormat("print('F1-score: {}'.format(metrics.f1_score({0}, {1}, average='weighted')))", targetData, predictData);
247246
codeCells.push(code.toString());
248247
}
249248
// if (roc_curve) {
@@ -278,15 +277,13 @@ define([
278277
if (r_squared) {
279278
code = new com_String();
280279
code.appendLine("# R square");
281-
code.appendFormat('display(metrics.r2_score({0}, {1}))', targetData, predictData);
282-
needDisplay = true;
280+
code.appendFormat("print('R square: {}'.format(metrics.r2_score({0}, {1})))", targetData, predictData);
283281
codeCells.push(code.toString());
284282
}
285283
if (mae) {
286284
code = new com_String();
287285
code.appendLine("# MAE(Mean Absolute Error)");
288-
code.appendFormat('display(metrics.mean_absolute_error({0}, {1}))', targetData, predictData);
289-
needDisplay = true;
286+
code.appendFormat("print('MAE: {}'.format(metrics.mean_absolute_error({0}, {1})))", targetData, predictData);
290287
codeCells.push(code.toString());
291288
}
292289
if (mape) {
@@ -295,24 +292,24 @@ define([
295292
code.appendLine('def MAPE(y_test, y_pred):');
296293
code.appendLine(' return np.mean(np.abs((y_test - pred) / y_test)) * 100');
297294
code.appendLine();
298-
code.appendFormat('display(MAPE({0}, {1}))', targetData, predictData);
299-
needDisplay = true;
295+
code.appendFormat("print('MAPE: {}'.format(MAPE({0}, {1})))", targetData, predictData);
300296
codeCells.push(code.toString());
301297
}
302298
if (rmse) {
303299
code = new com_String();
304300
code.appendLine("# RMSE(Root Mean Squared Error)");
305-
code.appendFormat('display(metrics.mean_squared_error({0}, {1})**0.5)', targetData, predictData);
306-
needDisplay = true;
301+
code.appendFormat("print('RMSE: {}'.format(metrics.mean_squared_error({0}, {1})**0.5))", targetData, predictData);
307302
codeCells.push(code.toString());
308303
}
309304
if (scatter_plot) {
310305
code = new com_String();
311306
code.appendLine('# Regression plot');
307+
code.appendLine("display(Markdown('### Regression plot'))");
312308
code.appendFormatLine('plt.scatter({0}, {1})', targetData, predictData);
313309
code.appendFormatLine("plt.xlabel('{0}')", targetData);
314310
code.appendFormatLine("plt.ylabel('{0}')", predictData);
315311
code.append('plt.show()');
312+
needMarkdown = true;
316313
codeCells.push(code.toString());
317314
}
318315
}
@@ -327,23 +324,28 @@ define([
327324
if (silhouetteScore) {
328325
code = new com_String();
329326
code.appendLine("# Silhouette score");
330-
code.appendFormat("print(f'Silhouette score: {metrics.cluster.silhouette_score({0}, {1})}')", featureData2, clusteredIndex);
327+
code.appendFormat("print('Silhouette score: {}'.format(metrics.cluster.silhouette_score({0}, {1})))", featureData2, clusteredIndex);
331328
codeCells.push(code.toString());
332329
}
333330
if (ari) {
334331
code = new com_String();
335332
code.appendLine("# ARI(Adjusted Rand score)");
336-
code.appendFormat("print(f'ARI: {metrics.cluster.adjusted_rand_score({0}, {1})}')", targetData2, clusteredIndex);
333+
code.appendFormat("print('ARI: {}'.format(metrics.cluster.adjusted_rand_score({0}, {1})))", targetData2, clusteredIndex);
337334
codeCells.push(code.toString());
338335
}
339336
if (nmi) {
340337
code = new com_String();
341338
code.appendLine("# NMI(Normalized Mutual Info Score)");
342-
code.appendFormat("print(f'NM: {metrics.cluster.normalized_mutual_info_score({0}, {1})}')", targetData2, clusteredIndex);
339+
code.appendFormat("print('NM: {}'.format(metrics.cluster.normalized_mutual_info_score({0}, {1})))", targetData2, clusteredIndex);
343340
codeCells.push(code.toString());
344341
}
345342
}
346-
if (needDisplay === true) {
343+
if (needMarkdown === true) {
344+
codeCells = [
345+
"from IPython.display import display, Markdown",
346+
...codeCells
347+
];
348+
} else if (needDisplay === true) {
347349
codeCells = [
348350
"from IPython.display import display",
349351
...codeCells

0 commit comments

Comments
 (0)