如何编写函数来记录组输入

时间:2018-07-20 19:34:33

标签: scala

我想编写一个函数,该函数将记录每个组的输入,然后显示其输入。例如,

组输入:

predictions = pd.DataFrame(predictions[1])
actual = pd.DataFrame(y_test)
test = pd.concat([actual.reset_index(drop=True), predictions], axis=1)
# Rename column Renew to 'actual' and '1' to 'predictions'
test.rename(columns={"Renew": "actual", 1: "predictions"}, inplace=True)

TP = np.repeat('NA', 101)
FN = np.repeat('NA', 101)
FP = np.repeat('NA', 101)
TN = np.repeat('NA', 101)
Sensitivity = np.repeat('NA', 101)
Specificity = np.repeat('NA', 101)
AUROC = 0

for i in range(100):
    test['temp'] = 0
    test[test['predictions'] > (i/100), "temp"] = 1
    TP[i+1] = [test[test["actual"]==1 and test["temp"]==1,]].shape[0]
    FN[i+1] = [test[test["actual"]==1 and test["temp"]==0,]].shape[0]
    FP[i+1] = [test[test["actual"]==0 and test["temp"]==1,]].shape[0]
    TN[i+1] = [test[test["actual"]==0 and test["temp"]==0,]].shape[0]
    Sensitivity[i+1] = TP[i+1] / (TP[i+1] + FN[i+1])
    Specificity[i+1] = TN[i+1] / (TN[i+1] + FP[i+1])
    if(i > 0):
            AUROC = AUROC+0.5*(Specificity[i+1] - Specificity[i])* 
(Sensitivity[i+1] + Sensitivity[i])

多少个小组:

groupOneInput = a, b, c

groupTwoInput = i, j, k

当前解决方案:

numOfGroups = 2

输出:

import scala.io.StdIn._

def x(numOfGroups: Int): String = {
  (
    if(numOfGroups <1) "Done"
    else {
      println("\nPlease enter your values:\n")
      val input = readLine
      input + x(numOfGroups-1)
    }
  )
}

所需的输出:

groupOne = a,b,c

groupTwo = i,j,k

谢谢

1 个答案:

答案 0 :(得分:0)

<?php 
require_once  SMARTY_DIR . 'Smarty.class.php';
 class Application extends Smarty 
 {
   public function __construct()
   {
  parent::Smarty();
  $this->template_dir = TEMPLATE_DIR;
  $this->compile_dir = COMPILE_DIR;
  $this->config_dir = CONFIG_DIR;
   }
}
?>

在Scala REPL中:

def x(numOfGroups: Int): Unit = {
     def y(numOfGroups:Int):String =
       if(numOfGroups <1) "Done"
        else { println("\nPlease enter your values:\n")             
               val input = readLine
               input + y(numOfGroups-1)
             }
    val t = y(numOfGroups).dropRight(4).mkString.replaceAll(",","").
      replaceAll(" ","").grouped(3).toList.map(x=>x.mkString(","))
    val x = List("groupOne","groupTwo").zipWithIndex
    for((i,j)<-x) println(i+" = "+t(j))
  }