# -*- coding: utf-8 -*-
"""
Created on Mon Sep 14 13:28:34 2020
@author: Dogukan
"""
import numpy as np
import random
from itertools import compress
def create_mnar_single(df, missing_column, p_missing, threshold, condition):
if condition == 'less':
np.random.seed(3)
t = (df[missing_column] <= threshold)
right_indices = list(compress(range(len(t)), t))
indices = random.choices(right_indices, k = round(p_missing*df.shape[0]))
while len(set(indices)) < round(p_missing * df.shape[0]):
add = random.choice(right_indices)
indices.append(add)
mar_column = [1 if i in indices else 0 for i in range(df.shape[0])]
elif condition == 'greater':
np.random.seed(7)
t = (df[missing_column] > threshold)
right_indices = list(compress(range(len(t)), t))
模拟缺失数据3:MNAR
最新推荐文章于 2022-12-14 14:27:49 发布