How to train regression model with multiple dataset

The datasets I am working with correspond to individual time series signals. Each signal is unique, with differing total number of data points. here I want to simulate dataset A using dataset B.

dataset A:

dataset B :

Spliting Dataset Code:

x = SmartInsole[:,0:178]
y = Avg[:,0]
y = y.reshape(-1,1)

scaler_x = MinMaxScaler()
scaler_y = MinMaxScaler()
scaler_x.fit(x)
xscale = scaler_x.transform(x)
scaler_y.fit(y)
yscale = scaler_y.transform(y)

X_train, X_test, y_train, y_test = train_test_split(xscale, yscale, test_size=0.25, random_state=2)

The dataset after splitting and normalized:

[0.83974359 0.81818182 0.60264901 0.10457516 0.         0.
 0.         0.         0.         0.66878981 0.7654321  0.77439024
 0.05031447 0.18674699 0.         0.         0.         0.
 0.83892617 0.85620915 0.8590604  0.77852349 0.57236842 0.35333333
 0.         0.         0.         0.05217391 0.6835443  0.85064935
 0.72955975 0.08275862 0.         0.         0.         0.
 0.         0.73758865 0.84868421 0.76923077 0.69230769 0.53472222
 0.53571429 0.65714286 0.49450549 0.47747748 0.72592593 0.77707006
 0.86928105 0.80519481 0.31333333 0.         0.0516129  0.
 0.         0.         0.         0.39316239 0.35036496 0.07086614
 0.38392857 0.57843137 0.58181818 0.68376068 0.74100719 0.84868421
 0.81879195 0.80519481 0.14       0.         0.         0.
 0.         0.         0.83802817 0.89189189 0.88811189 0.48979592
 0.         0.         0.         0.         0.         0.33793103
 0.         0.         0.         0.         0.         0.9929078
 0.97222222 0.81118881 0.45890411 0.         0.         0.
 0.         0.63551402 0.97810219 0.95172414 0.95205479 0.88356164
 0.94630872 0.40384615 0.         0.         0.         0.97222222
 0.9862069  0.96478873 0.76510067 0.52       0.24113475 0.
 0.         0.         0.21568627 0.88970588 0.94594595 0.89864865
 0.08510638 0.37662338 0.0979021  0.         0.         0.
 0.46153846 0.92517007 0.74590164 0.48571429 0.05882353 0.19847328
 0.11428571 0.07857143 0.11510791 0.56375839 0.80794702 0.87012987
 0.81045752 0.21527778 0.         0.         0.         0.
 0.         0.         0.         0.         0.         0.
 0.         0.07042254 0.21052632 0.62745098 0.75471698 0.80503145
 0.78980892 0.         0.         0.         0.         0.
 0.         0.55357143 0.66878981 0.67272727 0.17682927 0.
 0.         0.         0.         0.         0.         0.
 0.         0.         0.         0.        ]
[0.59662633]
(3000, 178)
(3000, 1)

I am working with Keras and trying to fit a resnet50 to the data just to evaluate it. Below is the my renet model structure:

Below is identity blok:

def identity_block(input_tensor,units):
The identity block is the block that has no conv layer at shortcut.
# Arguments
    input_tensor: input tensor
    units:output shape
# Returns
    Output tensor for the block.

x = layers.Dense(units)(input_tensor)
x = layers.BatchNormalization()(x)
x = layers.Activation('relu')(x)

x = layers.Dense(units)(x)
x = layers.BatchNormalization()(x)
x = layers.Activation('relu')(x)

x = layers.Dense(units)(x)
x = layers.BatchNormalization()(x)

x = layers.add([x, input_tensor])
x = layers.Activation('relu')(x)

return x

Below is dens_block:

def dens_block(input_tensor,units):
A block that has a dense layer at shortcut.
# Arguments
    input_tensor: input tensor
    unit: output tensor shape
# Returns
    Output tensor for the block.

x = layers.Dense(units)(input_tensor)
x = layers.BatchNormalization()(x)
x = layers.Activation('relu')(x)

x = layers.Dense(units)(x)
x = layers.BatchNormalization()(x)
x = layers.Activation('relu')(x)

x = layers.Dense(units)(x)
x = layers.BatchNormalization()(x)

shortcut = layers.Dense(units)(input_tensor)
shortcut = layers.BatchNormalization()(shortcut)

x = layers.add([x, shortcut])
x = layers.Activation('relu')(x)
return x

Resnet50 model:

def ResNet50Regression():
Res_input = layers.Input(shape=(178,))
width = 16

x = dens_block(Res_input,width)
x = identity_block(x,width)
x = identity_block(x,width)

x = dens_block(x,width)
x = identity_block(x,width)
x = identity_block(x,width)

x = dens_block(x,width)
x = identity_block(x,width)
x = identity_block(x,width)

x = layers.BatchNormalization()(x)
x = layers.Dense(1,activation=linear)(x)
model = models.Model(inputs=Res_input, outputs=x)

return model

Essentially, I am fitting the model to each dataset as follows:

import datetime
from tensorflow.keras import layers,models

model = ResNet50Regression()

model.compile(loss='mse', optimizer=Adam(learning_rate=0.0001), metrics=['mse'])
model.summary()

starttime = datetime.datetime.now()

history = model.fit(X_train, y_train, epochs=200, batch_size=64,  verbose=2, validation_data=(X_test, y_test))
endtime = datetime.datetime.now()

How can I get optimal prediction results from the above model, below is my results prediction now:

based on the predictions of the model above, the predictions generated are not able to predict properly. how to make prediction results correspondent the real value

Topic regression

Category Data Science

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.