Impute Missing Values and Normalize Columns
Problem statement
In each column of dataset, treat zero as missing and replace it with the mean of that column's nonzero values. Then z-score normalize the imputed column using its population mean and population standard deviation.
Function
imputeAndNormalize(dataset: double[][]) → double[][]Examples
Example 1
dataset = [[1,2,0],[0,1,1],[5,6,5]]return = [[-1.224744871391589,-0.4629100498862757,0.0],[0.0,-0.9258200997725514,-1.224744871391589],[1.224744871391589,1.3887301496588271,1.224744871391589]]Zeros become the nonzero column means before population z-score normalization.
Constraints
2 <= dataset.length <= 50.1 <= dataset[i].length <= 50and all rows have equal length.- Every column has at least two different nonzero values.
- Results use absolute tolerance
1e-5.