def regression(X, Y, X_out, Y_out, l, ts='linear'):
    X = transform(X, ts)
    X_out = transform(X_out, ts)
    w = weightDecayRegression((X, Y), l)
    #   print w
    return classificationError((X, Y), w), classificationError((X_out, Y_out),
                                                               w)
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 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 regression(X, Y, X_out, Y_out, l, ts='linear'):
  X = transform(X, ts)
  X_out = transform(X_out, ts)
  w = weightDecayRegression((X, Y), l)
#   print w
  return classificationError((X, Y), w), classificationError((X_out, Y_out), w)