当前位置: 首页>>代码示例>>Python>>正文


Python SklearnClassifier._convert方法代码示例

本文整理汇总了Python中nltk.classify.scikitlearn.SklearnClassifier._convert方法的典型用法代码示例。如果您正苦于以下问题:Python SklearnClassifier._convert方法的具体用法?Python SklearnClassifier._convert怎么用?Python SklearnClassifier._convert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nltk.classify.scikitlearn.SklearnClassifier的用法示例。


在下文中一共展示了SklearnClassifier._convert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: zip

# 需要导入模块: from nltk.classify.scikitlearn import SklearnClassifier [as 别名]
# 或者: from nltk.classify.scikitlearn.SklearnClassifier import _convert [as 别名]
#build, train, and test classifiers
from sklearn.svm import LinearSVC
from nltk.classify.scikitlearn import SklearnClassifier
sv=SklearnClassifier(LinearSVC())
sv.train(train)
#note that train performance matches tmp.sum()
pred_train_sv=sv.batch_classify(train_feat)
nltk.ConfusionMatrix(train_tag,pred_train_sv)
#also test performance matches tmp_test.sum()
pred_sv=sv.batch_classify(test_feat)
#confusion matrices
cmsv=nltk.ConfusionMatrix(test_tag,pred_sv)
print cmsv.pp(sort_by_count=True, show_percents=False, truncate=5)
#some SklearnClassifier internals
featsets, labs = zip(*train)
X = sv._convert(featsets)
import numpy
y=numpy.array([sv._label_index[l] for l in labs])
#then to train one would use sv._clf.fit(X,y)

#-------------------------------------
#To vectorize/classify all in sklearn
#-------------------------------------
porter=nltk.PorterStemmer()
#for use with sklearn 
def myparser(s):
	punc='[!"#$%&\'()*+,-./:;<=>[email protected][\\]^_`{|}~\n ]' #all punc+whtspc+newline
	np=[a for a in re.split(punc,s) if a not in string.punctuation]
	low=[a.lower() for a in np if len(a)>2] #only two-lett words lowered
	nostop=[a for a in low if a not in stopwords.words('english')]
	return [porter.stem(a) for a in nostop if re.findall(r"[^\W\d]",a)]
开发者ID:akhil137,项目名称:nlp-tagging,代码行数:33,代码来源:ipyTxtClassSetEnv.py


注:本文中的nltk.classify.scikitlearn.SklearnClassifier._convert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。