@@ -199,6 +199,7 @@ define([
199
199
sizeOfClusters, silhouetteScore, ari, nmi,
200
200
clusteredIndex, featureData2, targetData2
201
201
} = this . state ;
202
+ let needDisplay = false ;
202
203
203
204
//====================================================================
204
205
// Classfication
@@ -207,7 +208,8 @@ define([
207
208
if ( confusion_matrix ) {
208
209
code = new com_String ( ) ;
209
210
code . appendLine ( "# Confusion Matrix" ) ;
210
- code . appendFormat ( 'pd.crosstab({0}, {1}, margins=True)' , targetData , predictData ) ;
211
+ code . appendFormat ( 'display(pd.crosstab({0}, {1}, margins=True))' , targetData , predictData ) ;
212
+ needDisplay = true ;
211
213
codeCells . push ( code . toString ( ) ) ;
212
214
}
213
215
if ( report ) {
@@ -219,25 +221,29 @@ define([
219
221
if ( accuracy ) {
220
222
code = new com_String ( ) ;
221
223
code . appendLine ( "# Accuracy" ) ;
222
- code . appendFormat ( 'metrics.accuracy_score({0}, {1})' , targetData , predictData ) ;
224
+ code . appendFormat ( 'display(metrics.accuracy_score({0}, {1}))' , targetData , predictData ) ;
225
+ needDisplay = true ;
223
226
codeCells . push ( code . toString ( ) ) ;
224
227
}
225
228
if ( precision ) {
226
229
code = new com_String ( ) ;
227
230
code . appendLine ( "# Precision" ) ;
228
- code . appendFormat ( "metrics.precision_score({0}, {1}, average='weighted')" , targetData , predictData ) ;
231
+ code . appendFormat ( "display(metrics.precision_score({0}, {1}, average='weighted'))" , targetData , predictData ) ;
232
+ needDisplay = true ;
229
233
codeCells . push ( code . toString ( ) ) ;
230
234
}
231
235
if ( recall ) {
232
236
code = new com_String ( ) ;
233
237
code . appendLine ( "# Recall" ) ;
234
- code . appendFormat ( "metrics.recall_score({0}, {1}, average='weighted')" , targetData , predictData ) ;
238
+ code . appendFormat ( "display(metrics.recall_score({0}, {1}, average='weighted'))" , targetData , predictData ) ;
239
+ needDisplay = true ;
235
240
codeCells . push ( code . toString ( ) ) ;
236
241
}
237
242
if ( f1_score ) {
238
243
code = new com_String ( ) ;
239
244
code . appendLine ( "# F1-score" ) ;
240
- code . appendFormat ( "metrics.f1_score({0}, {1}, average='weighted')" , targetData , predictData ) ;
245
+ code . appendFormat ( "display(metrics.f1_score({0}, {1}, average='weighted'))" , targetData , predictData ) ;
246
+ needDisplay = true ;
241
247
codeCells . push ( code . toString ( ) ) ;
242
248
}
243
249
// if (roc_curve) {
@@ -272,13 +278,15 @@ define([
272
278
if ( r_squared ) {
273
279
code = new com_String ( ) ;
274
280
code . appendLine ( "# R square" ) ;
275
- code . appendFormat ( 'metrics.r2_score({0}, {1})' , targetData , predictData ) ;
281
+ code . appendFormat ( 'display(metrics.r2_score({0}, {1}))' , targetData , predictData ) ;
282
+ needDisplay = true ;
276
283
codeCells . push ( code . toString ( ) ) ;
277
284
}
278
285
if ( mae ) {
279
286
code = new com_String ( ) ;
280
287
code . appendLine ( "# MAE(Mean Absolute Error)" ) ;
281
- code . appendFormat ( 'metrics.mean_absolute_error({0}, {1})' , targetData , predictData ) ;
288
+ code . appendFormat ( 'display(metrics.mean_absolute_error({0}, {1}))' , targetData , predictData ) ;
289
+ needDisplay = true ;
282
290
codeCells . push ( code . toString ( ) ) ;
283
291
}
284
292
if ( mape ) {
@@ -287,13 +295,15 @@ define([
287
295
code . appendLine ( 'def MAPE(y_test, y_pred):' ) ;
288
296
code . appendLine ( ' return np.mean(np.abs((y_test - pred) / y_test)) * 100' ) ;
289
297
code . appendLine ( ) ;
290
- code . appendFormat ( 'MAPE({0}, {1})' , targetData , predictData ) ;
298
+ code . appendFormat ( 'display(MAPE({0}, {1}))' , targetData , predictData ) ;
299
+ needDisplay = true ;
291
300
codeCells . push ( code . toString ( ) ) ;
292
301
}
293
302
if ( rmse ) {
294
303
code = new com_String ( ) ;
295
304
code . appendLine ( "# RMSE(Root Mean Squared Error)" ) ;
296
- code . appendFormat ( 'metrics.mean_squared_error({0}, {1})**0.5' , targetData , predictData ) ;
305
+ code . appendFormat ( 'display(metrics.mean_squared_error({0}, {1})**0.5)' , targetData , predictData ) ;
306
+ needDisplay = true ;
297
307
codeCells . push ( code . toString ( ) ) ;
298
308
}
299
309
if ( scatter_plot ) {
@@ -333,6 +343,12 @@ define([
333
343
codeCells . push ( code . toString ( ) ) ;
334
344
}
335
345
}
346
+ if ( needDisplay === true ) {
347
+ codeCells = [
348
+ "from IPython.display import display" ,
349
+ ...codeCells
350
+ ] ;
351
+ }
336
352
// return as seperated cells
337
353
return codeCells ;
338
354
}
0 commit comments