- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试预测某些文档的标签。每个文档可以有多个标签。这是我编写的示例程序
import pandas as pd
import pickle
import re
from sklearn.cross_validation import train_test_split
from sklearn.metrics.metrics import classification_report, accuracy_score, confusion_matrix
from nltk.stem import WordNetLemmatizer
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.naive_bayes import MultinomialNB as MNB
from sklearn.pipeline import Pipeline
from sklearn.grid_search import GridSearchCV
def Mytrain():
pipeline = Pipeline([
('vect', TfidfVectorizer(stop_words='english',sublinear_tf=True)),
('clf', MNB())
])
parameters = {
'vect__max_df': (0.25, 0.5, 0.6, 0.7, 1.0),
'vect__ngram_range': ((1, 1), (1, 2), (2,3), (1,3), (1,4), (1,5)),
'vect__use_idf': (True, False),
'clf__fit_prior': (True, False)
}
traindf = pickle.load(open("train.pkl","rb"))
X, y = traindf['Data'], traindf['Tags'].as_matrix()
Xtrain, Xtest, ytrain, ytest = train_test_split(X, y, train_size=0.7)
gridSearch = GridSearchCV(pipeline, parameters, n_jobs=3, verbose=1, scoring='accuracy')
gridSearch.fit(Xtrain, ytrain)
print ('best score: %0.3f' % gridSearch.best_score_)
print ('best parameters set:')
res = open("res.txt", 'w')
res.write ('best parameters set:\n')
bestParameters = gridSearch.best_estimator_.get_params()
for paramName in sorted(parameters.keys()):
print ('\t %s: %r' % (paramName, bestParameters[paramName]))
res.write('\t %s: %r\n' % (paramName, bestParameters[paramName]))
pickle.dump(bestParameters,open("bestParams.pkl","wb"))
predictions = gridSearch.predict(Xtest)
print ('Accuracy:', accuracy_score(ytest, predictions))
print ('Confusion Matrix:', confusion_matrix(ytest, predictions))
print ('Classification Report:', classification_report(ytest, predictions))
请注意,标签可以有多个值。现在我明白了
An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (40, 0))
Traceback (most recent call last):
File "X:\abc\predMNB.py", line 128, in <module>
MNBdrill(fname,topn)
File "X:\abc\predMNB.py", line 82, in MNBdrill
gridSearch.fit(Xtrain, ytrain)
File "X:\pqr\Anaconda2\lib\site-packages\sklearn\grid_search.py", line 732, in fit
return self._fit(X, y, ParameterGrid(self.param_grid))
File "X:\pqr\Anaconda2\lib\site-packages\sklearn\grid_search.py", line 505, in _fit
for parameters in parameter_iterable
File "X:\pqr\Anaconda2\lib\site-packages\sklearn\externals\joblib\parallel.py", line 666, in __call__
self.retrieve()
File "X:\pqr\Anaconda2\lib\site-packages\sklearn\externals\joblib\parallel.py", line 549, in retrieve
raise exception_type(report)
sklearn.externals.joblib.my_exceptions.JoblibMemoryError: JoblibMemoryError
然后
Multiprocessing exception:
...........................................................................
X:\pqr\Anaconda2\lib\site-packages\sklearn\grid_search.py in fit(self=GridSearchCV(cv=None, error_score='raise',
..._func=None,
scoring='accuracy', verbose=1), X=14151 text for document having t1,t2,t3,t4
Name: Content, dtype: object, y=array([u't1',u't2',u't3',u't4'], dtype=object))
727 y : array-like, shape = [n_samples] or [n_samples, n_output], optional
728 Target relative to X for classification or regression;
729 None for unsupervised learning.
730
731 """
--> 732 return self._fit(X, y, ParameterGrid(self.param_grid))
self._fit = <bound method GridSearchCV._fit of GridSearchCV(...func=None,
scoring='accuracy', verbose=1)>
X = 14151 text for document having t1,t2,t3,t4
Name: Content, dtype: object
y = array([u't1',u't2',u't3',u't4'], dtype=object)
self.param_grid = {'clf__fit_prior': (True, False), 'vect__max_df': (0.25, 0.5, 0.6, 0.7, 1.0), 'vect__ngram_range': ((1, 1), (1, 2), (2, 3), (1, 3), (1, 4), (1, 5)), 'vect__use_idf': (True, False)}
733
734
735 class RandomizedSearchCV(BaseSearchCV):
736 """Randomized search on hyper parameters.
...........................................................................
X:\pqr\Anaconda2\lib\site-packages\sklearn\grid_search.py in _fit(self=GridSearchCV(cv=None, error_score='raise',
..._func=None,
scoring='accuracy', verbose=1), X=14151 text for document having t1,t2,t3,t4
Name: Content, dtype: object, y=array([u't1',u't2',u't3',u't4'], dtype=object), parameter_iterable=<sklearn.grid_search.ParameterGrid object>)
500 )(
501 delayed(_fit_and_score)(clone(base_estimator), X, y, self.scorer_,
502 train, test, self.verbose, parameters,
503 self.fit_params, return_parameters=True,
504 error_score=self.error_score)
--> 505 for parameters in parameter_iterable
parameters = undefined
parameter_iterable = <sklearn.grid_search.ParameterGrid object>
506 for train, test in cv)
507
508 # Out is a list of triplet: score, estimator, n_test_samples
509 n_fits = len(out)
...........................................................................
X:\pqr\Anaconda2\lib\site-packages\sklearn\externals\joblib\parallel.py in __call__(self=Parallel(n_jobs=3), iterable=<itertools.islice object>)
661 if pre_dispatch == "all" or n_jobs == 1:
662 # The iterable was consumed all at once by the above for loop.
663 # No need to wait for async callbacks to trigger to
664 # consumption.
665 self._iterating = False
--> 666 self.retrieve()
self.retrieve = <bound method Parallel.retrieve of Parallel(n_jobs=3)>
667 # Make sure that we get a last message telling us we are done
668 elapsed_time = time.time() - self._start_time
669 self._print('Done %3i out of %3i | elapsed: %s finished',
670 (len(self._output),
---------------------------------------------------------------------------
Sub-process traceback:
---------------------------------------------------------------------------
MemoryError
堆栈跟踪在此之后继续指向具有相同问题的其他方法。如果需要,我可以发布整个内容,但这就是我认为正在发生的事情
通知
scoring='accuracy', verbose=1), X=14151 text for document having t1,t2,t3,t4
Name: Content, dtype: object, y=array([u't1',u't2',u't3',u't4'], dtype=object))
由于有多个标签,这会导致问题吗?
还有,什么意思
多处理异常?
内存错误?
请帮我解决这个问题。
最佳答案
您有多少列车数据?
我最好的选择是,唯一的“真正”错误是MemoryError
,即您在尝试训练分类器时使用所有可用的RAM,而所有其他奇怪的错误/回溯都是失败的后果内存分配。
在训练分类器时,您是否检查过您的可用内存?
关于Python机器学习: Using Multinomial Naive Bayes gives Multiprocessing exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34181647/
我正在将 TortoiseSVN 用于我的 C++ 项目,并试图将“分支”重新集成到主干中。 我的情况很简单,因此对于分支中已更改的每个文件,我希望它完全覆盖主干中的匹配文件。不幸的是,Tortois
朴素贝叶斯的朴素是什么? 最佳答案 实际上有一个很好的例子on Wikipedia : In simple terms, a naive Bayes classifier assumes that t
我开始学习 Haskell 并且我一直在阅读 this Haskell 的 wiki 页面,报告了这个 qsort 实现: qsort :: (Ord a) => [a] -> [a] qsort
我有一个格式对列表 (a: A, x: Int),并且 x 在列表中不重复。现在我知道 x 在一定范围内 0 until n,我想做一个大小为 n 的数组,其 i 第一个元素的类型是 Option[A
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be
我正在尝试使用 Java 编写一个简单的 Kafka Producer。该应用程序接受两个输入: 要生成消息的 Kafka 主题名称 包含要生成到 Kafka 的消息的文件路径 我写了下面的代码。当我
这个问题已经有答案了: C++ strange results - brute force is quicker than Rabin-Karp...? (1 个回答) 已关闭 3 年前。 我实现了
我正在对我的 Django 应用程序进行 Docker 化。由于我将数据库从 SQLite 更改为 Postgres,迁移失败并收到此错误: RuntimeWarning: DateTimeField
我的环境: 驯象师:0.7 Hadoop:1.0.3 我做了什么: 安装了 mahout,并测试了朴素的贝叶斯示例 - 20newsgroup,它运行良好。 我想要达到的目标: 有 trainnb 和
我正在尝试使用 IPython 发送一封简单的邮件。我没有设置任何模型仍然出现此错误。可以做什么? Error : /home/sourabh/Django/learn/local/lib/pytho
我想我或多或少了解朴素贝叶斯,但我对它在简单二进制文本分类中的实现有几个问题。 假设文档 D_i是词汇表的一些子集 x_1, x_2, ...x_n 有两个类c_i任何文档都可以落在上面,我想计算 P
我已经看到推荐使用 GetHashCode 函数的素数实现,例如 here .但是,使用以下代码(在 VB 中,抱歉),似乎该实现提供了与“天真”异或实现相同的哈希密度。如果密度相同,我认为两种实现中
我正在使用资源管理器功能进行分类。我的.arff数据文件有10个数字和二进制值的特征; (只有实例的 ID 是名义上的)。我有大约 16 个实例。要预测的类别是是/否。我使用了朴素贝叶斯,但我无法解释
我在理解express.js路线时遇到了一些麻烦 如果我设置开箱即用的 hello world 应用程序,我将获得带有单个路由的基本设置 app.get('/', routes.home); 正如在e
我正在尝试编码而不在我的控制台中抛出任何警告。到目前为止,我一直很擅长避免这种情况,直到这个案例为止,这对我来说就像先有鸡还是先有蛋的情况。 from datetime import datetime
分而治之 (D&C) 解决方案和矩阵乘法的朴素解决方案都是使用 C 编程语言“就地”实现的。所以根本没有动态内存分配。 正如我们对这两种解决方案所了解的那样,它们实际上具有相同的时间复杂度,即 O(n
有人可以解释一下这是怎么行不通的吗? 有问题的 shapefile 是 here并在代码中读作 shp=gpd.read_file("Microdatos_Censo_2017_Manzana/Mic
ModuleNotFoundError Traceback (most recent call last) in () 3 import operator 4 from fu
我正在尝试预测某些文档的标签。每个文档可以有多个标签。这是我编写的示例程序 import pandas as pd import pickle import re from sklearn.cross
托管我的db 的服务器位于美国。当我向 db 添加项目时,我希望使用 Australia/Sydney 时间存储时间。无论用户在哪个国家/地区,如果他们检索此记录,都应使用 Australia/Syd
我是一名优秀的程序员,十分优秀!