How to declare missing polynomial values

FabianDiFabianDi Member Posts: 1 Newbie
Hey guys, this is probably an easy one for someone who knows where to look :smile:

i'm currently working on trying out different methods for imputing missing data.
For this, i used an existing (complete) dataset and delete values using an R script.
However, when i do this to a polynomial attribute, the dataset still shows 0 missing values, and "?" has just been added to the range of the polynomial attribute. I tried the "Declare Missing Values" operator, but that didn't help (or i didn't use it correctly).

Here is a minimal example of the problem:
<?xml version="1.0" encoding="UTF-8"?><process version="9.8.000"><br>  <context><br>    <input/><br>    <output/><br>    <macros/><br>  </context><br>  <operator activated="true" class="process" compatibility="9.8.000" expanded="true" name="Process"><br>    <parameter key="logverbosity" value="init"/><br>    <parameter key="random_seed" value="2001"/><br>    <parameter key="send_mail" value="never"/><br>    <parameter key="notification_email" value=""/><br>    <parameter key="process_duration_for_mail" value="30"/><br>    <parameter key="encoding" value="SYSTEM"/><br>    <process expanded="true"><br>      <operator activated="true" class="retrieve" compatibility="9.8.000" expanded="true" height="68" name="Retrieve SouthGermanCredit" width="90" x="45" y="85"><br>        <parameter key="repository_entry" value="//Local Repository/data/SouthGermanCredit"/><br>      </operator><br>      <operator activated="true" class="r_scripting:execute_r" compatibility="9.6.000" expanded="true" height="103" name="Delete MCAR" width="90" x="313" y="85"><br>        <parameter key="script" value="&#10;library(utils)&#10;library(caret)&#10;&#10;&#10;# Erstellt eine Aufallmatrix (MCAR) mit den uebergebenen Parametern&#10;# Achtung: Mehr Ausfaelle als Werte erzeugt Endlosschleife&#10;&#10;mcarSingle &lt;- function(zeilen, ausfaelle){&#10;  x &lt;- sample(1:zeilen, ausfaelle)&#10;  ausfallvektor &lt;- seq(0, 0, length.out = zeilen)&#10;  for(i in 1:length(x)){&#10;    ausfallvektor[x[i]] &lt;- 1&#10;  }&#10;  return(ausfallvektor)&#10;}&#10;&#10;marSingle &lt;- function(daten, spalte, ausfaelle){&#10;  koeffizienten &lt;- sample(0:100, ncol(daten)-1,)&#10;  #Ausfallwahrscheinlichkeit fuer jede Zeile&#10;  ausfallwert &lt;- seq(0, 0, length.out=nrow(daten))&#10;  for(i in 1:nrow(daten)){&#10;    ausfallwert[i] = (koeffizienten%*%(as.matrix(daten)[i,-spalte]))[1,1]&#10;  }&#10;  &#10;  # Auf Summe = 1 normieren - evtl unnoetig&#10;  ausfallwert &lt;- ausfallwert/(sum(ausfallwert))&#10;  &#10;  # Ausfaelle aus abhaengig von Ausfallwerten samplen&#10;  ausfallvektor &lt;- seq(0, 0, length.out = nrow(daten))&#10;  for(i in 1:ausfaelle){&#10;    gezogen &lt;- sample(ausfallwert, 1, prob = ausfallwert) &#10;    indices &lt;- which(ausfallwert==gezogen, arr.ind=TRUE)&#10;    ausfallvektor[indices[1]] &lt;- 1&#10;    ausfallwert[indices[1]] &lt;- 0&#10;  }&#10;  &#10;  return(ausfallvektor)&#10;}&#10;&#10;mcar &lt;- function(zeilen, spalten, ausfaelle){&#10;  &#10;  matrix &lt;- diag(x = 0, nrow = zeilen, ncol = spalten)&#10;  for(i in 1:ausfaelle){&#10;    &#10;    # Um Dopplungen zu verhindern, der Umweg mit 'done'&#10;    done &lt;- FALSE&#10;    while(!done){&#10;      x &lt;- sample(1:zeilen, 1)&#10;      y &lt;- sample(1:spalten, 1)&#10;      &#10;      if(matrix[x,y] == 0){&#10;        matrix[x,y] &lt;- 1&#10;        done &lt;- TRUE&#10;      }&#10;    }&#10;  }&#10;  &#10;  return(matrix)&#10;}&#10;&#10;&#10;# Erstellt eine Aufallmatrix (MAR) mit den uebergebenen Parametern&#10;mar &lt;- function(daten, ausfaelle){&#10;  &#10;  spalten &lt;- ncol(daten) #21&#10;  zeilen &lt;- nrow(daten) #1000&#10;  vektor &lt;- matrix(0L, nrow = spalten, ncol = spalten-1)&#10;  &#10;  # Ausfallmodelle fuer alle Variablen generieren&#10;  for(i in 1:ncol(daten)){&#10;    vektor[i,] &lt;- sample(0:100, ncol(daten)-1, replace=TRUE)/100&#10;  }&#10;  &#10;  # Ausfallwerte fuer alle Eintraege im Datensatz erzeugen&#10;  ausfallwert &lt;- matrix(0L, nrow = zeilen, ncol = spalten)&#10;  for(i in 1:spalten){&#10;    for(j in 1:zeilen){&#10;      ausfallwert[j,i] = sum(vektor[i,]*(daten[j,-i]))&#10;    }&#10;  }&#10;  &#10;  # Auf Summe = 1 normieren - evtl unnoetig&#10;  ausfallwert &lt;- ausfallwert/(sum(ausfallwert))&#10;  &#10;  # Ausfaelle aus abhaengig von Ausfallwerten samplen&#10;  ausfallmatrix &lt;- matrix(0L, nrow = zeilen, ncol = spalten)&#10;  for(i in i:ausfaelle){&#10;    gezogen &lt;- sample(ausfallwert, 1, prob = ausfallwert) &#10;    indices &lt;- which(ausfallwert==gezogen, arr.ind=TRUE)&#10;    ausfallmatrix[indices[1,1], indices[1,2]] &lt;- 1&#10;    ausfallwert[indices[1,1], indices[1,2]] &lt;- 0&#10;  }&#10;  &#10;  return(ausfallmatrix)&#10;}&#10;&#10;&#10;# Ersetzt Daten zufaellig durch NA&#10;# Labelspalte wird nicht ignoriert, muss ggfs. vorher entfernt werden&#10;deletedatamcar &lt;- function(data, spalte, ausfaelle){&#10;  &#10;  mcarvector &lt;- mcarSingle(nrow(data), ausfaelle)&#10;  &#10;  # Das Ersetzen geht sicher in einer Zeile, ist fuer mich so aber verstaendlicher&#10;  for(i in 1:nrow(data)){&#10;    if(mcarvector[i] == 1){&#10;      data[i, spalte] &lt;- NA&#10;    }&#10;  }&#10;  &#10;  return(data)&#10;}&#10;&#10;deletedatamar &lt;- function(data, spalte, ausfaelle){&#10;  &#10;  marvector &lt;- marSingle(data, spalte, ausfaelle)&#10;  &#10;  # Das Ersetzen geht sicher in einer Zeile, ist fuer mich so aber verstaendlicher&#10;  for(i in 1:nrow(data)){&#10;    if(marvector[i] == 1){&#10;      data[i, spalte] &lt;- NA&#10;    }&#10;  }&#10;  &#10;  return(data)&#10;}&#10;&#10;&#10;rm_main = function(data)&#10;{&#10;    return(deletedatamcar(data, 3, 100))&#10;}&#10;"/><br>        <parameter key="use_default_R" value="true"/><br>        <parameter key="Rscript_executable" value="C:/R/Rscript.exe"/><br>        <parameter key="use_default_R_LIBS_paths" value="true"/><br>        <enumeration key="R_LIBS_paths"/><br>      </operator><br>      <connect from_op="Retrieve SouthGermanCredit" from_port="output" to_op="Delete MCAR" to_port="input 1"/><br>      <connect from_op="Delete MCAR" from_port="output 1" to_port="result 1"/><br>      <portSpacing port="source_input 1" spacing="0"/><br>      <portSpacing port="sink_result 1" spacing="0"/><br>      <portSpacing port="sink_result 2" spacing="0"/><br>    </process><br>  </operator><br></process><br><br>

I guess the dataset is not included in the above code, so this is the one i am using, the only relevant thing, is that the attribute "moral" is imported as polynomial type:
Sorry, can't post the Link.. It's the South German Credit (Update) Dataset from UCI.

If it helps, this is the problem i have:



The attribute "moral" has 0 missing values, but contains "?" in it's range, which should be the missing ones.

Happy for any suggestions

Answers

  • kaymankayman Member Posts: 662 Unicorn
    Declare missing values should do the trick, might be one of the settings you overlooked. Don't know them by hard but selecting nominal and adding the questionmark in the value field should be enough. 

    You could also replace the questionmark with nothing and have it followed by a trim to get the same result. 
Sign In or Register to comment.