<jupyter_start><jupyter_text>Loading data  Checkins<jupyter_code>checkins = pd.read_csv("./data/checkins.dat", delimiter='|', skiprows=[1], skipfooter=2, skipinitialspace = True, engine="python")
checkins.columns = checkins.columns.str.replace(' ', '')
checkins.replace(regex=r'^\s*$', value=np.nan, inplace=True)
checkins.dropna(inplace=True)
display(checkins)<jupyter_output><empty_output><jupyter_text>Company coords<jupyter_code>company_coords = pd.read_csv("./data/company_coords.csv")
display(company_coords)<jupyter_output><empty_output><jupyter_text>Clustering  Training<jupyter_code>X = checkins[["latitude", "longitude"]].iloc[:100000, :]
%%time

ms = MeanShift(bandwidth=0.1)
ms.fit(X)<jupyter_output>CPU times: user 2min 31s, sys: 438 ms, total: 2min 32s
Wall time: 2min 32s<jupyter_text>Analyzing<jupyter_code>print(f"Number of clusters: {len(set(ms.labels_))}")
n = 1500
labels_of_big_clusters = [k for k, v in dict(Counter(ms.labels_)).items() if v > n]
print(f"Number of clusters bigger {n}: {len(labels_of_big_clusters)}")

for label in labels_of_big_clusters:
    plt.scatter(X[ms.labels_ == label]["latitude"], X[ms.labels_ == label]["longitude"])
plt.show()<jupyter_output>Number of clusters bigger 1500: 9<jupyter_text>Finding most close ones  extracting biggest cluster centers<jupyter_code>n = 15
labels_of_big_clusters = [k for k, v in dict(Counter(ms.labels_)).items() if v > n]
print(f"Number of clusters bigger {n}: {len(labels_of_big_clusters)}")

cluster_centers = pd.DataFrame(ms.cluster_centers_[labels_of_big_clusters], columns=X.columns)
display(cluster_centers)<jupyter_output>Number of clusters bigger 15: 592<jupyter_text>calculating distances to offices<jupyter_code>distances = []

for cluster_center_index, cluster_center in cluster_centers.iterrows():
    for company_index, company in company_coords.iterrows():
        distances.append({
            "latitude": cluster_center["latitude"],
            "longitude": cluster_center["longitude"],
            "distance": np.linalg.norm(np.array([cluster_center["latitude"], cluster_center["longitude"]]) -  np.array([company["latitude"], company["longitude"]])),
            "city": company["city"]
        })
        
distances = pd.DataFrame(distances)
distances.sort_values(by="distance", inplace=True)
display(distances.iloc[:20])
display(company_coords)<jupyter_output><empty_output><jupyter_text>Writing answer<jupyter_code>answer = distances.iloc[0]
with open("./output/ans.txt", "w") as f:
    f.write(f"{answer['latitude']} {answer['longitude']}")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15106796116504853, 'fraction_numerical': 0.015922330097087378, 'mean_word_length': 7.151898734177215, 'pattern_counts': {'":': 4, '<': 26, '<?xml version=': 0, '>': 28, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '556244', 'license': 'MIT', 'n_tokens_mistral': 948, 'n_tokens_neox': 907, 'n_words': 149, 'path': 'UnsupervisedLearning/1.Clustering/BannersPlacement.ipynb', 'repo_name': 'SmirnovAlexander/MachineLearningDataAnalysis', 'size': '2575'}