如何在负值数据集中使用卡方检验

2024-09-30 00:36:34 发布

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

我不能完全解释这个标题。为了在我的数据集中使用卡方检验,我找到了最小的值,并将每个单元格加上该值。(例如,这里的数据范围是[-8,11],所以我给每个单元格加了+8,范围变成了[0,19])。你知道吗

for i in range(len(dataValues.index)):
    for j in range(len(dataValues.columns)):
        dataValues.iat[i, j] += 8

预处理后:

for i in range(len(dataValues.index)):
    for x in topFeatures:
        finalDataFrame.at[i, x] = dataValues.at[i, x] - 8

但这会导致性能问题。我正在考虑的另一个解决办法是使之正常化。我写了一个如下的函数:

def normalization(df):
    from sklearn import preprocessing

    x = df.values  # returns a numpy array
    min_max_scaler = preprocessing.MinMaxScaler()
    x_scaled = min_max_scaler.fit_transform(x)
    df = pd.DataFrame(x_scaled, columns=df.columns)

    return df

我的程序加速了很多,但这次我的精确度下降了。我用第一种方法所做的特征选择过程产生0.85精度的结果,这次我产生0.70精度。你知道吗

我想摆脱这种原始方法,但我也希望精度保持不变。我该怎么做?你知道吗

先谢谢你。你知道吗


Tags: columns数据indfforindexlen精度

热门问题