- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试在管道内实现 imblearn 的 SMOTE。我的数据集是存储在 Pandas 数据框中的文本数据。请看下面的代码片段
text_clf =Pipeline([('vect', TfidfVectorizer()),('scale', StandardScaler(with_mean=False)),('smt', SMOTE(random_state=5)),('clf', LinearSVC(class_weight='balanced'))])
在此之后,我正在使用 GridsearchCV。
grid = GridSearchCV(text_clf, parameters, cv=4, n_jobs=-1, scoring = 'accuracy')
其中的参数只不过是主要针对 TfidfVectorizer() 的调整参数。我收到以下错误。
All intermediate steps should be transformers and implement fit and transform. 'SMOTE
发布这个错误,我已经将代码更改为如下。
vect = TfidfVectorizer(use_idf=True,smooth_idf = True, max_df = 0.25, sublinear_tf = True, ngram_range=(1,2))
X = vect.fit_transform(X).todense()
Y = vect.fit_transform(Y).todense()
X_Train,X_Test,Y_Train,y_test = train_test_split(X,Y, random_state=0, test_size=0.33, shuffle=True)
text_clf =make_pipeline([('smt', SMOTE(random_state=5)),('scale', StandardScaler(with_mean=False)),('clf', LinearSVC(class_weight='balanced'))])
grid = GridSearchCV(text_clf, parameters, cv=4, n_jobs=-1, scoring = 'accuracy')
parameters
只是调整 SVC
分类器中的 C
。这次我收到以下错误:
Last step of Pipeline should implement fit.SMOTE(....) doesn't
这是怎么回事?有人可以帮忙吗?
最佳答案
imblearn.SMOTE
没有transform
方法。文档是 here .
但是管道中除了最后一步之外的所有步骤都应该有它,以及 fit
。
要将 SMOTE 与 sklearn 管道一起使用,您应该在 transform
方法中实现一个调用 SMOTE.fit_sample()
的自定义转换器。
另一个更简单的选择是使用 ibmlearn 管道:
from imblearn.over_sampling import SMOTE
from imblearn.pipeline import Pipeline as imbPipeline
# This doesn't work with sklearn.pipeline.Pipeline because
# SMOTE doesn't have a .tranform() method.
# (It has .fit_sample() or .sample().)
pipe = imbPipeline([
...
('oversample', SMOTE(random_state=5)),
('clf', LinearSVC(class_weight='balanced'))
])
关于python imblearn make_pipeline 类型错误 : Last step of Pipeline should implement fit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53114668/
我有一个系统,我需要在其中显示记录列表,这样我们可以使用三个选项 上周 上个月 去年 我的表结构有一个名为 createdate 的字段,它是 BIGINT 类型并保存从 PHP 的 time() 函
假设,我对某些功能使用哪一个并不重要,是否使用它会在性能方面产生任何差异 $('div:last'); 或 $('div').last(); 谢谢! 最佳答案 last() 在大型 DOM 集上明显比
有人可以解释 .last() 和 :last 之间的区别吗?我似乎找不到明确的解释。 为什么 $('td.cellsOfSpecificClass:last', '.table tr') 返回每个 t
我想用 li:last 做点什么: var p = $("li:last"); 我需要它的位置:position.left 通过该位置,我可以对齐一些元素。问题是,在某些情况下,最后一个 li 被 e
请看这张图片: 谁能解释一下其中的区别吗? 编辑 让我指出什么让我困惑。请注意: $row.is('tr.items:last') === false $row[0].id === $('tr.ite
我注意到 $( 'filter:last' ) 与 jQuery 中的 $( 'filter:last-child' ) 不同。 我尝试了 jQuery 文档,但很难理解 :last 的额外用途以及它
我正在尝试使用 CSS 选择最后一个 col-xs-12 div 中包含的最后一个元素。关键是元素是动态的,所以它可以是 h2 或 h3 等。
当我使用 :last-child 定位 div 时,它不起作用。使用 :first-child 没关系。 :last-of-type 也可以。有任何想法吗?谢谢。 HTML Lorem
HTML: ... ... ... ... CSS: .plan-box:last-of-type { ... } 在上面的 CSS 代码中,如果我在
我想知道 .filter(':last') 和 .last() 之间是否有任何区别? 对我来说,他们似乎也在做同样的事情,但我是 jQuery 的新手。如果结果没有差异,推荐使用哪一种还是只是个人喜好
std::adjacent_find searches the range [first, last) for two consecutive identical elements. Return v
这个问题在这里已经有了答案: How can I select the last element with a specific class, not last child inside of pa
目标 创建一个辅助列,将单元格的值从 Last, First 转换至First Last 下面的公式工作正常。 A1包含 Last, First下面的公式转换为所需的输出。 A2 = MID(A1,
我需要获取歌曲的发行日期。 在 last.fm API 中,如文档中所述,足以向服务器发出 HTTP 请求,它将使用包含字段“”的 XML(或 JSON)进行回复(如示例响应中所示在网站上)。 问题是
类似于 .Last.value有什么办法可以访问上次通话吗?低于预期的潜在结果.Last.call . sum(1, 2) # [1] 3 str(.Last.call) # language su
在 Perl 中调用 last 而不是在 C 中调用 break 的历史原因是什么? Perl 的设计受到 C 的影响(此外还有 awk、sed 和 sh - 请参阅下面的手册页),因此不采用熟悉的
我正在尝试交换字符串中的两个单词。我目前有一个 txt 文件,其中有一列用户格式为 last.first。我如何将它交换为 first.last? 最佳答案 -split 字符串并连接: $Last,
我有以下 html 代码: Text1 Text2 Text3 使用: nav :last-child { text-transform: upperca
我主要是一名Python程序员,正在学习一些Java。我需要一个函数将包含“First Last”形式的名称的字符串转换为“Last, First”(我还需要它能够处理单个名称:“Cher”=>“Ch
难以尝试将集合中的特定元素作为最后一个匹配的选择器。 this is today this is today
我是一名优秀的程序员,十分优秀!