@@ -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
202203let needDisplay = false ;
204+ let needMarkdown = false ;
203205
204206//====================================================================
205207// Classfication
@@ -208,8 +210,9 @@ define([
208210if ( confusion_matrix ) {
209211code = new com_String ( ) ;
210212code . appendLine ( "# Confusion Matrix" ) ;
213+ code . appendLine ( "display(Markdown('### Confusion Matrix'))" ) ;
211214code . appendFormat ( 'display(pd.crosstab({0}, {1}, margins=True))' , targetData , predictData ) ;
212- needDisplay = true ;
215+ needMarkdown = true ;
213216codeCells . push ( code . toString ( ) ) ;
214217}
215218if ( report ) {
@@ -221,29 +224,25 @@ define([
221224if ( accuracy ) {
222225code = new com_String ( ) ;
223226code . 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 ) ;
226228codeCells . push ( code . toString ( ) ) ;
227229}
228230if ( precision ) {
229231code = new com_String ( ) ;
230232code . 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 ) ;
233234codeCells . push ( code . toString ( ) ) ;
234235}
235236if ( recall ) {
236237code = new com_String ( ) ;
237238code . 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 ) ;
240240codeCells . push ( code . toString ( ) ) ;
241241}
242242if ( f1_score ) {
243243code = new com_String ( ) ;
244244code . 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 ) ;
247246codeCells . push ( code . toString ( ) ) ;
248247}
249248// if (roc_curve) {
@@ -278,15 +277,13 @@ define([
278277if ( r_squared ) {
279278code = new com_String ( ) ;
280279code . 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 ) ;
283281codeCells . push ( code . toString ( ) ) ;
284282}
285283if ( mae ) {
286284code = new com_String ( ) ;
287285code . 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 ) ;
290287codeCells . push ( code . toString ( ) ) ;
291288}
292289if ( mape ) {
@@ -295,24 +292,24 @@ define([
295292code . appendLine ( 'def MAPE(y_test, y_pred):' ) ;
296293code . appendLine ( ' return np.mean(np.abs((y_test - pred) / y_test)) * 100' ) ;
297294code . appendLine ( ) ;
298- code . appendFormat ( 'display(MAPE({0}, {1}))' , targetData , predictData ) ;
299- needDisplay = true ;
295+ code . appendFormat ( "print('MAPE: {}'.format(MAPE({0}, {1})))" , targetData , predictData ) ;
300296codeCells . push ( code . toString ( ) ) ;
301297}
302298if ( rmse ) {
303299code = new com_String ( ) ;
304300code . 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 ) ;
307302codeCells . push ( code . toString ( ) ) ;
308303}
309304if ( scatter_plot ) {
310305code = new com_String ( ) ;
311306code . appendLine ( '# Regression plot' ) ;
307+ code . appendLine ( "display(Markdown('### Regression plot'))" ) ;
312308code . appendFormatLine ( 'plt.scatter({0}, {1})' , targetData , predictData ) ;
313309code . appendFormatLine ( "plt.xlabel('{0}')" , targetData ) ;
314310code . appendFormatLine ( "plt.ylabel('{0}')" , predictData ) ;
315311code . append ( 'plt.show()' ) ;
312+ needMarkdown = true ;
316313codeCells . push ( code . toString ( ) ) ;
317314}
318315}
@@ -327,23 +324,28 @@ define([
327324if ( silhouetteScore ) {
328325code = new com_String ( ) ;
329326code . 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 ) ;
331328codeCells . push ( code . toString ( ) ) ;
332329}
333330if ( ari ) {
334331code = new com_String ( ) ;
335332code . 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 ) ;
337334codeCells . push ( code . toString ( ) ) ;
338335}
339336if ( nmi ) {
340337code = new com_String ( ) ;
341338code . 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 ) ;
343340codeCells . 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 ) {
347349codeCells = [
348350"from IPython.display import display" ,
349351 ...codeCells