-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscatter_plot.py
More file actions
65 lines (55 loc) · 1.73 KB
/
scatter_plot.py
File metadata and controls
65 lines (55 loc) · 1.73 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import csv
import ml_functions as ml
import matplotlib.pyplot as plt
csvfile = open('assets/dataset_train.csv')
rawdata = list(csv.reader(csvfile))
# Features: modify indexFeatures according to the dataset
indexFeatures = 6
lenFeatures = len(rawdata[0]) - indexFeatures
features = [] * lenFeatures
for i in range(len(rawdata[0]) - indexFeatures):
features.append(rawdata[0][i + indexFeatures])
marks = []
stds = []
# Get data
for i in range(lenFeatures):
marks.append([])
del rawdata[0]
for row in rawdata:
if ml.isFormatted(row):
for i in range(lenFeatures):
marks[i].append(float(row[i + indexFeatures]))
# Get stats
for i in range(lenFeatures):
minV, maxV = ml.getMinMax(marks[i])
marks[i] = ml.normalizeData(marks[i], minV, maxV)
mean = ml.getMean(marks[i])
stds.append(ml.getStd(marks[i], mean))
# Compare values
i1 = 0
i2 = 1
j1 = 0
j2 = 1
for i in range(lenFeatures):
for j in range(lenFeatures):
if stds[i] != stds[j]:
if abs(stds[i] - stds[j]) < abs(stds[i1] - stds[i2]):
i1 = i
i2 = j
elif abs(stds[i] - stds[j] > abs(stds[j1] - stds[j2])):
j1 = i
j2 = j
print('The most identical features are:', features[i1], 'and', features[i2])
print('The most different features are:', features[j1], 'and', features[j2])
# Plot
plt.figure(1)
plt.title('The most identical features')
plt.scatter(marks[i1], marks[i2], color=['blue', 'green'])
plt.xlabel(features[i1], fontsize=16)
plt.ylabel(features[i2], fontsize=16)
plt.figure(2)
plt.title('The most different features')
plt.scatter(marks[j1], marks[j2], color=['blue', 'green'])
plt.xlabel(features[j1], fontsize=16)
plt.ylabel(features[j2], fontsize=16)
plt.show()