DataConversionWarning: Data with input dtype int32, int64 were all converted to float64 by StandardS

机器学习过程中构建一颗决策树对数据进行标准化,使用下面两段代码

X_train = ss_X.fit_transform(X_train)
X_test = ss_X.transform(X_test)

运行之后出现下面警告

D:\Python\Anaconda3\lib\site-packages\sklearn\preprocessing\data.py:625: DataConversionWarning: Data with input dtype int32, int64 were all converted to float64 by StandardScaler.
  return self.partial_fit(X, y)
D:\Python\Anaconda3\lib\site-packages\sklearn\base.py:462: DataConversionWarning: Data with input dtype int32, int64 were all converted to float64 by StandardScaler.
  return self.fit(X, **fit_params).transform(X)

【解决方案】

将代码改成如下所示就可以

X_train = ss_X.fit_transform(X_train.astype(float))
X_test = ss_X.transform(X_test.astype(float))

再次运行就不会出现这样的警告了,希望对你有所帮助。

你可能感兴趣的:(机器学习)