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


Python PassiveAggressiveClassifier.score方法代码示例

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


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

示例1: test_classifier_accuracy

# 需要导入模块: from sklearn.linear_model import PassiveAggressiveClassifier [as 别名]
# 或者: from sklearn.linear_model.PassiveAggressiveClassifier import score [as 别名]
def test_classifier_accuracy():
    for data in (X, X_csr):
        for fit_intercept in (True, False):
            clf = PassiveAggressiveClassifier(C=1.0, n_iter=30,
                                              fit_intercept=fit_intercept,
                                              random_state=0)
            clf.fit(data, y)
            score = clf.score(data, y)
            assert_greater(score, 0.79)
开发者ID:Big-Data,项目名称:scikit-learn,代码行数:11,代码来源:test_passive_aggressive.py

示例2: test_classifier_partial_fit

# 需要导入模块: from sklearn.linear_model import PassiveAggressiveClassifier [as 别名]
# 或者: from sklearn.linear_model.PassiveAggressiveClassifier import score [as 别名]
def test_classifier_partial_fit():
    classes = np.unique(y)
    for data in (X, X_csr):
            clf = PassiveAggressiveClassifier(C=1.0,
                                              fit_intercept=True,
                                              random_state=0)
            for t in range(30):
                clf.partial_fit(data, y, classes)
            score = clf.score(data, y)
            assert_greater(score, 0.79)
开发者ID:Big-Data,项目名称:scikit-learn,代码行数:12,代码来源:test_passive_aggressive.py

示例3: test_classifier_accuracy

# 需要导入模块: from sklearn.linear_model import PassiveAggressiveClassifier [as 别名]
# 或者: from sklearn.linear_model.PassiveAggressiveClassifier import score [as 别名]
def test_classifier_accuracy():
    for data in (X, X_csr):
        for fit_intercept in (True, False):
            for average in (False, True):
                clf = PassiveAggressiveClassifier(
                    C=1.0, max_iter=30, fit_intercept=fit_intercept,
                    random_state=1, average=average, tol=None)
                clf.fit(data, y)
                score = clf.score(data, y)
                assert_greater(score, 0.79)
                if average:
                    assert hasattr(clf, 'average_coef_')
                    assert hasattr(clf, 'average_intercept_')
                    assert hasattr(clf, 'standard_intercept_')
                    assert hasattr(clf, 'standard_coef_')
开发者ID:allefpablo,项目名称:scikit-learn,代码行数:17,代码来源:test_passive_aggressive.py

示例4: test_classifier_partial_fit

# 需要导入模块: from sklearn.linear_model import PassiveAggressiveClassifier [as 别名]
# 或者: from sklearn.linear_model.PassiveAggressiveClassifier import score [as 别名]
def test_classifier_partial_fit():
    classes = np.unique(y)
    for data in (X, X_csr):
        for average in (False, True):
            clf = PassiveAggressiveClassifier(
                C=1.0, fit_intercept=True, random_state=0,
                average=average, max_iter=5)
            for t in range(30):
                clf.partial_fit(data, y, classes)
            score = clf.score(data, y)
            assert_greater(score, 0.79)
            if average:
                assert hasattr(clf, 'average_coef_')
                assert hasattr(clf, 'average_intercept_')
                assert hasattr(clf, 'standard_intercept_')
                assert hasattr(clf, 'standard_coef_')
开发者ID:allefpablo,项目名称:scikit-learn,代码行数:18,代码来源:test_passive_aggressive.py

示例5: runLearner

# 需要导入模块: from sklearn.linear_model import PassiveAggressiveClassifier [as 别名]
# 或者: from sklearn.linear_model.PassiveAggressiveClassifier import score [as 别名]
def runLearner(printStages = True, useSelector = False, discreteHelpfulness = True, useRST = True, useFew = False):
    learner = PassiveAggressiveClassifier() if discreteHelpfulness else PassiveAggressiveRegressor()
    #bestwords = getBestWords(instances,num=1000)
    tfidvec = TfidfVectorizer(sublinear_tf=True,stop_words='english', ngram_range=(1,3), decode_error='replace')
    selector = SelectKBest(chi2, k=50000) if useSelector else None
    encoder = LabelEncoder() if discreteHelpfulness else None
    if discreteHelpfulness:
        classlabels = encoder.fit_transform(labels)
    newData = False

    count = 0
    if useRST:
      print 'Getting RST data'
      nums, texts, ilabels = getPickledRSTSciKitDataLists(True) if newData else getRSTSciKitDataLists(True)

      random = RandomFeatureExtractor()
      lengthBaseline = LenFeatureExtractor()
      fullRST = FullPickledRSTFeatureExtractor(nums)  if newData else FullTextRSTFeatureExtractor(nums)
      limitedRST = LimitedPickledRSTFeatureExtractor(nums)  if newData else LimitedTextRSTFeatureExtractor(nums)
      vectorizer =  FeatureUnion([('extra',limitedRST),('tfid',tfidvec)])

      print 'Fitting random features baseline'
      random.fit(texts)
      print 'Fitting text length baseline'
      lengthBaseline.fit(texts)
      print 'Fitting full RST features'
      fullRST.fit(texts)
      print 'Fitting limited RST features'
      limitedRST.fit(texts)
      print 'Fitting limited RST with tfidvec features'
      vectorizer.fit(texts)
      print 'Fitting tfidvec features'
      tfidvec.fit(texts)

      split = int(0.8*len(ilabels))
      trainData = (texts[:split],ilabels[:split])
      testData = (texts[split:],ilabels[split:])      

      X,y = getAsSciKit(trainData[0],trainData[1],random,encoder,selector)
      learner.fit(X,y)
      X,y = getAsSciKit(trainData[0],trainData[1],random,encoder,selector)
      print 'random features baseline trained on %d instances has accuracy %f'%(len(trainData[0]),learner.score(X,y))

      dummy = DummyClassifier()
      X,y = getAsSciKit(trainData[0],trainData[1],random,encoder,selector)
      dummy.fit(X,y)
      X,y = getAsSciKit(testData[0],testData[1],random,encoder,selector)
      print 'Dummy label distribution baseline trained on %d instances has accuracy %f'%(len(trainData[0]),dummy.score(X,y))

      X,y = getAsSciKit(trainData[0],trainData[1],lengthBaseline,encoder,selector)
      learner.fit(X,y)
      X,y = getAsSciKit(testData[0],testData[1],lengthBaseline,encoder,selector)
      print 'text length baseline trained on %d instances has accuracy %f'%(len(trainData[0]),learner.score(X,y))

      X,y = getAsSciKit(trainData[0],trainData[1],fullRST,encoder,selector)
      learner.fit(X,y)
      X,y = getAsSciKit(testData[0],testData[1],fullRST,encoder,selector)
      print 'Full RST learner trained on %d instances has accuracy %f'%(len(trainData[0]),learner.score(X,y))

      X,y = getAsSciKit(trainData[0],trainData[1],limitedRST,encoder,selector)
      learner.fit(X,y)
      X,y = getAsSciKit(testData[0],testData[1],limitedRST,encoder,selector)
      print 'Limited RST learner trained on %d instances has accuracy %f'%(len(trainData[0]),learner.score(X,y))

      X,y = getAsSciKit(trainData[0],trainData[1],vectorizer,encoder,selector)
      learner.fit(X,y)
      X,y = getAsSciKit(testData[0],testData[1],vectorizer,encoder,selector)
      print 'Limited RST with ngram learner trained on %d instances has accuracy %f'%(len(trainData[0]),learner.score(X,y))

      X,y = getAsSciKit(trainData[0],trainData[1],tfidvec,encoder,selector)
      learner = learner.fit(X,y)
      X,y = getAsSciKit(testData[0],testData[1],tfidvec,encoder,selector)
      print 'ngram learner trained on %d instances has accuracy %f'%(len(trainData[0]),learner.score(X,y))


    else:
      vectorizer = tfidvec
      testData = None
      vocabGotten = False
      instances = ([],[])
      numVocab = 50000
      numTest = 50000
      numTrain = 100000
      maxTrainStages = 20
      for text,label in getSciKitData(stateProgress = False, discreteLabels=discreteHelpfulness):
          if label!='few' or useFew:
            instances[0].append(text)
            instances[1].append(label)
            if not vocabGotten and len(instances[0]) == numVocab:
                if printStages:
                    print 'Fitting vocabulary with %d instances'%numVocab
                vectorizer.fit(instances[0],None)
                if selector is not None:
                    X,y = getSciKitInstance(instances[0],instances[1],vectorizer,encoder,None)
                    selector.fit(X,y)
                vocabGotten = True
                instances = ([],[])
            elif vocabGotten and testData is None and len(instances[0]) == numTest:
                if printStages:
                    print 'Getting test data with %d instances'%numTest
#.........这里部分代码省略.........
开发者ID:ybur-yug,项目名称:emailinsight,代码行数:103,代码来源:reviewHelpfulnessClassification.py

示例6: range

# 需要导入模块: from sklearn.linear_model import PassiveAggressiveClassifier [as 别名]
# 或者: from sklearn.linear_model.PassiveAggressiveClassifier import score [as 别名]
    percScoresTrain = []
    percScoresDev = []
    for i in range(10):
        perceptron.fit(trainX, trainY)
        percScoresDev.append(perceptron.score(devX, devY))
        percScoresTrain.append(perceptron.score(trainX, trainY))

    print "Perceptron Train:", np.mean(percScoresTrain)
    print "Perceptron Dev:", np.mean(percScoresDev)
    
    passAggScoresTrain = []
    passAggScoresDev = []
    for i in range(10):
        passAgg.fit(trainX, trainY) 
        passAggScoresDev.append( passAgg.score(devX, devY))
        passAggScoresTrain.append( passAgg.score(trainX, trainY))


    print "Passive Aggressive Train:", np.mean(passAggScoresTrain)
    print "Passive Aggressive Dev:", np.mean(passAggScoresDev)

    
    passAggScoresSmallTrain = []
    passAggScoresSmallDev = []
    for i in range(10):
        passAgg.fit(trainX, trainY) 
        passAggScoresSmallDev.append( passAgg.score(devX, devY))
        passAggScoresSmallTrain.append( passAgg.score(trainXSmall,trainYSmall))

    print "Passive Aggressive (Small Dataset)) Train:", np.mean(passAggScoresSmallTrain)
开发者ID:marcoscattolin,项目名称:MLCodeLab,代码行数:32,代码来源:allModels.py


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