<jupyter_start><jupyter_text>filtrado colaborativo<jupyter_code>movie_data_ratings_data=movies.merge(ratings,on = 'movieId',how = 'inner')
movie_data_ratings_data.head(3)
movie_data_ratings_data.drop(columns = ['genres'], inplace = True)
movie_data_ratings_data.drop(columns = ['title'], inplace = True)
movie_data_ratings_data
# load the model from disk
import pickle
filename = 'filtrado_colaborativo.sav'
loaded_model = pickle.load(open(filename, 'rb'))
# getting the number unique users and restaurants
unique_users = movie_data_ratings_data.userId.unique().shape[0]
print(unique_users)
unique_restaurants = movie_data_ratings_data.movieId.unique().shape[0]
print(unique_restaurants)
#Create two user-item matrices, one for training and another for testing
unique_users
matrix_all = np.zeros((unique_users, unique_restaurants))
#matrix_all
current_reviews= movie_data_ratings_data[ ["userId","movieId","rating"] ]
current_reviews
current_reviews= movie_data_ratings_data[ ["userId","movieId","rating"] ]
current_reviews['user_id_simple'] = pd.factorize(current_reviews.userId)[0]
current_reviews['movie_id_simple'] = pd.factorize(current_reviews.movieId)[0]
for i in current_reviews.index:
    #print(current_reviews['userId'][i])
    matrix_all[current_reviews['user_id_simple'][i], current_reviews['movie_id_simple'][i]] = current_reviews['rating'][i]
matrix_all
current_reviews
for i in range(0,unique_users):
    user_id = current_reviews.loc[current_reviews.user_id_simple==i].userId.unique()[0]
    for j in range(0, unique_restaurants):
        if matrix_all[i][j] == 0:    
            star2=loaded_model.predict(i, j, r_ui=None, verbose=False)
            matrix_all[i][j] =  int(star2.est)
            #print(star2)

# llena los valores que si calificó el usuario con 0
for i in current_reviews.index:
    #print(current_reviews['userId'][i])
    matrix_all[current_reviews['user_id_simple'][i], current_reviews['movie_id_simple'][i]] = 0
matrix_all<jupyter_output><empty_output><jupyter_text>conectarse a mysql<jupyter_code>!pip install mysql
!pip install mysql.connector
!pip install mysql-connector-python-rf
import mysql.connector
from mysql.connector import errorcode
#Configuración de la conexión a Mysql
try:
  cnx = mysql.connector.connect(user='user_taller3', password='<PASSWORD>.', host='127.0.0.1', database='taller3')
except mysql.connector.Error as err:
  if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
    print("Something is wrong with your user name or password")
  elif err.errno == errorcode.ER_BAD_DB_ERROR:
    print("Database does not exist")
  else:
    print(err)

cursor = cnx.cursor()
sql = "INSERT INTO `recomendations_movies` (`user_id`, `movie_id`, `recomendation_score`) VALUES (%s, %s, %s)"

for i in range(0,unique_users):
    user_id = current_reviews.loc[current_reviews.user_id_simple==i].userId.unique()[0]
    #print(user_id)
    for j in range(0, unique_restaurants):
        if matrix_all[i][j] >=4:    
            for k in current_reviews.index:
                if current_reviews['movie_id_simple'] [k]== j :
                    business_id = current_reviews['movieId'][k]
                    break
            #print(business_id)
            list_rec = recommendations(business_id)
            if len(list_rec) >0:
                for k in list_rec:
                    cursor.execute(sql, (str(user_id),str(k),int(matrix_all[i][j])))
            else:
                cursor.execute(sql, (str(user_id),str(business_id),int(matrix_all[i][j])))
            cnx.commit()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12450815064643057, 'fraction_numerical': 0.007588532883642495, 'mean_word_length': 4.844006568144499, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '225139', 'license': 'Apache-2.0', 'n_tokens_mistral': 1234, 'n_tokens_neox': 1214, 'n_words': 224, 'path': 'modelo/Modelo.ipynb', 'repo_name': 'MINE4201grupo2/sr_taller_3', 'size': '3555'}