コード例 #1
0
def supportFunction(rawX, rawY, rawXTesting, rawYTesting):
  X = [elem[0:1] for elem in rawX]
  Y = rawY
  senses = [elem[2] for elem in rawX]
  words = [elem[3] for elem in rawX]
  #modelr = svm.SVR()
  modelr = sup.SVC(kernel = 'poly', degree = 2, probability = True)
  modelr.fit(X,Y)
  
  # This part needs to be changed to sample
    
  sampleX = [elem[0:1] for elem in rawXTesting]
  sampleY = rawYTesting
  q = modelr.predict_proba(sampleX)
  predictedProb = [elem[1] for elem in q]
  
  predictedY = evaluation.getPredictedY(words, senses, predictedProb, rawXTesting, rawYTesting)
  return evaluation.evaluationMetrics(sampleY, predictedY)
コード例 #2
0
def supportFunction(rawX, rawY, rawXTesting, rawYTesting):
    X = [elem[0:1] for elem in rawX]
    Y = rawY
    senses = [elem[2] for elem in rawX]
    words = [elem[3] for elem in rawX]
    #modelr = svm.SVR()
    modelr = sup.SVC(kernel='poly', degree=2, probability=True)
    modelr.fit(X, Y)

    # This part needs to be changed to sample

    sampleX = [elem[0:1] for elem in rawXTesting]
    sampleY = rawYTesting
    q = modelr.predict_proba(sampleX)
    predictedProb = [elem[1] for elem in q]

    predictedY = evaluation.getPredictedY(words, senses, predictedProb,
                                          rawXTesting, rawYTesting)
    return evaluation.evaluationMetrics(sampleY, predictedY)
コード例 #3
0
def kmeansFunction(rawX, rawY, rawXTesting, rawYTesting):
  X = [elem[0:1] for elem in rawX]
  Y = rawY
  senses = [elem[2] for elem in rawX]
  words = [elem[3] for elem in rawX]
  
  
  modelk = cluster.KMeans(n_clusters = 2)  
  modelk.fit(X)
  
  # This part needs to be changed to sample
    
  sampleX = [elem[0:1] for elem in rawXTesting]
  sampleY = rawYTesting
  q = modelk.transform(sampleX)
  # This gives distance to the new "clusters"
  predictedProb = [-elem[1] for elem in q]
  # Note we use negative since we want lower distance!
  
  predictedY = evaluation.getPredictedY(words, senses, predictedProb, rawXTesting, rawYTesting)
  return evaluation.evaluationMetrics(sampleY, predictedY)
コード例 #4
0
def multinomialNB(rawX, rawY, rawXTesting, rawYTesting): 
  X = np.array([[elem[0], elem[1]] for elem in rawX]) # relatedness and commonness
  senses = [elem[2] for elem in rawX] # which sense it comes from
  words = [elem[3] for elem in rawX] # which word it comes from
 
  Y = np.array(rawY)

  clf = BernoulliNB(alpha = 0.0, class_prior = None, fit_prior = True)
  # clf = MultinomialNB(alpha = 0.1, class_prior = None, fit_prior = True)
  clf.fit(X, Y)
  
  # This part needs to be changed to a sample

  sampleX = np.array([[elem[0], elem[1]] for elem in rawXTesting])
  sampleY = np.array(rawYTesting)
  
  q = clf.predict_proba(sampleX)
  predictedProb = [elem[1] for elem in q]

  predictedY = evaluation.getPredictedY(words, senses, predictedProb, rawXTesting, rawYTesting)
  return evaluation.evaluationMetrics(sampleY, predictedY)
コード例 #5
0
def multinomialNB(rawX, rawY, rawXTesting, rawYTesting):
    X = np.array([[elem[0], elem[1]]
                  for elem in rawX])  # relatedness and commonness
    senses = [elem[2] for elem in rawX]  # which sense it comes from
    words = [elem[3] for elem in rawX]  # which word it comes from

    Y = np.array(rawY)

    clf = BernoulliNB(alpha=0.0, class_prior=None, fit_prior=True)
    # clf = MultinomialNB(alpha = 0.1, class_prior = None, fit_prior = True)
    clf.fit(X, Y)

    # This part needs to be changed to a sample

    sampleX = np.array([[elem[0], elem[1]] for elem in rawXTesting])
    sampleY = np.array(rawYTesting)

    q = clf.predict_proba(sampleX)
    predictedProb = [elem[1] for elem in q]

    predictedY = evaluation.getPredictedY(words, senses, predictedProb,
                                          rawXTesting, rawYTesting)
    return evaluation.evaluationMetrics(sampleY, predictedY)