<jupyter_start><jupyter_text>GoGet Recommendation System<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import classification_report, confusion_matrix
from sklearn.metrics import roc_curve, roc_auc_score
import seaborn as sns<jupyter_output><empty_output><jupyter_text>Reading the Data<jupyter_code>data = pd.read_csv('/home/dhanush/Downloads/Test_dataset_3.csv')<jupyter_output><empty_output><jupyter_text>Printing the first 5 entries<jupyter_code>data.head()<jupyter_output><empty_output><jupyter_text>Printing the information of the Dataset<jupyter_code>data.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 100 entries, 0 to 99
Data columns (total 5 columns):
 #   Column       Non-Null Count  Dtype  
---  ------       --------------  -----  
 0   Shop Name    100 non-null    object 
 1   Avalability  100 non-null    int64  
 2   Distance     100 non-null    float64
 3   Rating       100 non-null    float64
 4   Total bill   100 non-null    int64  
dtypes: float64(2), int64(2), object(1)
memory usage: 4.0+ KB<jupyter_text>To understand the range of each rating, a bargraph is plotted.<jupyter_code>rating_counts = data.Rating.value_counts()
plt.figure(figsize=(20,5))
sns.barplot(x=rating_counts.index, y=rating_counts.values, palette="Oranges")
plt.xlabel("Rating value")
plt.ylabel("Counts")
plt.title("Most Common Rating Counts");<jupyter_output><empty_output><jupyter_text>To understand the Availability, another bargraph is plotted.<jupyter_code>Availability_counts = data.Avalability.value_counts()
plt.figure(figsize=(20,5))
sns.barplot(x=Availability_counts.index, y=Availability_counts.values, palette="Greens")
plt.xlabel("Avalability")
plt.ylabel("Counts")
plt.title("Availability Counts");
#Converting the dataframe into a list.
df = data.values.tolist()
#Finding the median of the Total Bill across the shops.
total_bill = []
for i in range(len(df)):
    if(df[i][1]==1):
        total_bill.append(df[i][4])
median = sorted(total_bill)[len(total_bill)//2]
print("Median is "+str(median))        
#Calculating Final score using the GoGet formula.
for i in range(len(df)):
  fs = 0
  d=0
  if(df[i][1]==1):
      if(df[i][4]<=median):
        d = 5//(df[i][2])
        fs = df[i][3] *20+ (median - df[i][4]) + d
        df[i].append(fs)  
      else:
        d = 5//(df[i][2])
        fs = df[i][3] *20 + (median - df[i][4])  +d
        df[i].append(fs)  
  else:
      df[i].append(0) 
dataset = pd.DataFrame(df, columns = ['Shop_name', 'Availability','Distance','Rating','Total_bill','Final_score'])<jupyter_output><empty_output><jupyter_text>Printing the new dataset along with the Final score<jupyter_code>dataset.head()
dataset.info()
df = dataset.values.tolist()<jupyter_output><empty_output><jupyter_text>Assigning classes to each shop based on the Final score.<jupyter_code>for i in range(len(df)):
    if(df[i][5]>=100):
        df[i].append('1')
    elif(80<=df[i][5]<100):
        df[i].append('2')
    elif(60<=df[i][5]<80):
        df[i].append('3')
    elif(40<=df[i][5]<60):
        df[i].append('4')
    elif(0<=df[i][5]<40):
        df[i].append('5')    
dataset = pd.DataFrame(df, columns = ['Shop_name', 'Availability','Distance','Rating','Total_bill','Final_score','Class'])
dataset.head()
X=dataset.iloc[:,5:-1].values
y=dataset.iloc[:, 6].values<jupyter_output><empty_output><jupyter_text>Performing train test split on the dataset.<jupyter_code>X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.4, random_state=60)<jupyter_output><empty_output><jupyter_text>Preprocessing the dataset using StandardScaler.<jupyter_code>scaler = StandardScaler()
scaler.fit(X_train)
X_train = scaler.transform(X_train)
X_test = scaler.transform(X_test)<jupyter_output><empty_output><jupyter_text>Applying KNN algorithm<jupyter_code>classifier = KNeighborsClassifier(n_neighbors=5)
classifier.fit(X_train,y_train)
#Calculating y_pred
y_pred = classifier.predict(X_test)
#Finding the Accuracy, precision, recall, f1-score and support
print(classification_report(y_test, y_pred))
#Printing multiclass confusion matrix
print(confusion_matrix(y_test, y_pred))
rec = []
final = dataset.values.tolist()
final.sort(key = lambda x: x[5], reverse=True)<jupyter_output><empty_output><jupyter_text>Top 10 recommendations using GoGet Recommendation System<jupyter_code>for i in range(0,10):
    print(final[i])<jupyter_output>['Pacchu Kiraani Stores', 1, 4.9, 4.7, 180, 110.0, '1']
['Sri laxmi stores', 1, 0.6, 4.7, 190, 107.0, '1']
["Babanna's Shop", 1, 0.8, 4.7, 190, 105.0, '1']
['Karnataka General\xa0STORE', 1, 0.7, 4.8, 195, 103.0, '1']
['shobha store', 1, 1.4, 4.6, 190, 100.0, '1']
['Shhravan Grocery\xa0Store', 1, 4.5, 4.6, 188, 100.0, '1']
['SPB store', 1, 2.9, 4.8, 194, 98.0, '2']
['Shri Gurusai Stores', 1, 1.3, 4.9, 198, 98.0, '2']
['S.N.M Stores', 1, 4.1, 4.8, 195, 97.0, '2']
['Ragavendra provision store', 1, 3.3, 4.4, 188, 96.0, '2']
{'fraction_non_alphanumeric': 0.15888215751416845, 'fraction_numerical': 0.0480750439710768, 'mean_word_length': 5.15884476534296, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '212215', 'license': 'MIT', 'n_tokens_mistral': 2119, 'n_tokens_neox': 1913, 'n_words': 401, 'path': 'goget_knn.ipynb', 'repo_name': 'achyuth13/GoGet---Notebook', 'size': '5117'}