コード例 #1
0
ファイル: recommendKCos.py プロジェクト: karljackab/Database
grades = func.findGrades(stds, cos)
print("Finish")

# Compute the similarity between every students
print("Getting the similarity between student . . .")
similarity = np.zeros((len(stds), len(stds)))
s_len = len(stds)
for a in range(s_len):
    for b in range(s_len):
        similarity[a][b] = func.getSimilarity(grades[a], grades[b])
print("Finish")

# Predict the cos score of not pass cos for every student
print("Predicting cos score and generate recommend. . .")
pred = func.predict(similarity, grades)

# Generate the top K high score of not pass cos for every student
suggest = func.generate(cos, pred, 30)

# Fill the empty suggest base on K-Means clustering
func.fillEmpty(suggest, pred)
print("Finish")

# Parse the recommend cos with specify semester and K courses
print("Matching the course name . . .")
result = func.parseCurrentCos(stds, suggest, sem, K)
print("Finish")

print("Transfer to csv file . . .")
result = pd.DataFrame(result)
result.to_csv('RS.csv', index=False)
コード例 #2
0
currentCos = func.findCurrentCos(sem)
AutoEncoder = at.AutoEncoder
autoencoder = torch.load('net2.pkl')

# start encode
print('Encoding')
encoded, _ = autoencoder(score)
encoded = encoded.detach().numpy()
# get similarity
print('Getting Similarity')
s_len = len(encoded)
similarity = np.zeros((s_len, s_len))
for a in range(s_len):
    for b in range(s_len):
        if a == b:
            similarity[a][b] = 0
        else:
            similarity[a][b] = func.getSimilarity(encoded[a], encoded[b])

# start predict
score = score.numpy()
pred = func.predict(similarity, score)
# Generate the top K high score of not pass cos for every student
suggest = func.generate(allCos, pred, 50)

# Parse the recommend cos with specify semester and K courses
result = func.parseCurrentCos(stds, suggest, sem, K)

print("Transfer to csv file . . .")
result = pd.DataFrame(result)
result.to_csv('RS_auto_2.csv', index=False)
コード例 #3
0
ファイル: auto_generate.py プロジェクト: leolee0118/csca_db
sem = input('Enter the semester: ')

# parameter
INF = 123.0

# prepare data and model
stds = func.findAllStudent()
allCos = func.findAllCos()
score = func.findGrades(stds, allCos)
score = np.float32(np.nan_to_num(score))
score = torch.FloatTensor(score)
currentCos = func.findCurrentCos(sem)
AutoEncoder = at.AutoEncoder

autoencoder = torch.load('net.pkl')

# start predict
_, decoded = autoencoder(score)
decoded = decoded.detach().numpy()
score = score.numpy()
decoded[score != 0] = -INF
res = func.generate(allCos, decoded, 30)
res = func.parseCurrentCos(stds, res, sem, 10)

# write to file

with open('RS_auto.csv', 'w') as out:
    for se in res:
        temp = se[0] + ',"' + ','.join(se[1:]) + '"'
        print(temp)
        print(temp, file=out)