# Notebook from iatal/RCTvsBurden
Path: .ipynb_checkpoints/A.2- Mapping health research effort - creating replicates-checkpoint.ipynb

Mapping health research effort
-------------------------------------
Database:
          1. All RCTs registered at WHO ICTRP by Jan 1st 2016,
          2. with start date between 2006 and 2015
          3. with study type and design corresponding to RCT
          4. with at least one country location among the 187 countries included in the GBD2010 study

We will:
          1. Create replicates of the mapping of RCTs across diseases_____no_output_____

#Upload database: not included in the repository
data <- read.table("/media/igna/Elements/HotelDieu/Cochrane/MappingRCTs_vs_Burden/database_RCTs_regions_27diseases.txt")
names(data)

#Upload traduction names/label categories 27 groups of diseases
Mgbd <- read.table("Data/27_gbd_groups.txt")_____no_output_____

- TrialID: unique trial ID from WHOICTRP
- Regions: 7 epidemiological regions from GBD 2010 study
- GBD27: classification according to 27 categories defined in Atal et al. BMC Bioinformatics (2016): This classification do not include injuries (names of groups of diseases included in database Mgbd)_____no_output_____## 2- Estimation of number RCTs per region and disease

For each disease, we simulate what would have been the mapping of RCTs within regions if the misclassification of RCTs towards groups of diseases was corrected, given the sensitivities and specificities of the classifier to identify each group of disease.

To estimate the performances of the classifier for each group of diseases, we dispose a test set with 2,763 trials manually classified towards the 27-class grouping of diseases used in this work. The test set is described at Atal et al. BMC Bioinformatics 2016.

The method used is based on the method presented at Fox et al. Int J Epidemiol 2005.

To do so, for each disease we will:

1. Doing N=10k times the following simulation
    * Randomly choose a sens and spec based on beta distribution for identifying the disease and identifying another disease (no correlation between sens and spec, neither between disease and another disease both)
    * Derive Positive and Negative Predictive Values (PPV and NPV) for each.
    * Simulate the correction of the classification based on PPVs and NPVs
    * Save the replicated mappings
3. Next step is to measure Nb RCTs, Local proportion RCTs, Nb Patients, etc, in replicated mappings

Replicated mappings are saved in a_____no_output_____### Construction of replicates_____no_output_____

Lgbd <- lapply(as.character(data$GBD27),function(x){as.numeric(unlist(strsplit(x,"&")))})_____no_output_____PERF <- read.csv('Tables/Performances_per_27disease_data.csv')_____no_output_____NK <- 10000
set.seed(7212)_____no_output_____#For all diseases
t0 <- proc.time()
g<- 0
PERF_g <- PERF[PERF$dis==0,]
dir.create(paste("/media/igna/Elements/HotelDieu/Cochrane/MappingRCTs_vs_Burden/Replicates/",as.character(PERF_g$dis),sep=""))

    #which trials are relevant to the burden
    is_dis <- sapply(Lgbd,length)==1

    #PPV et NPVs for finding the disease
    sens_r <- PERF_g$TP_Dis
    sens_n <- PERF_g$TP_Dis + PERF_g$FN_Dis
    spec_r <- PERF_g$TN_Dis
    spec_n <- PERF_g$TN_Dis + PERF_g$FP_Dis
    sens <- rbeta(NK,sens_r+1,sens_n-sens_r+1)
    spec <- rbeta(NK,spec_r+1,spec_n-spec_r+1)
    write.table(data.frame(sens=sens,spec=spec),
                paste(c("/media/igna/Elements/HotelDieu/Cochrane/MappingRCTs_vs_Burden/Replicates/",
                        as.character(PERF_g$dis),"/Sens_spec.txt"),collapse=""))

    a_dis <- sum(is_dis)
    b_dis <- N-a_dis
    As <- (a_dis-(1-spec)*N)/(sens - (1-spec))
    Bs <- N-As
    T1 <- sens*As
    T0 <- spec*Bs
    F1 <- (1-spec)*Bs
    F0 <- (1-sens)*As
    PPV_dis <- T1/(T1+F1)
    NPV_dis <- T0/(T0+F0)

    false_it <- PPV_dis<0 | PPV_dis>1 |
                NPV_dis<0 | NPV_dis>1

    print(paste(c(g,"has",sum(false_it),"suppressed false iterations"
                                                    ),collapse=" "))

    PPV_dis <- PPV_dis[!false_it]
    NPV_dis <- NPV_dis[!false_it]

    #Simulation: reclassifying each trial
        for(k in 1:length(PPV_dis)){

            tp_dis <- runif(a_dis)
            tn_dis <- runif(b_dis)
            recl_dis <- is_dis
            recl_dis[recl_dis==TRUE][tp_dis>PPV_dis[k]] <- FALSE
            recl_dis[recl_dis==FALSE][tn_dis>NPV_dis[k]] <- TRUE
            write.table(data.frame(recl_dis=as.numeric(recl_dis)),
                        paste(c("/media/igna/Elements/HotelDieu/Cochrane/MappingRCTs_vs_Burden/Replicates/",
                                as.character(PERF_g$dis),"/Reclassification_",
                                "_",k,".txt"),collapse=""),row.names=FALSE)

            }

t1 <- proc.time()-t0
t1/60
Warning message in dir.create(paste("/media/igna/Elements/HotelDieu/Cochrane/Mapping_Cancer/Incertitude_mapping/Replicates/", :
“'/media/igna/Elements/HotelDieu/Cochrane/Mapping_Cancer/Incertitude_mapping/Replicates/0' already exists”#For all diseases, we will simulate the mapping across regions of trials concerning
#the disease or concerning other diseases
dis <- 1:27_____no_output_____
#For each disease
t0 <- proc.time()

for(g in dis){

    PERF_g <- PERF[PERF$dis==g,]
    dir.create(paste("/media/igna/Elements/HotelDieu/Cochrane/MappingRCTs_vs_Burden/Replicates/",as.character(PERF_g$dis),sep=""))

    #which trials concern the disease
    is_dis <- sapply(Lgbd,function(x){g%in%x})
    #which trials concern another disease
    is_oth <- sapply(Lgbd,function(x){sum(setdiff(1:27,g)%in%x)>0})

    #PPV et NPVs for finding the disease
    sens_r <- PERF_g$TP_Dis
    sens_n <- PERF_g$TP_Dis + PERF_g$FN_Dis
    spec_r <- PERF_g$TN_Dis
    spec_n <- PERF_g$TN_Dis + PERF_g$FP_Dis
    sens <- rbeta(NK,sens_r+1,sens_n-sens_r+1)
    spec <- rbeta(NK,spec_r+1,spec_n-spec_r+1)
    Dss <- data.frame(sens_dis=sens,spec_dis=spec)

    a_dis <- sum(is_dis)
    b_dis <- N-a_dis
    As <- (a_dis-(1-spec)*N)/(sens - (1-spec))
    Bs <- N-As
    T1 <- sens*As
    T0 <- spec*Bs
    F1 <- (1-spec)*Bs
    F0 <- (1-sens)*As
    PPV_dis <- T1/(T1+F1)
    NPV_dis <- T0/(T0+F0)

    #PPV and NPVs for finding another disease
    sens_r <- PERF_g$TP_Oth
    sens_n <- PERF_g$TP_Oth + PERF_g$FN_Oth
    spec_r <- PERF_g$TN_Oth
    spec_n <- PERF_g$TN_Oth + PERF_g$FP_Oth
    sens <- rbeta(NK,sens_r+1,sens_n-sens_r+1)
    spec <- rbeta(NK,spec_r+1,spec_n-spec_r+1)
    Dss$sens_oth <- sens
    Dss$spec_oth <- spec

    a_oth <- sum(is_oth)
    b_oth <- N-a_oth
    As <- (a_oth-(1-spec)*N)/(sens - (1-spec))
    Bs <- N-As
    T1 <- sens*As
    T0 <- spec*Bs
    F1 <- (1-spec)*Bs
    F0 <- (1-sens)*As
    PPV_oth <- T1/(T1+F1)
    NPV_oth <- T0/(T0+F0)

    write.table(Dss,
                paste(c("/media/igna/Elements/HotelDieu/Cochrane/MappingRCTs_vs_Burden/Replicates/",
                        as.character(PERF_g$dis),"/Sens_spec.txt"),collapse=""))

    #Some values of sens and spec may lead to impossible values of PPV or NPV (>1 or <0)
    #We supress and count them. If the total of suppressed iterations is higher than 10% of total iterations we
    #will modify the distributions for Specificity and Sensitivity
    false_it <- PPV_dis<0 | PPV_dis>1 |
                NPV_dis<0 | NPV_dis>1 |
                PPV_oth<0 | PPV_oth>1 |
                NPV_oth<0 | NPV_oth>1

    print(paste(c(g,"has",sum(false_it),"suppressed false iterations"
                                                    ),collapse=" "))

    PPV_dis <- PPV_dis[!false_it]
    NPV_dis <- NPV_dis[!false_it]
    PPV_oth <- PPV_oth[!false_it]
    NPV_oth <- NPV_oth[!false_it]

    L <- list()
    #Simulation: reclassifying each trial
        for(k in 1:length(PPV_dis)){

            tp_dis <- runif(a_dis)
            tn_dis <- runif(b_dis)
            recl_dis <- is_dis
            recl_dis[recl_dis==TRUE][tp_dis>PPV_dis[k]] <- FALSE
            recl_dis[recl_dis==FALSE][tn_dis>NPV_dis[k]] <- TRUE
            rt <- as.numeric(recl_dis)

            #Oth_dis
            tp_oth <- runif(a_oth)
            tn_oth <- runif(b_oth)
            recl_oth <- is_oth
            recl_oth[recl_oth==TRUE][tp_oth>PPV_oth[k]] <- FALSE
            recl_oth[recl_oth==FALSE][tn_oth>NPV_oth[k]] <- TRUE

            write.table(data.frame(recl_dis=as.numeric(recl_dis),recl_oth=as.numeric(recl_oth)),
                        paste(c("/media/igna/Elements/HotelDieu/Cochrane/MappingRCTs_vs_Burden/Replicates/",
                                as.character(PERF_g$dis),"/Reclassification_",
                                "_",k,".txt"),collapse=""),row.names=FALSE)

        }
}

t1 <- proc.time()

print(t1-t0)/60Warning message in dir.create(paste("/media/igna/Elements/HotelDieu/Cochrane/Mapping_Cancer/Incertitude_mapping/Replicates/", :
“'/media/igna/Elements/HotelDieu/Cochrane/Mapping_Cancer/Incertitude_mapping/Replicates/1' already exists”

It took 13h_____no_output_____

# Diseases with more than 10% of suppressed iterations:
Mgbd$cause_name[c(9,11,21,23,27)]_____no_output_____

We will re-simulate only for diseases corresponding to more than 1% of local burden in a region_____no_output_____


# Notebook from Dream74/coursera-ml-py
Path: machine-learning-ex8/ex8/ex8_cofi.ipynb

<code>
import matplotlib.pyplot as plt
import numpy as np
import scipy.io as scio
import scipy.optimize as opt

import cofiCostFunction as ccf
import checkCostFunction as cf
import loadMovieList as lm
import normalizeRatings as nr
_____no_output_____
plt.ion()
np.set_printoptions(formatter={'float': '{: 0.6f}'.format})_____no_output_____# ===================== Part 1: Loading movie ratings dataset =====================
# We will start by loading the movie ratings dataset to understand the
# structure of the data
print('Loading movie ratings dataset.')

# Load data
data = scio.loadmat('ex8_movies.mat')
Y = data['Y']
R = data['R']

# Y is a 1682 x 943 2-d ndarray, containing ratings 1-5 of 1682 movies on 943 users
#
# R is a 1682 x 943 2-d ndarray, where R[i, j] = 1 if and only if user j gave a
# rating to movie iLoading movie ratings dataset.
# From the matrix, we can compute statistics like average rating.
print('Average ratings for movie 0(Toy Story): {:0.6f}/5'.format(np.mean(Y[0, np.where(R[0] == 1)])))Average ratings for movie 0(Toy Story): 3.878319/5
# We can visualize the ratings matrix by plotting it with plt.imshow
plt.figure(figsize=(20, 10))
plt.imshow(Y)
plt.colorbar()
plt.xlabel('Users')
plt.ylabel('Movies')_____no_output_____# ===================== Part 2: Collaborative Filtering Cost function =====================
# You will now implement the cost function for collaborative filtering.
# To help you debug your cost function, we have included set of weights
# that we trained on that. Specifically, you should complete the code in
# cofiCostFunc.py to return cost.
#

# Load pre-trained weights (X, theta, num_users, num_movies, num_features)
data = scio.loadmat('ex8_movieParams.mat')
X = data['X']
theta = data['Theta']
num_users = data['num_users'][0,0]
num_movies = data['num_movies'][0,0]
num_features = data['num_features'][0,0]_____no_output_____# Reduce the data set size so that this runs faster
num_users = 4
num_movies = 5
num_features = 3
X = X[0:num_movies, 0:num_features]
theta = theta[0:num_users, 0:num_features]
Y = Y[0:num_movies, 0:num_users]
R = R[0:num_movies, 0:num_users]_____no_output_____lmd = 1.5_____no_output_____def cofi_cost_function(params, Y, R, num_users, num_movies, num_features, lmd):
    X = params[0:num_movies * num_features].reshape((num_movies, num_features))
    theta = params[num_movies * num_features:].reshape((num_users, num_features))

    # You need to set the following values correctly.
    cost = 0
    X_grad = np.zeros(X.shape)
    theta_grad = np.zeros(theta.shape)

    # ===================== Your Code Here =====================
    # Instructions: Compute the cost function and gradient for collaborative
    #               filtering. Concretely, you should first implement the cost
    #               function (without regularization) and make sure it is
    #               matches our costs. After that, you should implement the
    #               gradient and use the checkCostFunction routine to check
    #               that the gradient is correct. Finally, you should implement
    #               regularization.
    #
    # Notes: X - num_movies x num_features matrix of movie features
    #        theta - num_users x num_features matrix of user features
    #        Y - num_movies x num_users matrix of user ratings of movies
    #        R - num_movies x num_users matrix, where R[i, j] = 1 if the
    #        i-th movie was rated by the j-th user
    #
    # You should set the following variables correctly
    #
    #        X_grad - num_movies x num_features matrix, containing the
    #                 partial derivatives w.r.t. to each element of X
    #        theta_grad - num_users x num_features matrix, containing the
    #                     partial derivatives w.r.t. to each element of theta

    cost = np.sum(np.power(((theta @ X.T).T - Y) * R, 2)) / 2 + lmd * np.sum(np.power(theta, 2)) / 2 + lmd * np.sum(np.power(X, 2)) / 2
    theta_grad += (((theta @ X.T).T - Y) * R).T @ X + lmd * theta
    X_grad += (((theta @ X.T).T - Y) * R) @ theta + lmd * X
    # ==========================================================

    grad = np.concatenate((X_grad.flatten(), theta_grad.flatten()))

    return cost, grad
_____no_output_____# Evaluate cost function
cost, grad = cofi_cost_function(np.concatenate((X.flatten(), theta.flatten())), Y, R, num_users, num_movies, num_features, 0)

print('Cost at loaded parameters: {:0.2f}\n(this value should be about 22.22)'.format(cost))
Cost at loaded parameters: 22.22
(this value should be about 22.22)
import computeNumericalGradient as cng

def check_cost_function(lmd):

    # Create small problem
    x_t = np.random.rand(4, 3)
    theta_t = np.random.rand(5, 3)

    # Zap out most entries
    Y = np.dot(x_t, theta_t.T)  # 4x5
    Y[np.random.rand(Y.shape[0], Y.shape[1]) > 0.5] = 0
    R = np.zeros(Y.shape)
    R[Y != 0] = 1

    # Run Gradient Checking
    x = np.random.randn(x_t.shape[0], x_t.shape[1])
    theta = np.random.randn(theta_t.shape[0], theta_t.shape[1])
    num_users = Y.shape[1]  #5
    num_movies = Y.shape[0]  #4
    num_features = theta_t.shape[1] #3

    def cost_func(p):
        return cofi_cost_function(p, Y, R, num_users, num_movies, num_features, lmd)

    numgrad = cng.compute_numerial_gradient(cost_func, np.concatenate((x.flatten(), theta.flatten())))

    cost, grad = cofi_cost_function(np.concatenate((x.flatten(), theta.flatten())), Y, R, num_users, num_movies, num_features, lmd)

    print(np.c_[numgrad, grad])
    print('The above two columns you get should be very similar.\n'
          '(Left-Your Numerical Gradient, Right-Analytical Gradient')

    diff = np.linalg.norm(numgrad - grad) / np.linalg.norm(numgrad + grad)
    print('If you backpropagation implementation is correct, then\n'
          'the relative difference will be small (less than 1e-9).\n'
          'Relative Difference: {:0.3e}'.format(diff))
_____no_output_____
# ===================== Part 3: Collaborative Filtering Gradient =====================
# Once your cost function matches up with ours, you should now implement
# the collaborative filtering gradient function. Specifically, you should
# complete the code in cofiCostFunction.py to return the grad argument.
#
print('Checking gradients (without regularization) ...')

# Check gradients by running check_cost_function()
check_cost_function(0)
Checking gradients (without regularization) ...
[[ 0.000000  0.000000]
 [ 0.000000  0.000000]
 [ 0.000000  0.000000]
 [-0.447814 -0.447814]
 [-3.590314 -3.590314]
 [ 0.241702  0.241702]
 [-0.609969 -0.609969]
 [-1.148636 -1.148636]
 [-1.011890 -1.011890]
 [-4.527463 -4.527463]
 [-4.725949 -4.725949]
 [ 6.679027  6.679027]
 [ 0.000000  0.000000]
 [ 0.000000  0.000000]
 [ 0.000000  0.000000]
 [-0.349269 -0.349269]
 [-0.105882 -0.105882]
 [-0.397356 -0.397356]
 [-2.504598 -2.504598]
 [-3.321788 -3.321788]
 [ 1.698649  1.698649]
 [ 2.472884  2.472884]
 [ 5.991712  5.991712]
 [-3.734202 -3.734202]
 [-0.514222 -0.514222]
 [-0.155889 -0.155889]
 [-0.585021 -0.585021]]
The above two columns you get should be very similar.
(Left-Your Numerical Gradient, Right-Analytical Gradient
If you backpropagation implementation is correct, then
the relative difference will be small (less than 1e-9).
Relative Difference: 1.131e-12
# ===================== Part 4: Collaborative Filtering Cost Regularization =====================
# Now, you should implement regularization for the cost function for
# collaborative filtering. You can implement it by adding the cost of
# regularization to the original cost computation.
#

# Evaluate cost function
cost, _ = cofi_cost_function(np.concatenate((X.flatten(), theta.flatten())), Y, R, num_users, num_movies, num_features, 1.5)

print('Cost at loaded parameters (lambda = 1.5): {:0.2f}\n'
      '(this value should be about 31.34)'.format(cost))Cost at loaded parameters (lambda = 1.5): 31.34
(this value should be about 31.34)
# ===================== Part 5: Collaborative Filtering Gradient Regularization =====================
# Once your cost matches up with ours, you should proceed to implement
# regularization for the gradient.
#

print('Checking Gradients (with regularization) ...')

# Check gradients by running check_cost_function
check_cost_function(1.5)
Checking Gradients (with regularization) ...
[[ 9.027049  9.027049]
 [ 8.191003  8.191003]
 [ 10.550557  10.550557]
 [ 2.710384  2.710384]
 [-1.123058 -1.123058]
 [-0.186470 -0.186470]
 [ 4.620906  4.620906]
 [ 3.330302  3.330302]
 [ 2.367734  2.367734]
 [ 7.272687  7.272687]
 [ 3.154981  3.154981]
 [ 8.516820  8.516820]
 [-3.452637 -3.452637]
 [-0.886003 -0.886003]
 [-0.921775 -0.921775]
 [-23.658376 -23.658376]
 [-16.581323 -16.581323]
 [-15.657283 -15.657283]
 [-0.536484 -0.536484]
 [-1.167359 -1.167359]
 [ 1.348195  1.348195]
 [-3.082133 -3.082133]
 [ 0.585631  0.585631]
 [ 0.327981  0.327981]
 [-6.462416 -6.462416]
 [-5.635479 -5.635479]
 [-4.761054 -4.761054]]
The above two columns you get should be very similar.
(Left-Your Numerical Gradient, Right-Analytical Gradient
If you backpropagation implementation is correct, then
the relative difference will be small (less than 1e-9).
Relative Difference: 1.617e-12

# ===================== Part 6: Entering ratings for a new user =====================
# Before we will train the collaborative filtering model, we will first
# add ratings that correspond to a new user that we just observed. This
# part of the code will also allow you to put in your own ratings for the
# movies in our dataset!
#
movie_list = lm.load_movie_list()

# Initialize my ratings
my_ratings = np.zeros(len(movie_list))

# Check the file movie_ids.txt for id of each movie in our dataset
# For example, Toy Story (1995) has ID 0, so to rate it "4", you can set
my_ratings[0] = 4

# Or suppose did not enjoy Silence of the lambs (1991), you can set
my_ratings[97] = 2

# We have selected a few movies we liked / did not like and the ratings we
# gave are as follows:
my_ratings[6] = 3
my_ratings[11] = 5
my_ratings[53] = 4
my_ratings[63] = 5
my_ratings[65] = 3
my_ratings[68] = 5
my_ratings[182] = 4
my_ratings[225] = 5
my_ratings[354] = 5

print('New user ratings:\n')
for i in range(my_ratings.size):
    if my_ratings[i] > 0:
        print('Rated {} for {}'.format(my_ratings[i], movie_list[i]))
New user ratings:

Rated 4.0 for Toy Story (1995)
Rated 3.0 for Twelve Monkeys (1995)
Rated 5.0 for Usual Suspects, The (1995)
Rated 4.0 for Outbreak (1995)
Rated 5.0 for Shawshank Redemption, The (1994)
Rated 3.0 for While You Were Sleeping (1995)
Rated 5.0 for Forrest Gump (1994)
Rated 2.0 for Silence of the Lambs, The (1991)
Rated 4.0 for Alien (1979)
Rated 5.0 for Die Hard 2 (1990)
Rated 5.0 for Sphere (1998)
# ===================== Part 7: Learning Movie Ratings =====================
# Now, you will train the collaborative filtering model on a movie rating
# dataset of 1682 movies and 943 users
#
print('Training collaborative filtering ...\n'
      '(this may take 1 ~ 2 minutes)')

# Load data
data = scio.loadmat('ex8_movies.mat')
Y = data['Y']
R = data['R']

# Y is a 1682x943 matrix, containing ratings (1-5) of 1682 movies by
# 943 users
#
# R is a 1682x943 matrix, where R[i,j] = 1 if and only if user j gave a
# rating to movie i

# Add our own ratings to the data matrix
Y = np.c_[my_ratings, Y]
R = np.c_[(my_ratings != 0), R]

# Normalize Ratings
Ynorm, Ymean = nr.normalize_ratings(Y, R)

# Useful values
num_users = Y.shape[1]
num_movies = Y.shape[0]
num_features = 10

# Set initial parameters (theta, X)
X = np.random.randn(num_movies, num_features)
theta = np.random.randn(num_users, num_features)

initial_params = np.concatenate([X.flatten(), theta.flatten()])

lmd = 10

def cost_func(p):
    return cofi_cost_function(p, Ynorm, R, num_users, num_movies, num_features, lmd)[0]

def grad_func(p):
    return cofi_cost_function(p, Ynorm, R, num_users, num_movies, num_features, lmd)[1]

theta, *unused = opt.fmin_cg(cost_func, fprime=grad_func, x0=initial_params, maxiter=100, disp=False, full_output=True)

# Unfold the returned theta back into U and W
X = theta[0:num_movies * num_features].reshape((num_movies, num_features))
theta = theta[num_movies * num_features:].reshape((num_users, num_features))

print('Recommender system learning completed')
print(theta)Training collaborative filtering ...
(this may take 1 ~ 2 minutes)
Recommender system learning completed
[[-0.093326  0.017588  0.048143 ... -0.217078  0.173830  0.094081]
 [-0.506476 -0.023157  0.038491 ... -0.066189 -0.220251  0.484453]
 [-0.019166 -0.066165  0.157813 ... -0.190447 -0.333667 -0.150314]
 ...
 [ 0.095642  0.086436  0.016858 ... -0.135651  0.114671  0.083226]
 [ 0.210220  0.075431  0.097506 ... -0.648584  0.000629 -0.137795]
 [ 0.402208  0.357737 -0.100483 ...  0.184523  0.320367  0.745397]]
# ===================== Part 8: Recommendation for you =====================
# After training the model, you can now make recommendations by computing
# the predictions matrix.
#
p = np.dot(X, theta.T)
my_predictions = p[:, 0] + Ymean

indices = np.argsort(my_predictions)[::-1]
print('\nTop recommendations for you:')
for i in range(10):
    j = indices[i]
    print('Predicting rating {:0.1f} for movie {}'.format(my_predictions[j], movie_list[j]))

print('\nOriginal ratings provided:')
for i in range(my_ratings.size):
    if my_ratings[i] > 0:
        print('Rated {} for {}'.format(my_ratings[i], movie_list[i]))

Top recommendations for you:
Predicting rating 5.0 for movie Star Kid (1997)
Predicting rating 5.0 for movie They Made Me a Criminal (1939)
Predicting rating 5.0 for movie Santa with Muscles (1996)
Predicting rating 5.0 for movie Aiqing wansui (1994)
Predicting rating 5.0 for movie Entertaining Angels: The Dorothy Day Story (1996)
Predicting rating 5.0 for movie Saint of Fort Washington, The (1993)
Predicting rating 5.0 for movie Prefontaine (1997)
Predicting rating 5.0 for movie Great Day in Harlem, A (1994)
Predicting rating 5.0 for movie Someone Else's America (1995)
Predicting rating 5.0 for movie Marlene Dietrich: Shadow and Light (1996)

Original ratings provided:
Rated 4.0 for Toy Story (1995)
Rated 3.0 for Twelve Monkeys (1995)
Rated 5.0 for Usual Suspects, The (1995)
Rated 4.0 for Outbreak (1995)
Rated 5.0 for Shawshank Redemption, The (1994)
Rated 3.0 for While You Were Sleeping (1995)
Rated 5.0 for Forrest Gump (1994)
Rated 2.0 for Silence of the Lambs, The (1991)
Rated 4.0 for Alien (1979)
Rated 5.0 for Die Hard 2 (1990)
Rated 5.0 for Sphere (1998)

</code>