【问题标题】:Why does the prediction of my model change between scaled and unscaled data when using standard scaler?使用标准缩放器时,为什么我的模型预测会在缩放数据和未缩放数据之间发生变化?
【发布时间】:2021-05-24 02:57:03
【问题描述】:

当我尝试使用标准缩放器缩放数据时,模型给出了错误的预测:

from sklearn.preprocessing import StandardScaler 
st=StandardScaler()
x_train=st.fit_transform(x_train)
x_test=st.transform(x_test)

arry = [51,1,0,140,261,0,186,1,0,2,0,2]
tes = np.asarray(arry)
se = tes.reshape(1,-1)
svc_load.predict(se)

输出:数组([0],dtype=int64)

但输入相同但没有缩放数据:

    arry = [51,1,0,140,261,0,186,1,0,2,0,2]
    tes = np.asarray(arry)
    se = tes.reshape(1,-1)
    svc_load.predict(se)

输出:数组([1],dtype=int64) 哪个是对的。 我是机器学习的新手。谁能帮我解决这个问题?

我正在使用 GaussianNB 分类器。

【问题讨论】:

  • 模型是如何训练的?在哪里扩展功能?两者的predict_proba(se) 是什么。事实上,你无法知道真正的答案是否是纯粹的幸运猜测。

标签: python


【解决方案1】:

规则:如果您使用缩放数据训练模型,请使用缩放数据进行测试。如果不是,请使用原始数据进行测试。使用pipelinefitpredict 让这更容易。

顺便说一下,您使用的高斯朴素贝叶斯模型不需要归一化,因为特征只是相互比较。

【讨论】:

    猜你喜欢
    • 2017-03-01
    • 2015-12-11
    • 2018-04-03
    • 1970-01-01
    • 2021-05-30
    • 1970-01-01
    • 2019-01-21
    • 2020-09-24
    • 1970-01-01
    相关资源
    最近更新 更多