def test(degree):
error_rate_of_artist = []
weight_of_artist = []
f_of_artist = []
F = 0.0
for j in range(0, 50):
p = artists_play_inday[j]
apcount = [0] * 184
apdate = range(0, 184)
for i in p:
apcount[i[1]] = i[0]
x = np.asarray(apdate[:122])
x_test = np.asarray(apdate[122:])
X = x[:, np.newaxis]
y = np.asarray(apcount[:122])
y_test_true = np.asarray(apcount[122:])
X_test = x_test[:, np.newaxis]
model = make_pipeline(PolynomialFeatures(degree), Ridge())
model.fit(X, y)
y_test_pred = model.predict(X_test)
error_rate_pow2_sum = 0.0
weight = 0.0
for idx in range(0, len(x_test)):
y_true = y_test_true[idx]
if y_true == 0:
y_true = 1 # deal with divide by zero
error_rate_pow2_sum += (float((int(math.ceil(y_test_pred[idx])) - y_true)) / float(y_true) )**2
weight += y_test_true[idx]
error_rate_j = math.sqrt(error_rate_pow2_sum / float(len(x_test)))
error_rate_of_artist.append(error_rate_j)
weight_j = math.sqrt(weight)
weight_of_artist.append(weight_j)
f_j = (1 - error_rate_j) * weight_j
f_of_artist.append(f_j)
F += f_j
print 'degree', degree
print 'error_rate_of_artist', error_rate_of_artist
print 'weight_of_artist', weight_of_artist
print 'f_of_artist', f_of_artist
print 'F', F
评论列表
文章目录