コード例 #1
0
ファイル: run.py プロジェクト: wz125/courses
def theProbabilities1():
  print '## Graphing the Probabilities 概率密度'
  reload(numpredict)
  data1=numpredict.wineset3()
  numpredict.cumulativegraph(data1,(1,1),120)
  reload(numpredict)
  numpredict.probabilitygraph(data1,(1,1),6)
コード例 #2
0
ファイル: run.py プロジェクト: wz125/courses
def unevenDistributions():
  ''' 对于某些关键特征,数据中并未体现,需要有种方式进行观测,比如部分数据是通过折扣店购买的!'''
  print '## Uneven Distributions 不对称性'
  reload(numpredict)
  data=numpredict.wineset3()
  print numpredict.wineprice(99.0,20.0)
  print numpredict.weightedknn(data,[99.0,20.0])
  print numpredict.crossvalidate(numpredict.weightedknn,data)
コード例 #3
0
def knn2(d, v):
    return numpredict.weightedknn(d, v, k=3)


print(numpredict.crossvalidate(knn1, data))
print(numpredict.crossvalidate(knn2, data))

# Parameter tuning
import optimization
print('<----Parameter tuning---->')
data2 = numpredict.wineset2()
print(numpredict.crossvalidate(knn1, data2))
print(numpredict.crossvalidate(numpredict.weightedknn, data2))
print('<--scaling-->')
sdata = numpredict.rescale(data2, [10, 10, 0, 0.5])
print(numpredict.crossvalidate(knn1, sdata))
print('<--optimizing-->')
costf = numpredict.createcostfunction(numpredict.knnestimate, data2)
print(optimization.geneticoptimize(numpredict.weightdomain, costf, step=2))

# Probability Density
print('\n<----Probability Density---->')
data3 = numpredict.wineset3()
numpredict.cumulativegraph(data3, (99, 20), 120)
numpredict.probabilitygraph(data3, (99, 20), 120)

# eBay API
# remaining problems
# import  ebaypredict
# laptops = ebaypredict.doSearch('laptop')
# print(laptops[:10])
コード例 #4
0
    ]

    # gaussian smooth with nearby points
    smoothed = []
    for i in range(len(probs)):  # O(n^2)
        sv = 0.0
        for j in range(0, len(probs)):
            dist = abs(i - j) * 0.1
            weight = numpredict.gaussianweight(dist, sigma=ss)
            sv += weight * probs[j]
        smoothed.append(sv)

    plot(t1, array(probs))
    plot(t1, array(smoothed))


if __name__ == '__main__':
    s = numpredict.wineset3(k=500)

    import pprint
    pprint.pprint(s)

    #wine = [99.0, 20.0]  # choose params were the sample data is somewhat dense
    wine = [99.0, 20.0]  # choose params were the sample data is somewhat dense
    # Draw graph that shows p(price | wine)
    print 'Real price 1:', numpredict.wineprice(wine[0], wine[1])
    print 'Real price 2:', 0.6 * numpredict.wineprice(wine[0], wine[1])
    cumulativegraph(s, wine, 120)
    probabilitygraph(s, wine, 120)
    show()  # this does user interaction
コード例 #5
0
import numpredict
import optimization
#print numpredict.wineprice(95.0, 3.0)
#data = numpredict.wineset1()
#print data[0],data[1]
#print numpredict.knnestimate(data,(99.0,50),k = 1)
#print numpredict.knnestimate(data,(99.0,50))
#print numpredict.weightedknn(data,(99.0,5.0))
#print numpredict.crossvalidate(numpredict.knnestimate,data)
#data = numpredict.wineset2()

#costf = numpredict.createcostfunction(numpredict.knnestimate, data)
#print optimization.annealingoptimize(numpredict.weightdomain, costf, step = 2)
data = numpredict.wineset3()
#print numpredict.probguess(data, [99,20],40,80)
numpredict.probabilitygraph(data, (99,30), 120)
  probs = [numpredict.probguess(data, vec1, v, v+S, k, weightfun) for v in t1]

  # gaussian smooth with nearby points
  smoothed = []
  for i in range(len(probs)):  # O(n^2)
    sv = 0.0
    for j in range(0, len(probs)):
      dist = abs(i - j)*0.1
      weight = numpredict.gaussianweight(dist, sigma=ss)
      sv += weight*probs[j]
    smoothed.append(sv)

  plot(t1, array(probs))
  plot(t1, array(smoothed))


if __name__ == '__main__':
  s = numpredict.wineset3(k=500)

  import pprint
  pprint.pprint(s)

  #wine = [99.0, 20.0]  # choose params were the sample data is somewhat dense
  wine = [99.0, 20.0]  # choose params were the sample data is somewhat dense
  # Draw graph that shows p(price | wine)
  print 'Real price 1:', numpredict.wineprice(wine[0], wine[1])
  print 'Real price 2:', 0.6 * numpredict.wineprice(wine[0], wine[1])
  cumulativegraph(s, wine, 120)
  probabilitygraph(s, wine, 120)
  show()  # this does user interaction