@@ -199,6 +199,7 @@ define([
199199 sizeOfClusters, silhouetteScore, ari, nmi,
200200 clusteredIndex, featureData2, targetData2
201201} = this . state ;
202+ let needDisplay = false ;
202203
203204//====================================================================
204205// Classfication
@@ -207,7 +208,8 @@ define([
207208if ( confusion_matrix ) {
208209code = new com_String ( ) ;
209210code . 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 ;
211213codeCells . push ( code . toString ( ) ) ;
212214}
213215if ( report ) {
@@ -219,25 +221,29 @@ define([
219221if ( accuracy ) {
220222code = new com_String ( ) ;
221223code . 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 ;
223226codeCells . push ( code . toString ( ) ) ;
224227}
225228if ( precision ) {
226229code = new com_String ( ) ;
227230code . 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 ;
229233codeCells . push ( code . toString ( ) ) ;
230234}
231235if ( recall ) {
232236code = new com_String ( ) ;
233237code . 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 ;
235240codeCells . push ( code . toString ( ) ) ;
236241}
237242if ( f1_score ) {
238243code = new com_String ( ) ;
239244code . 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 ;
241247codeCells . push ( code . toString ( ) ) ;
242248}
243249// if (roc_curve) {
@@ -272,13 +278,15 @@ define([
272278if ( r_squared ) {
273279code = new com_String ( ) ;
274280code . 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 ;
276283codeCells . push ( code . toString ( ) ) ;
277284}
278285if ( mae ) {
279286code = new com_String ( ) ;
280287code . 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 ;
282290codeCells . push ( code . toString ( ) ) ;
283291}
284292if ( mape ) {
@@ -287,13 +295,15 @@ define([
287295code . appendLine ( 'def MAPE(y_test, y_pred):' ) ;
288296code . appendLine ( ' return np.mean(np.abs((y_test - pred) / y_test)) * 100' ) ;
289297code . appendLine ( ) ;
290- code . appendFormat ( 'MAPE({0}, {1})' , targetData , predictData ) ;
298+ code . appendFormat ( 'display(MAPE({0}, {1}))' , targetData , predictData ) ;
299+ needDisplay = true ;
291300codeCells . push ( code . toString ( ) ) ;
292301}
293302if ( rmse ) {
294303code = new com_String ( ) ;
295304code . 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 ;
297307codeCells . push ( code . toString ( ) ) ;
298308}
299309if ( scatter_plot ) {
@@ -333,6 +343,12 @@ define([
333343codeCells . push ( code . toString ( ) ) ;
334344}
335345}
346+ if ( needDisplay === true ) {
347+ codeCells = [
348+ "from IPython.display import display" ,
349+ ...codeCells
350+ ] ;
351+ }
336352// return as seperated cells
337353return codeCells ;
338354}