<jupyter_start><jupyter_text>**IMPORT LIBRARIES**<jupyter_code>import numpy as np
import pandas as pd

from sklearn.model_selection import train_test_split, RepeatedStratifiedKFold, GridSearchCV
from sklearn.metrics import f1_score, classification_report, confusion_matrix, ConfusionMatrixDisplay
from sklearn.inspection import permutation_importance

from sklearn.gaussian_process import GaussianProcessClassifier
from sklearn.gaussian_process.kernels import RBF
from sklearn.gaussian_process.kernels import DotProduct
from sklearn.gaussian_process.kernels import Matern
from sklearn.gaussian_process.kernels import RationalQuadratic
from sklearn.gaussian_process.kernels import WhiteKernel

import matplotlib.pyplot as plt

import warnings
warnings.filterwarnings("ignore")<jupyter_output><empty_output><jupyter_text>**IMPORT DATA, TEST/TRAIN SPLIT, SCALE**<jupyter_code>features = pd.read_csv("../data/paris_lille/geometric_features.csv")

X = features.drop(['class'], axis=1)
y = features[['class']].values.flatten()

X_train, X_test, y_train, y_test = train_test_split(X, y)<jupyter_output><empty_output><jupyter_text>**BASELINE GAUSSIAN PROCESS CLASSIFIER**<jupyter_code>gp_model = GaussianProcessClassifier()
gp_model.fit(X_train, y_train)
y_pred = gp_model.predict(X_test)

print(classification_report(y_test, y_pred, digits=3))
print(f1_score(y_test, y_pred, average='micro'))<jupyter_output>precision    recall  f1-score   support

         Barrier      0.727     0.471     0.571        17
           Bench      1.000     0.500     0.667         2
    Bicycle Rack      0.600     0.600     0.600         5
Bicycle Terminal      0.857     0.857     0.857         7
         Bollard      0.838     0.814     0.826        70
        Building      0.000     0.000     0.000        17
           Chair      0.667     1.000     0.800         2
Distribution Box      1.000     0.500     0.667         2
      Floor Lamp      0.900     0.900     0.900        20
          Island      1.000     0.200     0.333         5
Lighting Console      0.838     0.816     0.827        38
        Low Wall      0.750     0.632     0.686        19
      Mobile Car      0.444     0.500     0.471         8
  Mobile Scooter      0.000     0.000     0.000         1
      Mobile Van      1.000     1.000     1.000         1
         Natural      0.917     0.917     0.917        60
  Parked Bicy[...]<jupyter_text>**HYPERPARAMETER TUNING**<jupyter_code>model = GaussianProcessClassifier()

params_grid = dict()
params_grid['kernel'] = [1*RBF(), 1*DotProduct(), 1*Matern(),  1*RationalQuadratic(), 1*WhiteKernel()]
cv = RepeatedStratifiedKFold(n_splits=5, n_repeats=2, random_state=0)
grid_search = GridSearchCV(estimator=model, n_jobs=-1, cv=cv, param_grid=params_grid, scoring='f1_micro')
search_results = grid_search.fit(X_train, y_train)
search_results.best_estimator_
best_model = search_results.best_estimator_
best_model.fit(X_train, y_train)
y_pred = best_model.predict(X_test)

print(classification_report(y_test, y_pred, digits=3))
print(f1_score(y_test, y_pred, average='micro'))<jupyter_output>precision    recall  f1-score   support

         Barrier      0.750     0.529     0.621        17
           Bench      0.000     0.000     0.000         2
    Bicycle Rack      1.000     0.600     0.750         5
Bicycle Terminal      1.000     1.000     1.000         7
         Bollard      0.899     0.886     0.892        70
        Building      1.000     0.353     0.522        17
           Chair      0.067     1.000     0.125         2
Distribution Box      0.500     0.500     0.500         2
      Floor Lamp      0.488     1.000     0.656        20
          Island      1.000     0.200     0.333         5
Lighting Console      0.970     0.842     0.901        38
        Low Wall      0.706     0.632     0.667        19
      Mobile Car      0.571     0.500     0.533         8
  Mobile Scooter      0.000     0.000     0.000         1
      Mobile Van      1.000     1.000     1.000         1
         Natural      0.889     0.933     0.911        60
  Parked Bicy[...]<jupyter_text>**CONFUSION MATRIX**<jupyter_code>cm = confusion_matrix(y_test, y_pred, labels=best_model.classes_)
cmd = ConfusionMatrixDisplay(cm, display_labels=best_model.classes_)

fig = plt.figure(figsize=(20,20))
ax = fig.add_subplot(111)
cmd.plot(ax=ax, xticks_rotation='vertical');

plt.savefig('confusionmatrix_gaussianprocess.png', dpi=600)<jupyter_output><empty_output><jupyter_text>**FEATURE IMPORTANCE**<jupyter_code>results = permutation_importance(best_model, X_test, y_test, scoring='f1_micro')
importance = results.importances_mean
for i,v in enumerate(importance):
    print('Feature: %0d, Score %.5f' % (i,v))
plt.figure(figsize=(25,15))
plt.bar(range(len(results.importances_mean)), results.importances_mean)
plt.xticks(range(len(results.importances_mean)), X.columns)
plt.savefig('featureimportance_gaussianprocess.png', dpi=600)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09416498993963783, 'fraction_numerical': 0.09416498993963783, 'mean_word_length': 2.503171247357294, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '260971', 'license': 'MIT', 'n_tokens_mistral': 1943, 'n_tokens_neox': 1708, 'n_words': 350, 'path': 'lidar_gp.ipynb', 'repo_name': 'UrbanInventories/UrbanInventories', 'size': '4970'}