定义Pareto边界的DataFrame多目标排序

2024-03-29 07:01:56 发布

您现在位置:Python中文网/ 问答频道 /正文

熊猫有没有内置多目标排序算法?你知道吗

我找到了this,这是一个NSGA-II算法(这正是我想要的),但它需要将目标函数作为单独的文件传入。在理想的情况下,我会对所有数据使用一个DataFrame,在指定目标函数列(和其他必需的参数)的同时对其调用一个类似multi_of_sort的方法,并返回另一个具有Pareto最优值的DataFrame。你知道吗

这似乎对熊猫来说是微不足道的,但我可能错了。你知道吗


Tags: 文件数据函数算法目标dataframe参数排序
1条回答
网友
1楼 · 发布于 2024-03-29 07:01:56

事实证明。。。上面引用的pareto处理数据帧输入。你知道吗

import pareto
import pandas as pd

# load the data
df = pd.read_csv('data.csv')

# define the objective function column indices
# optional. default is ALL columns
of_cols = [4, 5]

# define the convergence tolerance for the OF's
# optional. default is 1e-9
eps_tols = [1, 2]

# sort
nondominated = pareto.eps_sort([list(df.itertuples(False))], of_cols, eps_tols)

# convert multi-dimension array to DataFrame
df_pareto = pd.DataFrame.from_records(nondominated, columns=list(df.columns.values))

相关问题 更多 >