<jupyter_start><jupyter_text>Task1<jupyter_code>n = 0
totals = [0.0, 0.0, 0.0, 0.0]
for i in xrange(len(data_train_v)):
    if len(data_train_p[i]) > 0:
        n += 1        
        
        n_recommended = 1#min(1, len(set(data_train_v[i])))           
        recommended = get_recommended(data_train_v[i], v_train, n_recommended)
        #recommended = get_recommended2(data_train_v[i], v_train_sorted, n_recommended)
        totals[0] += get_recall(recommended, data_train_p[i], n_recommended)
        totals[1] += get_precision(recommended, data_train_p[i], n_recommended)
        
        n_recommended = 5#min(5, len(set(data_train_v[i])))
        recommended = get_recommended(data_train_v[i], v_train, n_recommended)
        #recommended = get_recommended2(data_train_v[i], v_train_sorted, n_recommended)
        totals[2] += get_recall(recommended, data_train_p[i], n_recommended)
        totals[3] += get_precision(recommended, data_train_p[i], n_recommended)
print totals       
res = ' '.join(['%.2f' % (total / float(n)) for total in totals])
print n
print res
out('task1.txt', res)<jupyter_output>[1593.5746142746127, 1842.0, 2973.8075480075486, 766.6000000000226]
3608
0.44 0.51 0.82 0.21<jupyter_text>Task2<jupyter_code>n = 0
totals = [0.0, 0.0, 0.0, 0.0]
for i in xrange(len(data_train_v)):
    if len(data_test_p[i]) > 0:
        n += 1        
        
        n_recommended = 1 #min(1, len(set(data_test_v[i])))           
        recommended = get_recommended(data_test_v[i], v_train, n_recommended)
        #recommended = get_recommended2(data_test_v[i], v_train_sorted, n_recommended)
        totals[0] += get_recall(recommended, data_test_p[i], n_recommended)
        totals[1] += get_precision(recommended, data_test_p[i], n_recommended)
        
        n_recommended = 5 #min(5, len(set(data_test_v[i])))
        recommended = get_recommended(data_test_v[i], v_train, n_recommended)
        #recommended = get_recommended2(data_test_v[i], v_train_sorted, n_recommended)
        totals[2] += get_recall(recommended, data_test_p[i], n_recommended)
        totals[3] += get_precision(recommended, data_test_p[i], n_recommended)
print totals       
res = ' '.join(['%.2f' % (total / float(n)) for total in totals])
print res
out('task2.txt', res)<jupyter_output>[1512.0742063492055, 1746.0, 2922.6248531868896, 1628.350000000019]
0.41 0.48 0.80 0.44<jupyter_text>Task3<jupyter_code>n = 0
totals = [0.0, 0.0, 0.0, 0.0]
for i in xrange(len(data_train_p)):
    if len(data_train_p[i]) > 0:
        n += 1        
        
        n_recommended = 1# min(1, len(set(data_train_v[i])))           
        recommended = get_recommended(data_train_v[i], p_train, n_recommended)
        totals[0] += get_recall(recommended, data_train_p[i], n_recommended)
        totals[1] += get_precision(recommended, data_train_p[i], n_recommended)
        
        n_recommended = 5#min(5, len(set(data_train_v[i])))
        recommended = get_recommended(data_train_v[i], p_train, n_recommended)
        totals[2] += get_recall(recommended, data_train_p[i], n_recommended)
        totals[3] += get_precision(recommended, data_train_p[i], n_recommended)
print totals       
res = ' '.join(['%.2f' % (total / float(n)) for total in totals])
print res
out('task3.txt', res)<jupyter_output><empty_output><jupyter_text>Task4<jupyter_code>n = 0
totals = [0.0, 0.0, 0.0, 0.0]
for i in xrange(len(data_test_p)):
    if len(data_test_p[i]) > 0:
        n += 1        
        
        n_recommended = min(1, len(set(data_test_v[i])))           
        recommended = get_recommended(data_test_v[i], p_train, n_recommended)
        totals[0] += get_recall(recommended, data_test_p[i], n_recommended)
        totals[1] += get_precision(recommended, data_test_p[i], n_recommended)
        
        n_recommended = min(5, len(set(data_test_v[i])))
        recommended = get_recommended(data_test_v[i], p_train, n_recommended)
        totals[2] += get_recall(recommended, data_test_p[i], n_recommended)
        totals[3] += get_precision(recommended, data_test_p[i], n_recommended)
print totals       
res = ' '.join(['%.2f' % (total / float(n)) for total in totals])
print res
out('task4.txt', res)
data_test_p[0]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13789846517119245, 'fraction_numerical': 0.05407319952774498, 'mean_word_length': 3.696230598669623, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '68690', 'license': 'Apache-2.0', 'n_tokens_mistral': 1847, 'n_tokens_neox': 1657, 'n_words': 274, 'path': 'course5/week4/.ipynb_checkpoints/Recommendations-checkpoint.ipynb', 'repo_name': 'astarostin/MachineLearningSpecializationCoursera', 'size': '4235'}