original_docstring: 
      This code does the cardiac disease classification (5-classes)
      
docstring: This code does the cardiac disease classification (5-classes)
docstring_tokens: This code does the cardiac disease classification ( 5 - classes )
code: def CardiacDiagnosisModelTester(clf, final_test_path, name, scaler, save_dir='./', label_available=False, prediction_csv=None):
      """
      This code does the cardiac disease classification (5-classes)
      """
      class_names = [NOR, MINF, DCM, HCM, RV]
      df = load_dataframe(final_test_path)
      features = list(df.columns[np.r_[START_COL:END_COL]])
      X_df = df[features]
      # print (features)
      X_scaled = scaler.transform(X_df)  
      y_pred = clf.predict(X_scaled)
      print ("Writing predictions to file", name)
      target = open(save_dir+'/'+ name+'predictions_{}.txt'.format(time.strftime("%Y%m%d_%H%M%S")), 'w')
      classes = {NOR: 0,MINF:0,DCM:0,HCM:0,RV:0}
      for pid, pred in zip(df['Name'], y_pred):
          classes[class_names[pred]] +=1
          line = '{} {}'.format(pid, class_names[pred])
          target.write(line)
          target.write("\n")
      target.close()
      print (classes)
      if label_available:
          y_true,_ = encode_target(df, 'GROUP', heart_disease_label_map)
          accuracy = accuracy_score(y_true['GROUP'], y_pred)
          print("Accuracy: %.2f%%" % (accuracy * 100.0))
      else:
          if prediction_csv:
              df = load_dataframe(test_on_prediction)
              df['GROUP'] = [class_names[pred] for pred in y_pred]
              df.to_csv(prediction_csv,  index=False)
code_tokens: def CardiacDiagnosisModelTester ( clf , final_test_path , name , scaler , save_dir = './' , label_available = False , prediction_csv = None ) : class_names = [ NOR , MINF , DCM , HCM , RV ] df = load_dataframe ( final_test_path ) features = list ( df . columns [ np . r_ [ START_COL : END_COL ] ] ) X_df = df [ features ] X_scaled = scaler . transform ( X_df ) y_pred = clf . predict ( X_scaled ) print ( "Writing predictions to file" , name ) target = open ( save_dir + '/' + name + 'predictions_{}.txt' . format ( time . strftime ( "%Y%m%d_%H%M%S" ) ) , 'w' ) classes = { NOR : 0 , MINF : 0 , DCM : 0 , HCM : 0 , RV : 0 } for pid , pred in zip ( df [ 'Name' ] , y_pred ) : classes [ class_names [ pred ] ] += 1 line = '{} {}' . format ( pid , class_names [ pred ] ) target . write ( line ) target . write ( "\n" ) target . close ( ) print ( classes ) if label_available : y_true , _ = encode_target ( df , 'GROUP' , heart_disease_label_map ) accuracy = accuracy_score ( y_true [ 'GROUP' ] , y_pred ) print ( "Accuracy: %.2f%%" % ( accuracy * 100.0 ) ) else : if prediction_csv : df = load_dataframe ( test_on_prediction ) df [ 'GROUP' ] = [ class_names [ pred ] for pred in y_pred ] df . to_csv ( prediction_csv , index = False )
short_docstring: This code does the cardiac disease classification (5-classes)
short_docstring_tokens: This code does the cardiac disease classification ( 5 - classes )
comment: """
      This code does the cardiac disease classification (5-classes)
      """$SEP$# print (features)