缩放数据仍然在python

时间:2017-05-19 16:12:05

标签: python-3.x machine-learning jupyter-notebook data-analysis bigdata

问题在于删除了我的数据中的所有列,在行上使用相等的值并应用max-min缩放的公式,即:(xx.min())/(x.max() - x。 min())我还有一个含NaN的专栏。

P.S。我删除了这些常量列,因为如果我保留它们然后进行缩放,x.max() - x.min()将为0,缩放后的所有这些列都将具有NaN值。

所以,我正在做的是以下内容:

我分别训练和测试数据集。一旦我在jupyter笔记本中导入它们,我创建一个函数来向我显示哪些列在行上具有完全相同的值。

def uniques(df):
    for e in df.columns:
        if len(pd.unique(df[e]))==1:
            yield e

然后我检查哪些是常数列:

col_test_=uniques(test_st1)
col_test=list(col_test_)
col_test

结果:

['uswrf_s1_3','uswrf_s1_6','uswrf_s1_10','uswrf_s1_11','uswrf_s1_13','uswrf_s1_5']

然后我得到这些列的所有索引:

 for i in list(col_test):
     idx_col=test_st1.columns.get_loc(i)
     print ("All values in column {} of the test data are the same".format(idx_col))

结果:

All values in column 220 of the test data are the same
All values in column 445 of the test data are the same
All values in column 745 of the test data are the same
All values in column 820 of the test data are the same
All values in column 970 of the test data are the same
All values in column 1120 of the test data are the same

然后我删除这些列,因为在应用最小 - 最大缩放后我不需要它们。

for j in col_test:
    test_st1=test_st1.drop(j,1)

基本上我对火车分区做同样的事情。 接下来,我将针对列车数据的最大最小缩放公式应用于训练和测试分区:

train_1= (train_st1-train_st1.min())/(train_st1.max()-train_st1.min())
test_1 = (test_st1-train_st1.min())/(train_st1.max()-train_st1.min())

在我删除具有相同值的列之后,我认为在规范化之后将不会有任何具有NaN的列。但是,当我检查是否有任何具有NaN值的列时,会发生以下情况:

a=uniques(test_1)
b=list(a)
b

结果:

['uswrf_s1_3']

检查哪一列是:

test_1.columns.get_loc('uswrf_s1_3')

结果:

1126

为什么在缩放后我得到一个带有NaN的列,记住我已经删除了行上的值完全相同的所有列?

0 个答案:

没有答案