<jupyter_start><jupyter_text>Recommendation Systme using AIA Recommendation System combines several computational techniques to select personalized items based on the interests of users and according to the context in which they are inserted. Profile recommendationFor the profile, we use data from user profiles, that is, professions of interest, areas of interest, location and age (for filtering). How?<jupyter_code>import pandas as pd

cols = ['user_id', 'age', 'sex', 'occupation', 'zip_code']
users = pd.read_csv("u.user", names=cols, delimiter="|")
users.head(20).style.background_gradient(cmap='Blues')
import pgeocode

nomi = pgeocode.Nominatim('us')

for index, zipcode in zip(users.index, users["zip_code"]):
  state = nomi.query_postal_code(zipcode)["state_name"]
  users.at[index, 'zip_code'] = state
users.head(15).style.hide_index().background_gradient(cmap='Accent')<jupyter_output><empty_output><jupyter_text>Acrescentando item de verificaçãoAqui acrescentamos uma coluna chamada **is_working**. Ela é usada para verificar se o perfil já tem um trabalho (alocado no mercado de trabalho) ou não.<jupyter_code>users["is_working"] = 'NaN'

for i, occ in zip(users.index, users["occupation"]):
    if occ == "student" or occ == "other":
        users.at[i, "is_working"] = "no"
    else:
        users.at[i, "is_working"] = "yes"
users.head(15).style.hide_index().background_gradient(cmap='Accent')<jupyter_output><empty_output><jupyter_text>Show database<jupyter_code>import seaborn as sns
from matplotlib import pyplot

sns.set_theme(style="darkgrid")<jupyter_output><empty_output><jupyter_text>Profile by occupation<jupyter_code>fig, ax = pyplot.subplots(figsize=(11.7, 8.27))
ax = sns.countplot(y="occupation", data=users)<jupyter_output><empty_output><jupyter_text>Profiles with occupation X Profiles without occupation<jupyter_code>fig, ax = pyplot.subplots(figsize=(11.7, 8.27))
ax = sns.countplot(x="is_working", data=users)<jupyter_output><empty_output><jupyter_text>Profiles by location<jupyter_code>fig, ax = pyplot.subplots(figsize=(11.7, 8.27))
ax = sns.countplot(y="zip_code", data=users)
users = users.dropna()
users_encoder = users.apply(preprocessing.LabelEncoder().fit_transform)
users_encoder.shape<jupyter_output><empty_output><jupyter_text>Recommendation System using KMeans<jupyter_code>kmeans = KMeans(n_clusters=8, init = 'k-means++', max_iter = 500, n_init = 10, random_state = 0)
kmeans.fit(users_encoder[["age", "sex", "occupation", "zip_code"]])
clusters = kmeans.fit_predict(users_encoder[["age", "sex", "occupation", "zip_code"]])
relation = pd.DataFrame(columns=['user_id', 'Cluster'])
index = 0
for user_id, cluster in zip(users_encoder["user_id"], clusters):
    relation.at[index, "user_id"] = user_id 
    relation.at[index, "Cluster"] = cluster

    index += 1<jupyter_output><empty_output><jupyter_text>Clusters by user<jupyter_code>relation.T.head(906)
for index in range(10):
    len_users = relation[relation['Cluster'] == index].shape[0]
    print('Número de usuários (perfis) no Cluster ' + str(index) + ' ----> ', len_users)
kmeans.cluster_centers_
fig, ax = pyplot.subplots(figsize=(11.7, 8.27))
plt.scatter(centers[:, 0], centers[:, 1], c='black', s=200, alpha=0.5);
fig, ax = pyplot.subplots(figsize=(11.7, 8.27))

y_kmeans = kmeans.predict(users_encoder[["age", "sex", "occupation", "zip_code"]])
plt.scatter(users_encoder["age"], users_encoder["zip_code"],  c=y_kmeans, s=40, cmap='viridis')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14905226881102815, 'fraction_numerical': 0.01723147616312464, 'mean_word_length': 7.292857142857143, 'pattern_counts': {'":': 1, '<': 33, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '663206', 'license': 'MIT', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1231, 'n_words': 257, 'path': 'recommendation using kmeans.ipynb', 'repo_name': 'vitorglemos/recommendation-system', 'size': '3482'}