def imputeMethodMedain(result, originData, missData, missRate, missPattern, dataType='continuous'): imputationMethod = "median" try: imputedData = SimpleFill("median").fit_transform(missData) if dataType != 'continuous': mark = [ temp[0] for temp in pd.DataFrame(np.unique(missData)).dropna( axis=0).values ] imputedData = modifier(imputedData, mark) result = addResult(result, missRate, missPattern, imputationMethod, evaluate.RMSE(originData, imputedData), MAE(originData, imputedData), masked_mape_np(originData, imputedData)) except Exception as e: print(e) imputedData = 'none' result = addResult(result, missRate, missPattern, imputationMethod, np.inf, np.inf, np.inf) return result, imputedData
def imputeMethod2(result, originData, missData, missRate, missPattern): imputationMethod = "ycimpute KNN" try: imputedData = yKNN(k=int(math.sqrt(len(missData)))).complete(missData) result = addResult(result, missRate, missPattern, imputationMethod, evaluate.RMSE(originData, imputedData), MAE(originData, imputedData), masked_mape_np(originData, imputedData)) except Exception as e: print(e) result = addResult(result, missRate, missPattern, imputationMethod, np.inf, np.inf, np.inf) return result
def imputeMethodMR(result,originData,missData,missRate,missPattern,dataType='continuous'): imputationMethod = "RandomForest" try: imputer = predictive_imputer.PredictiveImputer(f_model='RandomForest') imputedData = imputer.fit(missData).transform(missData.copy()) if dataType!='continuous': mark = [temp[0] for temp in pd.DataFrame(np.unique(missData)).dropna(axis=0).values] imputedData = modifier(imputedData, mark) result = addResult(result, missRate, missPattern, imputationMethod, evaluate.RMSE(originData, imputedData), MAE(originData, imputedData), masked_mape_np(originData, imputedData)) except Exception as e: print(e) imputedData = 'none' result = addResult(result, missRate, missPattern, imputationMethod, np.inf, np.inf, np.inf) return result,imputedData
def imputeMethodFixed(result, originData, missData, missRate, missPattern, dataType='continuous'): """ 默认值插补,插补为0 :param result: :param originData: :param missData: :param missRate: :param missPattern: :param dataType: :return: """ imputationMethod = "Fixed" try: imputedData = fixedImpute(missData) if dataType != 'continuous': mark = [ temp[0] for temp in pd.DataFrame(np.unique(missData)).dropna( axis=0).values ] imputedData = modifier(imputedData, mark) result = addResult(result, missRate, missPattern, imputationMethod, evaluate.RMSE(originData, imputedData), MAE(originData, imputedData), masked_mape_np(originData, imputedData)) except Exception as e: print(e) imputedData = 'none' result = addResult(result, missRate, missPattern, imputationMethod, np.inf, np.inf, np.inf) return result, imputedData