python fit训练数据_python – 缩放数据时,为什么训练数据集使用’fit’和’transform’,但测试数据集只使用’transform’?...

缩放数据时,为什么训练数据集使用’fit’和’transform’,但测试数据集只使用’transform’?

SAMPLE_COUNT = 5000

TEST_COUNT = 20000

seed(0)

sample = list()

test_sample = list()

for index, line in enumerate(open('covtype.data','rb')):

if index < SAMPLE_COUNT:

sample.append(line)

else:

r = randint(0,index)

if r < SAMPLE_COUNT:

sample[r] = line

else:

k = randint(0,index)

if k < TEST_COUNT:

if len(test_sample) < TEST_COUNT:

test_sample.append(line)

else:

test_sample[k] = line

from sklearn.preprocessing import StandardScaler

for n, line in enumerate(sample):

sample[n] = map(float, line.strip().split(','))

y = np.array(sample)[:,-1]

scaling = StandardScaler()

X = scaling.fit_transform(np.array(sample)[:,:-1]) ##here use fit and transform

for n,line in enumerate(test_sample):

test_sample[n] = map(float,line.strip().split(','))

yt = np.array(test_sample)[:,-1]

Xt = scaling.transform(np.array(test_sample)[:,:-1])##why here only use transform

正如注释所说,为什么Xt只使用变换而不适合?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值