Spaces:
Sleeping
Sleeping
Update utils.py
Browse filesBorro parte de versiones y direccion de donde tomar matriz y modelo
utils.py
CHANGED
@@ -10,56 +10,11 @@ from sklearn.metrics.pairwise import cosine_similarity
|
|
10 |
from joblib import dump, load
|
11 |
from sklearn.preprocessing import normalize
|
12 |
|
13 |
-
# def get_latest_version(base_filename):
|
14 |
-
# """
|
15 |
-
# Obtiene la 煤ltima versi贸n del archivo guardado.
|
16 |
-
# Args:
|
17 |
-
# base_filename (str): Nombre base del archivo (sin versi贸n)
|
18 |
-
# Returns:
|
19 |
-
# str: Nombre del archivo con la versi贸n m谩s reciente
|
20 |
-
# """
|
21 |
-
# # Buscar todos los archivos que coincidan con el patr贸n
|
22 |
-
# pattern = f"{base_filename}_*.joblib"
|
23 |
-
# matching_files = glob.glob(pattern)
|
24 |
-
|
25 |
-
# if not matching_files:
|
26 |
-
# return f"{base_filename}_0001.joblib"
|
27 |
-
|
28 |
-
# # Extraer los n煤meros de versi贸n y encontrar el m谩ximo
|
29 |
-
# versions = []
|
30 |
-
# for file in matching_files:
|
31 |
-
# match = re.search(r'_(\d{4})\.joblib$', file)
|
32 |
-
# if match:
|
33 |
-
# versions.append(int(match.group(1)))
|
34 |
-
|
35 |
-
# if versions:
|
36 |
-
# latest_version = max(versions)
|
37 |
-
# return f"{base_filename}_{latest_version:04d}.joblib"
|
38 |
-
|
39 |
-
# return f"{base_filename}_0001.joblib"
|
40 |
-
|
41 |
-
# def get_next_version(base_filename):
|
42 |
-
# """
|
43 |
-
# Genera el nombre del archivo para la siguiente versi贸n.
|
44 |
-
# Args:
|
45 |
-
# base_filename (str): Nombre base del archivo (sin versi贸n)
|
46 |
-
# Returns:
|
47 |
-
# str: Nombre del archivo con la siguiente versi贸n
|
48 |
-
# """
|
49 |
-
# latest_file = get_latest_version(base_filename)
|
50 |
-
# match = re.search(r'_(\d{4})\.joblib$', latest_file)
|
51 |
-
# if match:
|
52 |
-
# current_version = int(match.group(1))
|
53 |
-
# next_version = current_version + 1
|
54 |
-
# else:
|
55 |
-
# next_version = 1
|
56 |
-
|
57 |
-
# return f"{base_filename}_{next_version:04d}.joblib"
|
58 |
|
59 |
def recomienda_tf(new_basket, cestas, productos):
|
60 |
# Cargar la matriz TF y el modelo
|
61 |
-
tf_matrix = load('
|
62 |
-
count = load('
|
63 |
|
64 |
# Convertir la nueva cesta en formato TF (Term Frequency)
|
65 |
new_basket_str = ' '.join(new_basket)
|
@@ -128,8 +83,8 @@ def retroalimentacion(cestas, cesta_nueva):
|
|
128 |
tf_matrix = normalize(count_matrix, norm='l1')
|
129 |
|
130 |
|
131 |
-
dump(count_vectorizer, '
|
132 |
-
dump(tf_matrix, '
|
133 |
|
134 |
|
135 |
return None
|
|
|
10 |
from joblib import dump, load
|
11 |
from sklearn.preprocessing import normalize
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
def recomienda_tf(new_basket, cestas, productos):
|
15 |
# Cargar la matriz TF y el modelo
|
16 |
+
tf_matrix = load('models/count_matrix_2.joblib')
|
17 |
+
count = load('models/count_vectorizer_2.joblib')
|
18 |
|
19 |
# Convertir la nueva cesta en formato TF (Term Frequency)
|
20 |
new_basket_str = ' '.join(new_basket)
|
|
|
83 |
tf_matrix = normalize(count_matrix, norm='l1')
|
84 |
|
85 |
|
86 |
+
dump(count_vectorizer, 'models/count_vectorizer_final.joblib')
|
87 |
+
dump(tf_matrix, 'models/tf_matrix_final.joblib')
|
88 |
|
89 |
|
90 |
return None
|