Copyright 2017 Google Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
import tensorflow as tf
import keras
from sklearn.preprocessing import StandardScaler
import numpy as np
X_train = np.linspace(0, 80, 100).reshape(-1, 1)
# print(X_train)
Y_train = 5 * X_train
# print(Y_train)
X_test = np.linspace(0, 80, 20).reshape(-1, 1)
#print(X_test)
Y_test = 5 * X_test
#print(Y_test)
sc = StandardScaler()
x = sc.fit_transform(X_train)
y = sc.fit_transform(Y_train)
xt = sc.fit_transform(X_test)
yt = sc.fit_transform(Y_test)
from keras.layers import Input, Dense
from keras.models import Model
inputs = Input(shape=(1,))
preds = Dense(1,activation='linear')(inputs)
model = Model(inputs=inputs,outputs=preds)
sgd=keras.optimizers.SGD()
model.compile(optimizer=sgd ,loss='mse',metrics=['mse'])
model.fit(x,y, batch_size=1, epochs=30, shuffle=False)
score = model.evaluate(xt, yt, batch_size=16)
print("\nScore: %s" % score)