9951 explained code solutions for 126 technologies


python-scikit-learnSimple imputer example


import numpy as np
from sklearn import impute

im = impute.SimpleImputer(missing_values=np.nan, strategy='mean')

X = [[7, 2, 3], [4, np.nan, 6], [10, 5, 9]]
Xi = im.fit_transform(X)ctrl + c
from sklearn import

import module from scikit-learn

import numpy

import Numpy module

.SimpleImputer(

univariate imputer for completing missing values with simple strategies.

missing_values

which values to treat as missing

strategy

select strategy for filling missing values

.fit_transform(

trains and transforms given data with missing values filled


Usage example

import numpy as np
from sklearn import impute

im = impute.SimpleImputer(missing_values=np.nan, strategy='mean')

X = [[7, 2, 3], [4, np.nan, 6], [10, 5, 9]]
Xi = im.fit_transform(X)

print(Xi)
output
[[ 7.   2.   3. ]
 [ 4.   3.5  6. ]
 [10.   5.   9. ]]