- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我试图理解下面的代码
from sklearn.feature_extraction.text import CountVectorizer
vectorizer = CountVectorizer()
corpus = ['This is the first document.','This is the second second document.','And the third one.','Is this the first document?']
X = vectorizer.fit_transform(corpus)
当我尝试打印 X 以查看将返回什么时,我得到了这个结果:
(0, 1) 1
(0, 2) 1
(0, 6) 1
(0, 3) 1
(0, 8) 1
(1, 5) 2
(1, 1) 1
(1, 6) 1
(1, 3) 1
(1, 8) 1
(2, 4) 1
(2, 7) 1
(2, 0) 1
(2, 6) 1
(3, 1) 1
(3, 2) 1
(3, 6) 1
(3, 3) 1
(3, 8) 1
但是,我不明白这个结果的含义?
最佳答案
正如@Himanshu 所写,这是一个“(sentence_index, feature_index) count”
这里,计数部分是“一个词在文档中出现的次数”
例如,
(0, 1) 1
(0, 2) 1
(0, 6) 1
(0, 3) 1
(0, 8) 1
(1, 5) 2 Only for this example, the count "2" tells that the word "and" appears twice in this document/sentence
(1, 1) 1
(1, 6) 1
(1, 3) 1
(1, 8) 1
(2, 4) 1
(2, 7) 1
(2, 0) 1
(2, 6) 1
(3, 1) 1
(3, 2) 1
(3, 6) 1
(3, 3) 1
(3, 8) 1
让我们更改代码中的语料库。基本上,我在语料库列表的第二句中添加了两次“第二”这个词。
from sklearn.feature_extraction.text import CountVectorizer
vectorizer = CountVectorizer()
corpus = ['This is the first document.','This is the second second second second document.','And the third one.','Is this the first document?']
X = vectorizer.fit_transform(corpus)
(0, 1) 1
(0, 2) 1
(0, 6) 1
(0, 3) 1
(0, 8) 1
(1, 5) 4 for the modified corpus, the count "4" tells that the word "second" appears four times in this document/sentence
(1, 1) 1
(1, 6) 1
(1, 3) 1
(1, 8) 1
(2, 4) 1
(2, 7) 1
(2, 0) 1
(2, 6) 1
(3, 1) 1
(3, 2) 1
(3, 6) 1
(3, 3) 1
(3, 8) 1
关于python - vectorizer fit_transform 如何在 sklearn 中工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47898326/
我知道有几个类似的问题被问到,但我的问题仍然没有得到解答。 问题来了。我使用命令 python3 -m pip3 install -U scikit-learn 来安装 sklearn、numpy 和
_train_weather.values : [[ 0.61818182 0.81645199 0.6679803 ..., 0. 0. 1.
如果我有一个数据集X及其标签Y,那么我将其分为训练集和测试集,scle为0.2,并使用随机种子进行洗牌: 11 >>>X.shape (10000, 50,50) train_data, test_d
首先我查看了所有相关问题。给出了非常相似的问题。 所以我遵循了链接中的建议,但没有一个对我有用。 Data Conversion Error while applying a function to
这里有两种标准化方法: 1:这个在数据预处理中使用:sklearn.preprocessing.normalize(X,norm='l2') 2:分类方法中使用另一种方法:sklearn.svm.Li
所以刚看了一个教程,作者不需要import sklearn使用时 predict anaconda 环境中pickled 模型的功能(安装了sklearn)。 我试图在 Google Colab 中重
我想评估我的机器学习模型。我使用 roc_auc_score() 计算了 ROC 曲线下的面积,并使用 sklearn 的 plot_roc_curve() 函数绘制了 ROC 曲线。在第二个函数中,
我一直在寻找此信息,但在任何地方都找不到,所以这是我的镜头。 我是Python 2.7的初学者,我学习了一个模型,感谢cPickle我保存了它,但现在我想知道是否可以从另一个设备(没有sklearn库
>>> import sklearn.model_selection.train_test_split Traceback (most recent call last): File "", li
在阅读有关使用 python 的 LinearDiscriminantAnalysis 的过程中,我有两种不同的方法来实现它,可在此处获得, http://scikit-learn.org/stabl
我正在使用 sklearn,我注意到 sklearn.metrics.plot_confusion_matrix 的参数和 sklearn.metrics.confusion_matrix不一致。 p
我正在构建一个多标签文本分类程序,我正在尝试使用 OneVsRestClassifier+XGBClassifier 对文本进行分类。最初,我使用 Sklearn 的 Tf-Idf 矢量化来矢量化文本
我想看看模型是否收敛于我的交叉验证。我如何增加或减少 sklearn.svm.SVC 中的时代? 目前: SVM_Model = SVC(gamma='auto') SVM_Model.fit(X_t
有人可以帮助我吗?我很难知道它们之间的区别 from sklearn.model_selection import train_test_split from sklearn.cross_valida
我需要提取在 sklearn.ensemble.BaggingClassifier 中训练的每个模型的概率。这样做的原因是为了估计 XGBoostClassifier 模型的不确定性。 为此,我创建了
无法使用 scikit-learn 0.19.1 导入 sklearn.qda 和 sklearn.lda 我得到: 导入错误:没有名为“sklearn.qda”的模块 导入错误:没有名为“sklea
我正在尝试在 google cloud ai 平台上创建一个版本,但找不到 impute 模块 No module named 'sklearn.impute._base; 'sklearn.impu
我在 PyQt5 中编写了一个 GUI,其中包括以下行 from sklearn.ensemble import RandomForestClassifier 。 遵循this answer中的建议,
我正在做一个 Kaggle 比赛,需要输入一些缺失的数据。我安装了最新的Anaconda(4.5.4)具有所有相关依赖项(即 scikit-learn (0.19.1) )。 当我尝试导入模块时,出现
在安装了所需的模块后,我正在尝试将imblearn导入到我的Python笔记本中。但是,我收到以下错误:。。附加信息:我使用的是一个用Visual Studio代码编写的虚拟环境。。我已经确定venv
我是一名优秀的程序员,十分优秀!