【问题标题】:Prediction techniques using scikit-kearn (Polynomial regression)使用 scikit-learn 的预测技术(多项式回归)
【发布时间】:2019-02-27 23:31:43
【问题描述】:

我尝试使用sklearn 测试第一个示例:

from sklearn.preprocessing import PolynomialFeatures
from sklearn import linear_model

X = [[0.44, 0.68], [0.99, 0.23]]
vector = [109.85, 155.72]
predict= [0.49, 0.18]

poly = PolynomialFeatures(degree=2)
X_ = poly.fit_transform(X)
predict_ = poly.fit_transform(predict)

clf = linear_model.LinearRegression()
clf.fit(X_, vector)
print clf.predict(predict_)   

但我有这些错误:

/usr/lib/python2.7/dist-packages/scipy/sparse/csgraph/__init__.py:148:
 RuntimeWarning: numpy.dtype size changed, may indicate binary
 incompatibility
  from ._shortest_path import shortest_path, floyd_warshall, dijkstra,\
  /usr/lib/python2.7/dist-packages/scipy/sparse/csgraph/_validation.py:5:
  RuntimeWarning: numpy.dtype size changed, may indicate binary
  incompatibility
  File "hi.py", line 1, in <module>
  from sklearn.preprocessing import PolynomialFeatures
  ImportError: cannot import name PolynomialFeatures
   python -V --> 2.7.6 

请问,我该如何处理这些错误? 最好的。

【问题讨论】:

标签: python scikit-learn


【解决方案1】:

您可以检查您的sklearn 版本,使用:

import sklearn
print('Version {}.'.format(sklearn.__version__))

对我来说它显示:

Version 0.17.1.

然后检查(在PolynomialFeatures 的帮助下)哪个版本提供PolynomialFeatures 并进行更新。如果您的版本是 0.14.1 或更低,您将收到此错误。查看此页面以获取有关如何升级的更多详细信息:Not able to import PolynomialFeatures, make_pipeline in Scikit-learn(官方:http://scikit-learn.org/stable/install.html)

【讨论】:

  • root@graphene-119:~# sudo python Python 2.7.6(默认,2017 年 11 月 23 日,15:49:48)[GCC 4.8.4] 在 linux2 上键入“帮助”,“版权”、“学分”或“许可证”以获取更多信息。 >>> import sklearn Traceback(最近一次调用最后一次):文件“”,第 1 行,在 中 ImportError:没有名为 sklearn 的模块 >>> print('Version {}.'.format(sklearn.__version__ )) 回溯(最近一次调用最后一次):文件“”,第 1 行,在 NameError: name 'sklearn' is not defined >>>
  • 好的,看来你甚至没有安装sklearn,因此出现错误ImportError: No module named sklearn。只需访问 scikit-learn 网站并阅读有关如何安装它的更多信息。
  • sklearn 和 tensorflow 是不同的库。默认情况下,安装一个不会安装另一个。您将需要安装两者。顺便说一句,我仍然很困惑为什么您在问题的第一句话中写道“使用 tensorflow:”。您根本没有在代码中使用tensorflow。这只是sklearn。
  • 张量流有多项式回归吗?
  • 简单的 Google 搜索关键字使用 tensorflow 进行多项式回归将为您提供问题的答案。顺便说一句,您的问题的答案是“是”。
猜你喜欢
  • 2020-10-10
  • 2020-06-26
  • 2018-01-14
  • 2018-02-16
  • 2013-12-26
  • 2016-12-08
  • 2017-01-12
  • 2022-11-19
  • 2014-10-09
相关资源
最近更新 更多