I wanted to implement KNN in python. Till now I have loaded my data into Pandas DataFrame.
import pandas as pd
from sklearn.neighbors import KNeighborsClassifier
train_df = pd.read_csv("creditlimit_train.csv") # train dataset
train_df.head()
The output of head is
SNo Salary LoanAmt Level
101 100000 10000 Low Level
102 108500 11176 Low Level
103 125500 13303 Low Level
104 134000 14606 Low Level
105 142500 15960 Low Level
test_df = pd.read_csv("creditlimit_test.csv")
test_df.head()
The output of head is
SNo Salary LoanAmt Level
101 100000 10000 Low Level
102 108500 11176 Low Level
103 125500 13303 Low Level
104 134000 14606 Low Level
105 142500 15960 Low Level
neigh = KNeighborsClassifier(n_neighbors=5,algorithm='auto')
predictor_features = ['Salary','LoanAmt']
dependent_features = ['Level']
neigh.fit(train_df[predictor_features],train_df[dependent_features])
How do I use the fit function to use salary,loanAmt as predictor to predict the levels for my test_df?
Update 1: The levels are 3 : Low, Medium and High