【问题标题】:'sklearn.datasets' has no attribute 'samples_generator' [duplicate]“sklearn.datasets”没有属性“samples_generator”[重复]
【发布时间】:2021-07-02 10:32:19
【问题描述】:

我正在尝试使用 Google Colab 在Laplacian Eigenmaps for Dimensionality Reduction 上重现和理解本文档中包含的代码。但是,我收到以下错误:

AttributeError                            Traceback (most recent call last)
<ipython-input-8-c1726617ad98> in <module>()
      3 
      4 # Get the data and color map.
----> 5 S_curve, S_colors = datasets.samples_generator.make_s_curve(n_points, random_state=0)
      6 
      7 Axes3D

AttributeError: module 'sklearn.datasets' has no attribute 'samples_generator'

我已经确保我可以通过调用附加函数来实际显示the collection(瑞士卷)中的图,但它仍然不起作用。同样,Google Colab 建议的 this answer 也无济于事。

以下是相关代码:

from sklearn import datasets

# Define the number of points to consider. 
n_points = 3000

# Get the data and color map. 
S_curve, S_colors = datasets.samples_generator.make_s_curve(n_points, random_state=0)

【问题讨论】:

  • 欢迎来到 SO;请注意,通过将我们所有的代码按原样抛出问题,它确实起作用-请参阅如何创建minimal reproducible example。另外,问题与matplotlibgoogle-colaboratory 无关 - 请不要向无关标签发送垃圾邮件(已编辑)。

标签: python scikit-learn


【解决方案1】:

skicit-learn 的最新版本中没有名为 samples_generator 的模块。 所以就写

S_curve, S_colors = datasets.make_s_curve(n_points, random_state=0)

【讨论】:

    猜你喜欢
    • 2018-04-24
    • 1970-01-01
    • 2017-06-12
    • 2013-08-06
    • 1970-01-01
    • 1970-01-01
    • 2012-10-09
    • 2019-11-13
    • 2012-01-25
    相关资源
    最近更新 更多