le.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:AliMusicTrendPredict 作者: strint 项目源码 文件源码
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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号