-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathML-Assignment-4.py
48 lines (31 loc) · 1.19 KB
/
ML-Assignment-4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import pandas as pd
import numpy as np
from sklearn.neighbors import LocalOutlierFactor
from google.colab import drive
drive.mount('/content/drive')
fpath = "/content/drive/My Drive/data/Mall_customers.csv"
dataset = pd.read_csv(fpath) #reading path
dataset #printing
aIncome = data.iloc[:, 3].values
aIncome #printing Annual Income
aMedium = np.median(aIncome)
print('Global Median ', aMedian)
aCutoff = aMedian * 2 # k [1, 4], k = 2
aLower, aUpper = aMedian - aCutoff, aMedian + aCutoff
print('Annual Lower Points and Annual Upper Point', aLower, aUpper)
for income in aIncome:
if (income < aLower or income > Upper):
print(income)
spendingScore = corpus.iloc[:, 4].values
spendingMedian = np.median(spendingScore)
spendingCutoff = spendingMedian * 2
spendingLower, spendingUpper = spendingMedian - spendingCutoff, spendingMedian + spendingCutoff
print('spendingLower & spendingUpper', spendingLower, spendingUpper)
for spending in spendingScore:
if spending < spendingLower or spending > spendingUpper:
print(spending)
vdata = dataset.iloc[:, 2:5].values
print(vdata)
LOF = LocalOutlierFactor(n_neighbors = 2)
result = LOF.fit_predict(data) #Predicting Values LOF
print (result)