Keras Model for Regression with one input and one output

38 views Asked by At

I'm trying to set up a very simple model in Keras, having one input and one output and trying to find the connection between the two arrays. However, training does not reduce the MSE on the test data.

I split the dataset into input and output variables and created a model with two layers. At the end I would like the weight of the model as a representation of the connection between input and output. I used a very simple dataset: output = input*1.5

However, I'm struggling to fit the model. The input is of shape (505, 1) and the target is of shape (505,).

My approach to the model is as follows:

# load dataset
dataframe = pd.read_csv("data.CSV", delimiter=';')
dataset = dataframe.values
#print(dataset)
# split into input (X) and output (Y) variables
X = dataset[:,0]
Y = dataset[:,1]

# define base model
def baseline_model():
 # create model
 model = Sequential()
 model.add(Dense(1, input_shape=(1,), kernel_initializer='normal', activation='softmax'))
 model.add(Dense(1, kernel_initializer='normal'))
 # Compile model
 model.compile(loss='mean_squared_error', optimizer='adam')
 return model
# evaluate model
estimator = KerasRegressor(model=baseline_model, epochs=100, batch_size=5, verbose=0)
kfold = KFold(n_splits=2)
results = cross_val_score(estimator, X.reshape(-1,1), Y, cv=kfold, scoring='neg_mean_squared_error')
print("Baseline: %.2f (%.2f) MSE" % (results.mean(), results.std()))
0

There are 0 answers