# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
from sklearn.tree import export_text
from sklearn.tree import DecisionTreeClassifier

import pandas as pd

import pickle

from sklearn.cluster import AgglomerativeClustering
# -

with open('..\\data\\processed\\X_scaled.pickle', 'rb') as f:
    X_scaled = pickle.load(f)
f.close()

with open('..\\data\\interim\\X_2018.pickle', 'rb') as f:
    X = pickle.load(f)
f.close()


# # 1. Интерпретация разбиения на разное количество кластеров

def print_inerpretation(n_clusters, X_scaled, X):
    model = AgglomerativeClustering(n_clusters)
    model = model.fit(X_scaled)
    
    estimator = DecisionTreeClassifier(random_state=0)
    estimator.fit(X, model.labels_)
    
    tree_rules = export_text(estimator, feature_names=list(X.columns), max_depth=30)
    print(tree_rules)


# ## 1.1. Если разбить на 2 кластера

print_inerpretation(2, X_scaled, X)

# ## 1.2. Если разбить на 3 кластера

print_inerpretation(3, X_scaled, X)

# ## 1.3. Если разбить на 4 кластера

print_inerpretation(4, X_scaled, X)

# ## 1.4. Если разбить на 5 кластера

print_inerpretation(5, X_scaled, X)

# # 2. Интрепретация группы вузов с аномальными показателями

with open('..\\data\\interim\\IS_OUT.pickle', 'rb') as f:
    IS_OUT = pickle.load(f)
f.close()

estimator = DecisionTreeClassifier(random_state=0)
estimator.fit(X, IS_OUT)

tree_rules = export_text(estimator, feature_names=list(X.columns), max_depth=30)

print(tree_rules)

StarcoderdataJupyterScriptsDedupFiltered