I want to combine the extreme learning machine (ELM) algorithm with the LARS algorithm. I adapted the code below for this. Unfortunately I will not be able to share the dataset for data privacy reasons. All other part of the code is below. Any help would be very important to my project. Thank you.
# Normalized DataSet
X_n = (X - X.mean(axis=0, keepdims=True)) / X.std(axis=0, keepdims=True)
y_n = (y - y.mean()) / y.std()
# Dividing the dataset test data using train_test_split.
train_X, test_X, train_y, test_y = train_test_split(X_n, y_n, test_size=0.33, random_state=42)
def sigmoid(x):
return 1.0 / (1.0 + np.exp(-train_X))
input_size = train_X.shape[1]
M_hidden_size = 1000
input_weights = np.random.normal(size=[input_size, M_hidden_size])
biases = np.random.normal(size=[M_hidden_size])
def hidden_nodes(X):
G = np.dot(train_X, input_weights)
G = G + biases
H = sigmoid(G)
return H
H = hidden_nodes(X)
print("Array Dimension = ",len(H.shape)) # Array Dimension = 2
def lars(train_X, train_y):
n, p = train_X.shape
mu = np.zeros_like(train_y)
beta = np.zeros(p)
for _ in range(p):
c = np.dot(train_X.T, (train_y - mu))
c_abs = np.abs(c)
c_max = c_abs.max()
active = np.isclose(c_abs, c_max) # Array Dimension = 2
signs = np.where(c[active] > 0,1,-1) # Array Dimension = 1
H_active = signs * H[:, active] # print("Array Dimension = ",len(H_active.shape))
G = np.dot(H_active.T, H_active)
Ginv = np.linalg.inv(G)
A = Ginv.sum() ** (-0.5)
w = A * Ginv.sum(axis = 1)
u = np.dot(H_active, w)
gamma = c_max / A
if not np.all(active):
a = np.dot(train_X.T, u)
complement = np.invert(active)
cc = c[complement]
ac = a[complement]
candidates = np.concatenate([(c_max - cc) / (A - ac),
(c_max + cc) / (A + ac)])
gamma = candidates[candidates >= 0].min()
mu += gamma * u
beta[active] += gamma * signs
return mu, beta
beta = lars(train_X, train_y).fit
print ('Beta:\n', beta)
Traceback (most recent call last):
File "C:\Users\user\ELM\A.py", line 88, in beta = lars(train_X, train_y).fit
File "C:\Users\user\ELM\A.py", line 64, in lars H_active = signs * H[:, active] # print("Array Dimension = ",len(H_active.shape))
IndexError: too many indices for array: array is 2-dimensional, but 3 were indexed