# Feature Selection algorithm for a high featured data

I have a cancer patient database from mass spectrometry on patients which consists of more than half million features. My task is to apply a feature selection algorithm to extract the most relevant features from it. My question is, which feature selection model would be the most appropriate in this case? Any suggestion from practical experience for these types of data is appreciated.

• Half million features or half million images or data points? – Adnan S Mar 2 '18 at 8:12

Have you tried any possibilities?

You have many possible approaches.

FeatureMiner (http://featureselection.asu.edu/index.php) or SkLearn (https://scikit-learn.org/) are popular options for your purposes.

The documentation from these two possibilities is also interesting.

You may be mixing the concept of features with data granularity. Scan data after post processing is usually a cube of discrete density averages indexed by the three dimensions $$x$$, $$y$$, and $$z$$ corresponding to the standard directional references used in medicine. Features refer to what is extracted from those density readings, indicating concentrated angiogenesis or other indicators of concurrent failed apoptosis and t-cell activation.

Even if there are $$n$$ regions of potentially cancerous mass, there may only be $$9n$$ features. Each of $$n$$ regions may have features such as this list.

• x center
• y center
• z center
• x width
• y width
• z width
• max density
• margin distance
• margin entropy

If there are two types of scans, there would be a flag to differentiate an MRI density from PET with contrast density, for example.

I think maybe you can use this GLCM matrix code:

import cv2
import numpy as np
import sys
import math

class GLCM:
def __init__(self, image, dy, dx):
self.image = image
self.dy = dy
self.dx = dx
self.glcm = self.GLCMcount()
self.kontras, self.meanI, self.meanJ, self.energy, self.homogenity = self.contrast()
self.taoI, self.taoJ = self.tao()
self.korelasion = self.correlation()

def GLCMcount(self):
height, width = self.image.shape[:2]
glcm = np.zeros((256, 256, 3), np.double)
x = 0
for i in range(height):
for j in range(width):
if i + self.dy in range(height) and j + self.dx in range(width):
glcm[self.image[i, j, 0], self.image[i +
self.dy, j + self.dx, 0], 0] += 1
glcm[self.image[i, j, 1], self.image[i +
self.dy, j + self.dx, 1], 1] += 1
glcm[self.image[i, j, 2], self.image[i +
self.dy, j + self.dx, 2], 2] += 1
# print str(image[i,j,0]) + " " + str(image[i+dy,j+dx,0]) + "
# " + str(glcm[image[i,j,0],image[i+dy,j+dx,0],0])
x += 1
glcm = glcm / x
return glcm

def contrast(self):
contrast = np.zeros(3, np.float)
meanI = np.zeros(3, np.float)
meanJ = np.zeros(3, np.float)
energy = np.zeros(3, np.float)
homogenity = np.zeros(3, np.float)
for i in range(256):
for j in range(256):
contrast += pow(i - j, 2) * self.glcm[i, j, 0]
contrast += pow(i - j, 2) * self.glcm[i, j, 1]
contrast += pow(i - j, 2) * self.glcm[i, j, 2]
meanI += i * self.glcm[i, j, 0]
meanI += i * self.glcm[i, j, 1]
meanI += i * self.glcm[i, j, 2]
meanJ += j * self.glcm[i, j, 0]
meanJ += j * self.glcm[i, j, 1]
meanJ += j * self.glcm[i, j, 2]
energy += pow(self.glcm[i, j, 0], 2)
energy += pow(self.glcm[i, j, 1], 2)
energy += pow(self.glcm[i, j, 2], 2)
homogenity += self.glcm[i, j, 0] / (1 + abs(i - j))
homogenity += self.glcm[i, j, 1] / (1 + abs(i - j))
homogenity += self.glcm[i, j, 2] / (1 + abs(i - j))
return contrast, meanI, meanJ, energy, homogenity

def correlation(self):
correlation = np.zeros(3, np.float)
for i in range(256):
for j in range(256):
correlation += ((i - self.meanI) * (j - self.meanJ)
* self.glcm[i, j, 0]) / (self.taoI * self.taoJ)
correlation += ((i - self.meanI) * (j - self.meanJ)
* self.glcm[i, j, 1]) / (self.taoI * self.taoJ)
correlation += ((i - self.meanI) * (j - self.meanJ)
* self.glcm[i, j, 2]) / (self.taoI * self.taoJ)
# print correlation;
return correlation

def tao(self):
taoI = np.zeros(3, np.float)
taoJ = np.zeros(3, np.float)
for i in range(256):
for j in range(256):
taoI += pow(i - self.meanI, 2) * self.glcm[i, j, 0]
taoI += pow(i - self.meanI, 2) * self.glcm[i, j, 1]
taoI += pow(i - self.meanI, 2) * self.glcm[i, j, 2]
taoJ += pow(j - self.meanJ, 2) * self.glcm[i, j, 0]
taoJ += pow(j - self.meanJ, 2) * self.glcm[i, j, 1]
taoJ += pow(j - self.meanJ, 2) * self.glcm[i, j, 2]
# print str(taoJ)+" = "+ str(pow(j-meanJ,2)) + " x " + str(glcm[i,j,2])
# print "taoi = "
# print taoI
# print "taoj = "
# print taoJ
for i in range(3):
taoI[i] = math.sqrt(taoI[i])
taoJ[i] = math.sqrt(taoJ[i])
return taoI, taoJ

def printglcm(self):

print ("meanI = " + str(rgb2gs(self.meanI)))
print ("meanJ = " + str(rgb2gs(self.meanJ)))
print ("taoI = " + str(rgb2gs(self.taoI)))
print ("taoJ = " + str(rgb2gs(self.taoJ)))
print ("kontras = " + str(rgb2gs(self.kontras)))
print ("Energy = " + str(rgb2gs(self.energy)))
print ("Homogenitas = " + str(rgb2gs(self.homogenity)))
print ("Correlation = " + str(rgb2gs(self.korelasion)))

def writeglcm(self):
with open("test.txt", "a") as myfile:
myfile.write(str(rgb2gs(self.kontras)) + " " + str(rgb2gs(self.energy)) + " " +
str(rgb2gs(self.homogenity)) + " " + str(rgb2gs(self.korelasion)) + "\n")
with open("type.txt", "a") as myfile:
myfile.write(str(1) + ",\n")

def rgb2gs(rgb):
val = 0.114 * (rgb) + 0.587 * (rgb) + 0.299 * (rgb)
return val

if __name__ == '__main__':
glcm = GLCM(image, 0, 1)
imglcm = glcm.glcm.astype(np.uint8)
glcm.printglcm()
glcm.writeglcm()

# kontras, meanI, meanJ, energy, homogenity = contrast(glcm)
# taoI, taoJ = tao(glcm, meanI, meanJ)
# korelasion = correlation(glcm, meanI, meanJ, taoI, taoJ)
# print "meanI = " + str(rgb2gs(glcm.meanI))
# print "meanJ = " + str(rgb2gs(glcm.meanJ))
# print "taoI = " + str(rgb2gs(glcm.taoI))
# print "taoJ = " + str(rgb2gs(glcm.taoJ))
# print "kontras = " + str(rgb2gs(glcm.kontras))
# print "Energy = " + str(rgb2gs(glcm.energy))
# print "Homogenitas = " + str(rgb2gs(glcm.homogenity))
# print "Correlation = " + str(rgb2gs(glcm.korelasion))
# print glcm

# cv2.imshow("testing", imglcm)
# cv2.waitKey(0)
# cv2.destroyAllWindows()


It gives you meanI,meanJ,taoI,taoJ,contrast,Energy,Homogeneity,Correlation.

• Could you add a paragraph to describe what this class is doing and how it should be used? – DrMcCleod Dec 29 '18 at 10:03