def r_c50(rdf: RDataFrame, target: str, predictors: List[str]) -> RListVector: """ Wrapper function around the C5.0 classifier. Note: The target column must be a factor vector. TODO: Training control and other parameters. """ predictor_slice = rdf.rx(r_c(*predictors)) target_slice = rdf.rx2(r_c(target)) return C50.C5_0(predictor_slice, target_slice)
def r_dataframe_column_to_factor_by_name(rdf: RDataFrame, name: str) -> RDataFrame: """ Transform the column with the given name into a factor vector. Note: This modifies the passed dataframe. """ for index, item in enumerate(r_dataframe_column_names(rdf)): if item == name: rdf[index] = RFactorVector(RFactorVector(rdf.rx2(name))) return rdf raise ValueError('Given name is not in R dataframe')