fix: add feature transform
This commit is contained in:
parent
2e5fcb284f
commit
110631594b
@ -33,7 +33,33 @@ def error(gt, pred):
|
||||
err = (err+1) if gt[index]!=pred[index] else err
|
||||
return err/len(gt)
|
||||
|
||||
def transform(features):
|
||||
output_features = []
|
||||
for index, feature in enumerate(features):
|
||||
output_features.append([ 0 for _ in range(84) ])
|
||||
output_features[index][0] = 1
|
||||
|
||||
d_index = 1
|
||||
# 1-order
|
||||
for i in feature:
|
||||
output_features[index][d_index] = i
|
||||
d_index += 1
|
||||
|
||||
# 2-orde
|
||||
for i in range(len(feature)):
|
||||
for j in range(i, len(feature)):
|
||||
output_features[index][d_index] = feature[i]*feature[j]
|
||||
d_index += 1
|
||||
# 3-order
|
||||
for i in range(len(feature)):
|
||||
for j in range(i, len(feature)):
|
||||
for k in range(j, len(feature)):
|
||||
output_features[index][d_index] = i*j*k
|
||||
d_index += 1
|
||||
return output_features
|
||||
|
||||
x, y = read_data(FILENAME)
|
||||
x = transform(x)
|
||||
x = format(x)
|
||||
prob = problem(y, x)
|
||||
lambda_powers = [-6, -4, -2, 0, 2]
|
||||
|
||||
@ -36,7 +36,6 @@ def error(gt, pred):
|
||||
return err/len(gt)
|
||||
|
||||
def new_split(x, y):
|
||||
random.seed(datetime.datetime.now().timestamp())
|
||||
data = list(zip(x, y))
|
||||
random.shuffle(data)
|
||||
x, y = zip(*data)
|
||||
@ -44,10 +43,37 @@ def new_split(x, y):
|
||||
train_y, val_y = y[:120], y[120:]
|
||||
return (train_x, train_y), (val_x, val_y)
|
||||
|
||||
def transform(features):
|
||||
output_features = []
|
||||
for index, feature in enumerate(features):
|
||||
output_features.append([ 0 for _ in range(84) ])
|
||||
output_features[index][0] = 1
|
||||
|
||||
d_index = 1
|
||||
# 1-order
|
||||
for i in feature:
|
||||
output_features[index][d_index] = i
|
||||
d_index += 1
|
||||
|
||||
# 2-orde
|
||||
for i in range(len(feature)):
|
||||
for j in range(i, len(feature)):
|
||||
output_features[index][d_index] = feature[i]*feature[j]
|
||||
d_index += 1
|
||||
# 3-order
|
||||
for i in range(len(feature)):
|
||||
for j in range(i, len(feature)):
|
||||
for k in range(j, len(feature)):
|
||||
output_features[index][d_index] = i*j*k
|
||||
d_index += 1
|
||||
return output_features
|
||||
|
||||
x, y = read_data(FILENAME)
|
||||
x = transform(x)
|
||||
x = format(x)
|
||||
log_lambda = []
|
||||
for _ in range(128):
|
||||
for index in range(128):
|
||||
random.seed(datetime.datetime.now().timestamp()+index)
|
||||
(train_x, train_y), (val_x, val_y) = new_split(x, y)
|
||||
prob = problem(train_y, train_x)
|
||||
|
||||
|
||||
@ -52,7 +52,33 @@ def new_split(x, y):
|
||||
|
||||
return folds
|
||||
|
||||
def transform(features):
|
||||
output_features = []
|
||||
for index, feature in enumerate(features):
|
||||
output_features.append([ 0 for _ in range(84) ])
|
||||
output_features[index][0] = 1
|
||||
|
||||
d_index = 1
|
||||
# 1-order
|
||||
for i in feature:
|
||||
output_features[index][d_index] = i
|
||||
d_index += 1
|
||||
|
||||
# 2-orde
|
||||
for i in range(len(feature)):
|
||||
for j in range(i, len(feature)):
|
||||
output_features[index][d_index] = feature[i]*feature[j]
|
||||
d_index += 1
|
||||
# 3-order
|
||||
for i in range(len(feature)):
|
||||
for j in range(i, len(feature)):
|
||||
for k in range(j, len(feature)):
|
||||
output_features[index][d_index] = i*j*k
|
||||
d_index += 1
|
||||
return output_features
|
||||
|
||||
x, y = read_data(FILENAME)
|
||||
x = transform(x)
|
||||
x = format(x)
|
||||
log_lambda = []
|
||||
lambda_powers = [-6, -4, -2, 0, 2]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user