Python Laplacian Score Feature Selection: Code with Explanation and Optimization
Importing necessary libraries
from lp_score import * import argparse as aP import numpy as np import time
Defining a function to parse command line arguments
def ArgumenParser(): parser = aP.ArgumentParser(description='Parse the Command line arguments') parser.add_argument('-f', action='store', dest='DataSet', default='IRIS.csv') parser.add_argument('-k', action='store', dest='neighbour_size', type=int, default=16) parser.add_argument('-t', action='store', dest='t_param', type=int, default=2) return parser.parse_args()
if name == 'main': # Starting the timer start_time = time.time() # Parsing the command line arguments param = ArgumenParser() # Loading the data X = np.loadtxt(param.DataSet, delimiter=',') n_samples, n_feature = X.shape # Separating the features and the target variable data = X[:, 0:n_feature - 1] # Calculating Laplacian Score L = LaplacianScore(data, neighbour_size=param.neighbour_size, t_param=param.t_param) # Ranking the features using Laplacian Score print(L) print(feature_ranking(L)) # Printing the time taken to execute the program print('--- %s seconds ---' % (time.time() - start_time))
原文地址: http://www.cveoy.top/t/topic/m5A5 著作权归作者所有。请勿转载和采集!