Ejemplo n.º 1
0
 def add_data(self, env_id):
     """
     Start a data generation process.
     """
     self.data.append(
         DataProcess(self.experience_q[env_id], env_id, len(self.data)))
     self.data[-1].start()
Ejemplo n.º 2
0
 def __init__(self, process=DataProcess()):
     self.model = load_model('./seq2seq_keras.h5')
     self.process = process
     self.PAD_INDEX = 0
     self.STA_INDEX = 1
     self.END_INDEX = 2
     self.UNK_INDEX = 3
     self.max_sequences = 60
     self.ENCODER_INPUT = 0
Ejemplo n.º 3
0
 def load_data(self):
     mydata = DataProcess(self.img_rows, self.img_cols)
     imgs_train, imgs_mask_train = mydata.load_train_data()
     imgs_test = mydata.load_test_data()
     return imgs_train, imgs_mask_train, imgs_test
Ejemplo n.º 4
0
                    hit += 1
            recall += len(tu)
            precision += N
            # print((hit / (recall * 1.0),hit / (precision * 1.0)))
        return (hit / (recall * 1.0), hit / (precision * 1.0))


if __name__ == "__main__":
    N = 10

    # 输入的数据集
    totalData = './ml-100k/u.data'  # dataset
    trainFile = './ml-100k/u1.base'  # train_set
    testFile = './ml-100k/u1.test'  # test_set

    data = DataProcess(totalData)
    trainData = DataProcess(trainFile)
    testData = DataProcess(testFile)
    userCF = UserCFPearson(data, trainData, testData)
    # According to the training set and test set, the test
    # result set of predicting test result is obtained,
    # which is the same as the number of rows of test result set.

    # Calculate model accuracy based on test set and prediction result set
    # rmse, mae = userCF.calRmseAndMae(K)
    # print('rmse: %1.5f\t mae: %1.5f' % (rmse, mae))
    TopN, _ = userCF.recommendation(userID=123, N=10, K=10)

    i = 1
    print('userID = 123, N = 10, K = 10')
Ejemplo n.º 5
0
from unet import *
from data import DataProcess

mydata = DataProcess(512,512)

imgs_test = mydata.load_test_data()

myunet = myUnet()

model = myunet.get_unet()

model.load_weights('unet.hdf5')

imgs_mask_test = model.predict(imgs_test, verbose=1)

np.save('imgs_mask_test.npy', imgs_mask_test)
        return precision, recall, coverage, popularity

    def idToTitle(self, movieID, data):
        for index, row in data.iterrows():
            if movieID == row['MovieID']:
                return row['MovieTitle']


if __name__ == '__main__':
    # 输入的数据集
    totalData = './ml-100k/u.data'  #总数据集
    trainFile = './ml-100k/u1.base'  #训练集
    testFile = './ml-100k/u1.test'  #测试集

    data = DataProcess(totalData)
    trainData = DataProcess(trainFile)
    testData = DataProcess(testFile)
    ItemCF = ItemBasedCF(trainData, testData)
    movie_df = data.getMovies()

    N = 10
    recd = ItemCF.Recommendation(userID=123, K=10, N=10)
    i = 1
    print("userID=123,K=10,N=10")
    for key in recd.items():
        print("Top: ", i, ItemCF.idToTitle(key[0], movie_df))
        i += 1

    print("%5s%5s%20s%20s%20s%20s" %
          ('K', 'N', 'precision(%)', "recall(%)", 'coverage(%)', 'popularity'))
Ejemplo n.º 7
0
def run(user_question, seq2seq=Seq2seq(), proc=DataProcess()):
    pro_sent = proc.prepocess_sentence(user_question)
    txt_to_idx = seq2seq.convert_text_to_index(pro_sent, proc.word2idx)
    pred = seq2seq.predict_model()
    sentence = seq2seq.idx_to_sentence(txt_to_idx, pred)
    return sentence_spacing(sentence)
Ejemplo n.º 8
0
def run(userID, method):
    # 输入的数据集
    totalData = './ml-100k/u.data'  # 总数据集
    trainFile = './ml-100k/u1.base'  # 训练集
    testFile = './ml-100k/u1.test'  # 测试集

    # 参数  #用户ID
    K = 5  # K为选取相邻用户个数
    N = 5  # 推荐没有接触过的物品的个数
    threshold = 4  # 评分阀值

    data = DataProcess(totalData)
    trainData = DataProcess(trainFile)
    testData = DataProcess(testFile)

    if method == 'userbased-pearson':
        #userBased - pearson
        userCF = UserCFPearson(data, trainData, testData)

        # 根据训练集和测试集,得到预测试结果的测结果集,和测试集结果的行数一样
        # 根据测试集和预测结果集,计算模型精确度
        # rmse, mae = userCF.calRmseAndMae(K)
        # print('rmse: %1.5f\t mae: %1.5f' % (rmse, mae))
        TopN, recommend_list = userCF.recommendation(userID, N, K)
        trainDict = userCF.classifyMovie(trainData)
        testDict = userCF.classifyMovie(testData)

        i = 1
        for line in TopN:
            print("top", i, ": ", line)
            i += 1

        # 测算recall 和 precision
        # print("%5s%5s%20s%20s" % ('K', 'N', "recall", 'precision'))
        # K 选取临近的用户数量
        # N 输出推荐电影的数量
        for k in [5, 10, 20, 40, 80, 160]:
            for n in [5, 10, 15, 20]:
                recall, precision = userCF.recallAndPrecision(k, n)
                # print("%5d%5d%19.3f%%%19.3f%%" % (k,n,recall * 100,precision * 100))

        return 0

    elif method == 'userbased-euclidean':
        userCF = UserCFEuclidean(data, trainData, testData)
        TopN, _ = userCF.predict(userID, N, threshold)
        precision = userCF.evaluation(N)

        i = 1
        for line in TopN:
            print("top", i, ": ", line[1][1], "\t", line[1][0])
            i += 1

        return 0

    elif method == 'itembased':
        #itemBased - 余弦函数
        ItemCF = ItemBasedCF(data, trainData, testData)
        TopN, _, recommend_list = ItemCF.Recommendation(userID, K, N)

        i = 1
        for line in TopN:
            print("top", i, ": ", line)
            i += 1

        # 测算recall 和 precision
        print("%5s%5s%20s%20s" % ('K', 'N', "recall", 'precision'))
        # K 选取临近的用户数量
        # N 输出推荐电影的数量
        for k in [5, 10, 20, 40, 80, 160]:
            for n in [10]:
                recall, precision = ItemCF.recallAndPrecision(k, n)
                # print("%5d%5d%19.3f%%%19.3f%%" % (k,n,recall * 100,precision * 100))
        return 0

    elif method == 'exit':
        return 0
    else:
        return 1

    print("-------------Completed!!-----------")
            return precision, recall, cover, popular
        else:
            recall = self.Recall(train_set, test_set, N, K)
            precision = self.Precision(train_set, test_set, N, K)
            cover = self.Coverage(train_set, test_set, N, K, all_item)
            popular = self.Popularity(train_set, test_set, N, K,
                                      item_popularity)
        return precision, recall, cover, popular

    def xxx(self):
        a = self.Precision(self.trainMovieDict, self.testMovieDict, 5, 10, 1)
        return a


if __name__ == "__main__":
    data = DataProcess('./ml-100k/u.data')
    trainData = DataProcess('./ml-100k/u1.base')
    testData = DataProcess('./ml-100k/u1.test')

    trainLr = trainData.merge_lrRating_movies()
    trainX = trainLr[[
        'UserID', 'MovieID', 'Age', 'Gender', 'Occupation', 'ZipCode'
    ]]
    trainY = trainLr['Rating']

    testLr = testData.merge_lrRating_movies()
    testX = testLr[[
        'UserID', 'MovieID', 'Age', 'Gender', 'Occupation', 'ZipCode'
    ]]
    testY = testLr['Rating']