protected function map(Mapper $mapper): DataSet
    {
        $this->mapper = $mapper;
        $this->instances = $this->inputsMatrix = $this->outputsMatrix = [];

        foreach ($this->rawData as &$row) {
            //Split each row of the raw DataSet into inputs and outputs
            list($inputs, $outputs) = $this->mapper->map($row);
            //If the mapping was successfully made (the cleaners allowed the row to pass)
            if ($inputs && $outputs) {
                //Increment size
                $this->size++;
                //Save the inputs matrix
                $this->inputsMatrix[] = $inputs;
                $this->numberOfInputs = $this->numberOfInputs ?? count($inputs);
                //save the output matrix
                $this->outputsMatrix[] = $outputs;
                $this->numberOfOutputs = $this->numberOfOutputs ?? count($outputs);
            }

            foreach ($row as $key => $value) {
                //calculate the frequency at which each value occurs
                $this->frequency[$key][$value] = $this->frequency[$key][$value] ?? 0;
                $this->frequency[$key][$value]++;

                //calculate the rawAverage of each column of the raw DataSet, since cleaners might ignore a row
                $this->rawAverage[$key] = $this->rawAverage[$key] ?? 0;
                $this->rawAverage[$key] += floatval($value) / $this->rawSize;
            }

        }

        return $this;
    }