# -*- coding: utf-8 -*-
"""
Created on Mon Sep 14 13:22:44 2020
@author: Dogukan
"""
import numpy as np
import random
from itertools import compress
def create_mar_single(df, missing_column, p_missing, depends_on, threshold, condition):
if condition == 'less':
np.random.seed(4)
t = (df[depends_on] <= 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]):
indices.append(random.choice(right_indices))
mar_column = [1 if i in indices else 0 for i in range(df.shape[0])]
elif condition == 'greater':
np.random.seed(5)
indices = []
t = (df[depends_on] > threshold)
right_indices = list(compress(r
模拟缺失数据2:MAR
最新推荐文章于 2022-05-01 21:58:12 发布