<jupyter_start><jupyter_text>kNN model on kaggle-pet competition DATA LOADING<jupyter_code>import pandas as pd
import numpy as np
import os
os.listdir('../../data')
assert 'out_breed.csv' in os.listdir('../../data') # this assert breaks if the data is configured uncorrectly
breeds = pd.read_csv('../../data/out_breed.csv')
colors = pd.read_csv('../../data/out_color.csv')
states = pd.read_csv('../../data/out_state.csv')
train  = pd.read_csv('../../data/out_train.csv')
test   = pd.read_csv('../../data/out_test.csv')
sub    = pd.read_csv('../../data/out_submission.csv')<jupyter_output><empty_output><jupyter_text>MODEL<jupyter_code>from knnDogs20 import PredictiveModel as DogPredictiveModel
from knnCats14 import PredictiveModel as CatPredictiveModel<jupyter_output><empty_output><jupyter_text>EXAMPLE USAGE<jupyter_code>dogs = train[train['Type'] == 1].drop('Type',axis=1)
dogs_test = test[test['Type'] == 1].drop('Type',axis=1)
X_dogs = dogs.reset_index().drop(['index'],axis=1)
Y_dogs = dogs.reset_index()['AdoptionSpeed']
X_test_dogs = dogs_test.reset_index().drop(['index'],axis=1)

cats = train[train['Type'] == 2].drop('Type',axis=1)
cats_test = test[test['Type'] == 2].drop('Type',axis=1)
X_cats = cats.reset_index().drop(['index'],axis=1)
Y_cats = cats.reset_index()['AdoptionSpeed']
X_test_cats = cats_test.reset_index().drop(['index'],axis=1)
dog_model = DogPredictiveModel("submission_knn")
cat_model = CatPredictiveModel("submission_knn")
dog_model.train(X_dogs, Y_dogs)
cat_model.train(X_cats, Y_cats)
dog_predictions = dog_model.predict(X_test_dogs)
cat_predictions = cat_model.predict(X_test_cats)
assert len(dog_predictions)
assert len(cat_predictions)
len(dog_predictions) + len(cat_predictions) == len(test)
dog_map = pd.DataFrame(dog_predictions).set_index(X_test_dogs['PetID'])
dog_inplace_predictions = test['PetID'].map(dict(dog_map[0]))
cat_map = pd.DataFrame(cat_predictions).set_index(X_test_cats['PetID'])
cat_inplace_predictions = test['PetID'].map(dict(cat_map[0]))
predictions = np.fmax(cat_inplace_predictions, dog_inplace_predictions)
predictions.head()<jupyter_output><empty_output><jupyter_text>VALIDATION<jupyter_code>dogs = train[train['Type'] == 1].drop('Type',axis=1)
X_dogs = dogs.reset_index().drop(['index'],axis=1)
Y_dogs = dogs.reset_index()['AdoptionSpeed']

cats = train[train['Type'] == 2].drop('Type',axis=1)
X_cats = cats.reset_index().drop(['index'],axis=1)
Y_cats = cats.reset_index()['AdoptionSpeed']
dog_model = DogPredictiveModel("submission_knn")
dog_model.validation(X_dogs, Y_dogs, method=1, verbose=True)
dog_model.validation(X_dogs, Y_dogs, method=2, verbose=True)
cat_model = CatPredictiveModel("submission_knn")
cat_model.validation(X_cats, Y_cats, method=1, verbose=True)
cat_model.validation(X_cats, Y_cats, method=2, verbose=True)<jupyter_output>Fri Mar 22 18:02:46 2019 [submission_knn.validation] start validation method 2
Fri Mar 22 18:02:46 2019 [submission_knn.validation] single score = 0.15667216562844055 
Fri Mar 22 18:02:46 2019 [submission_knn.validation] single score = 0.14963211772232887 
Fri Mar 22 18:02:47 2019 [submission_knn.validation] single score = 0.12761381288086993 
Fri Mar 22 18:02:47 2019 [submission_knn.validation] single score = 0.1454680774774545 
Fri Mar 22 18:02:47 2019 [submission_knn.validation] single score = 0.12650523626047505 
Fri Mar 22 18:02:47 2019 [submission_knn.validation] validation score = 0.14117828199391377 
Fri Mar 22 18:02:47 2019 [submission_knn.validation] finished validation method 2<jupyter_text>Public LB score<jupyter_code>0.211<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15189520624303232, 'fraction_numerical': 0.06605351170568562, 'mean_word_length': 7.950124688279302, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '293455', 'license': 'MIT', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1330, 'n_words': 216, 'path': 'models/KNN/submissions.ipynb', 'repo_name': 'ferrucc-io/kaggle-pets', 'size': '3588'}