Python Machine Learning

K-Nearest Neightbors Regression

AgeLoanHousePriceIndex
2540000135
3560000256
4580000231
2020000267
35120000139
5218000150
2395000127
4062000216
60100000139
48220000250
33150000264
New customer Age: 48 has Loan: 142000 House Price Index?

Data raw

Age,Loan,HousePriceIndex
25,40000,135
35,60000,256
45,80000,231
20,20000,267
35,120000,139
52,18000,150
23,95000,127
40,62000,216
60,100000,139
48,220000,250
33,150000,264

Distance function

EuclideanManhattan
$$d(x,y)=\sqrt{\sum\limits_{i=1}^m(x_i-y_i)^2}$$ $$d(x,y)=\sum\limits_{i=1}^m\left|x_i-y_i\right|$$

Calculate KNN manually

AgeLoanHousePriceIndexDistanceRank
25400001351020009
3560000256820008
4580000231620005
202000026712200010
35120000139220002
521800015012400011
2395000127470004
4062000216800007
60100000139420003
48220000250780006
3315000026480001

Standardization

Standard Scaler Min Max Scaler Min Max Mean Scaler Max Abs Scaler
$$Xs=\frac{X-mean}{s.d}$$ $$Xs=\frac{X-min}{max - min}$$ $$Xs=\frac{X-mean}{max - min}$$ $$Xs=\frac{X-mean}{|max|}$$