<jupyter_start><jupyter_text>Content-Based Recommender Systems Nearest Neighbors Algorithm<jupyter_code>import pandas as pd
import numpy as np
import sklearn
from sklearn.neighbors import NearestNeighbors<jupyter_output><empty_output><jupyter_text>*mtcars dataset source:* <NAME> Velleman (1981), Building multiple regression models interactively. Biometrics, 37, 391–411.<jupyter_code>cars = pd.read_csv("/content/mtcars.csv")
cars.columns = ['car_names', 'mpg', 'cyl', 'disp', 'hp', 'drat', 'wt', 'qsec', 'vs', 'am', 'gear', 'carb']
cars.head()<jupyter_output><empty_output><jupyter_text>Below variable t is specification of the car which means that the user wants the car that has 15 mpg, 3.2 tons of weight, displacement size of 300 and 160 horsepower.<jupyter_code>t = [15, 300, 160, 3.2]
x = cars.loc[:,("mpg","disp", "hp", "wt")].values
x[0:5]
nbrs = NearestNeighbors(n_neighbors=1).fit(x)
result = nbrs.kneighbors([t])
print(result)<jupyter_output>(array([[10.77474942]]), array([[22]]))<jupyter_text>The index 22 is the recommendation.  Showing the car details of index 22<jupyter_code>cars.loc[result[1][0]]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14908456843940715, 'fraction_numerical': 0.046207497820401046, 'mean_word_length': 7.763358778625954, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '537346', 'license': 'MIT', 'n_tokens_mistral': 472, 'n_tokens_neox': 414, 'n_words': 104, 'path': 'CarRecommendation.ipynb', 'repo_name': 'Maze-lol/Recommendation', 'size': '1154'}