le.py 文件源码

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

项目:AliMusicTrendPredict 作者: strint 项目源码 文件源码
def predDegs(degree, start_date_rank_list):
    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):
        start_date_rank = start_date_rank_list[j]
        p = artists_play_inday[j]
        p = p[start_date_rank:]
        apcount = [0] * (183 - start_date_rank)
        apdate = range(start_date_rank, 183)
        for i in p:
            apcount[i[1] - start_date_rank] = i[0]

        d_train = np.asarray(apdate)
        c_train = np.asarray(apcount)

        # create matrix versions of these arrays
        D_train = d_train[:, np.newaxis]

        d_future = np.asarray(range(184, 244))
        D_future = d_future[:, np.newaxis]

        model = make_pipeline(PolynomialFeatures(degree[j]), Ridge())
        model.fit(D_train, c_train)
        c_future = model.predict(D_future)

        artist_id = artists_rank_to_id[j]
        for idx in range(0, 60):
            date = rank_to_date[d_future[idx]]
            play_num = int(math.ceil(c_future[idx]))
            if play_num < 0:
                play_num = 0
            row = [artist_id, play_num, date]
            print row
            fpwriter.writerow(row)

    fp.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号