def problem1():
  name = ['c://users//mark//in.dta', 'c://users//mark//out.dta']
  in_data = dataSet(readIn(name[0]))
  out_data = dataSet(readIn(name[1]))
  X, Y = in_data
  print 'Problem 1, 2'
  for k in (3, 4, 5, 6, 7):
    X_t, Y_t = X[:25, :k+1], Y[:25]
    X_v, Y_v = X[25:, :k+1], Y[25:]
    w = regression((X_t, Y_t))
    print k, classificationError((X_v, Y_v), w), classificationError((out_data[0][:, :k+1], out_data[1]) , w)
  print 'Problem 3, 4'
  for k in (3, 4, 5, 6, 7):
    X_t, Y_t = X[:25, :k+1], Y[:25]
    X_v, Y_v = X[25:, :k+1], Y[25:]
    w = regression((X_v, Y_v))
    print k, classificationError((X_t, Y_t), w), classificationError((out_data[0][:, :k+1], out_data[1]) , w)
Пример #2
0
def problem1():
    name = ['c://users//mark//in.dta', 'c://users//mark//out.dta']
    in_data = dataSet(readIn(name[0]))
    out_data = dataSet(readIn(name[1]))
    X, Y = in_data
    print 'Problem 1, 2'
    for k in (3, 4, 5, 6, 7):
        X_t, Y_t = X[:25, :k + 1], Y[:25]
        X_v, Y_v = X[25:, :k + 1], Y[25:]
        w = regression((X_t, Y_t))
        print k, classificationError((X_v, Y_v), w), classificationError(
            (out_data[0][:, :k + 1], out_data[1]), w)
    print 'Problem 3, 4'
    for k in (3, 4, 5, 6, 7):
        X_t, Y_t = X[:25, :k + 1], Y[:25]
        X_v, Y_v = X[25:, :k + 1], Y[25:]
        w = regression((X_v, Y_v))
        print k, classificationError((X_t, Y_t), w), classificationError(
            (out_data[0][:, :k + 1], out_data[1]), w)
def problem7():
  RO = [(3**.5 + 4)**.5,
        (3**.5 - 1)**.5,
        (9 + 4 * 6 **.5)**.5,
        (9 - 6 **.5)**.5,
        ]
  for i, ro in enumerate(RO):
    points = [(-1.,0.), (ro, 1.), (1., 0.)]
    points = np.array(points)
    e0, e1 = 0, 0
    for row in range(3):
      val = points[row]
      train = points[points[:,0] != val[0],:]
      val = np.insert(val,  0, 1, 0)
      train = np.insert(train,  0, 1, 1)
      train0 = np.copy(train)
      train0[:,1] = 0
      w0 = regression(train0)
      w1 = regression(train)
      e0 += (val[:-1].dot(w0) - val[-1])**2
      e1 += (val[:-1].dot(w1) - val[-1])**2
    print i, ro, e0, e1
Пример #4
0
def problem7():
    RO = [
        (3**.5 + 4)**.5,
        (3**.5 - 1)**.5,
        (9 + 4 * 6**.5)**.5,
        (9 - 6**.5)**.5,
    ]
    for i, ro in enumerate(RO):
        points = [(-1., 0.), (ro, 1.), (1., 0.)]
        points = np.array(points)
        e0, e1 = 0, 0
        for row in range(3):
            val = points[row]
            train = points[points[:, 0] != val[0], :]
            val = np.insert(val, 0, 1, 0)
            train = np.insert(train, 0, 1, 1)
            train0 = np.copy(train)
            train0[:, 1] = 0
            w0 = regression(train0)
            w1 = regression(train)
            e0 += (val[:-1].dot(w0) - val[-1])**2
            e1 += (val[:-1].dot(w1) - val[-1])**2
        print i, ro, e0, e1