def pred(degree):
predict_file_path = "./data/mars_tianchi_artist_plays_predict.csv"
fp = open(predict_file_path, 'wb')
fpwriter = csv.writer(fp, delimiter=',', quotechar='"', quoting=csv.QUOTE_NONE)
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)
X = x[:, np.newaxis]
y = np.asarray(apcount)
x_future = np.asarray(range(184, 245))
X_future = x_future[:, np.newaxis]
model = make_pipeline(PolynomialFeatures(degree), Ridge())
model.fit(X, y)
y_future = model.predict(X_future)
artist_id = artists_rank_to_id[j]
for idx in range(0, 61):
date = rank_to_date[x_future[idx]]
play_num = int(math.ceil(y_future[idx]))
if play_num < 0:
play_num = 0
row = [artist_id, play_num, date]
print row
fpwriter.writerow(row)
fp.close()
评论列表
文章目录