본문 바로가기

AI

[Tensorflow 자격증 공부] 1번문제

전체 복사 붙여넣게 금지

xs 와 ys 값이 랜덤으로 주어지므로 

#YOUR CODE HERE  

이하로만 손대기

 

import numpy as np
import tensorflow as tf


def solution_model():
    xs = np.array([-1.0, 0.0, 1.0, 2.0, 3.0, 4.0], dtype=float)
    ys = np.array([5.0, 6.0, 7.0, 8.0, 9.0, 10.0], dtype=float)
    # YOUR CODE HERE
    model = tf.keras.models.Sequential([
        tf.keras.layers.Dense(1, input_shape=[1]),
    ])
    model.compile(optimizer="sgd", loss="mse")
    model.fit(xs, ys, epochs=500, verbose=0)
    return model


# Note that you'll need to save your model as a .h5 like this
# This .h5 will be uploaded to the testing infrastructure
# and a score will be returned to you
if __name__ == '__main__':
    model = solution_model()
    model.save("mymodel.h5")
    print(model.predict([10.0]))