警告 - 函数 make_blobs 已弃用 [英] warning - Function make_blobs is deprecated

查看:175
本文介绍了警告 - 函数 make_blobs 已弃用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我想绘制伪造数据集的散点图时,遇到了一个关于函数make_blobs的错误:

When I wanted to draw a scatter plot of forge datasets, I met an error about function make_blobs:

FutureWarning: Function make_blobs is deprecated; 
Please import make_blobs directly from scikit-learn warnings.warn(msg, category=FutureWarning). 

我试图通过编写 from sklearn.datasets import make_blobs 来解决这个问题,但是没有效果.我的代码如下:

I tried to solve this problem by writing from sklearn.datasets import make_blobs, but it's not effective. My code is below:

import mglearn
from sklearn import datasets
from sklearn.datasets import make_blobs
X, y = mglearn.datasets.make_forge()

推荐答案

首先,您不会收到错误(即您的程序没有停止),而只是一个警告 - 和关于未来的警告,就此而言.

To start with, you do not get an error (i.e. your program does not halt), but just a warning - and a warning about the future, for that matter.

已经澄清,在 scikit-learn v0.22.2 中,from sklearn.datasets import make_blobs 不会产生任何警告:

Having clarified that, in scikit-learn v0.22.2, from sklearn.datasets import make_blobs does not produce any warning:

import sklearn
sklearn.__version__
# 0.22.2.post1
from sklearn.datasets import make_blobs
# works OK, no warnings

即使在当前 (0.24.1) 版本的 scikit-learn 中,也没有迹象表明 make_blobs文档.

Even in the current (0.24.1) version of scikit-learn, there is no indication of make_blobs being (or soon to be) deprecated in the documentation.

根据此 Github 线程这个较旧的 SO 线程,这个问题似乎与 mglearn 包有关,而不是scikit 学习.确实,警告来自mglearnmake_blobs函数,它实际上是make_forge() 调用;来自其源代码:

According to this Github thread and this older SO thread, the issue seems to be related to the mglearn package, and not to scikit-learn. Indeed, the warning comes from the make_blobs function of mglearn, which is actually called by make_forge(); from its source code:

@deprecated("Please import make_blobs directly from scikit-learn")
def make_blobs(n_samples=100, n_features=2, centers=2, cluster_std=1.0,
               center_box=(-10.0, 10.0), shuffle=True, random_state=None):

无论如何,根据mglearn 上面提到的 Github 线程中的包创建者,你应该不要担心警告,更新 mglearn 会解决它:

In any case, and according to the mglearn package creator in the Github thread mentioned above, you should not worry about the warning, and updating mglearn will resolve it:

是的,没关系.不过,您可以更新 mglearn 以消除警告.

yes that's fine. You can update mglearn to get rid of the warning though.

这篇关于警告 - 函数 make_blobs 已弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆