hhh_ml

导航

tensorflow简单实现一阶线性预测

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '1'
import tensorflow as tf
import keras
import numpy as np
 
 
model = keras.Sequential([keras.layers.Dense(units = 1,input_shape = [1])])
model.compile(optimizer = 'sgd',loss = 'mean_squared_error')
 
xs = np.array([-1,0,1,2,3,4],dtype = float)
ys = np.array([-3,-1,1,3,5,7],dtype = float)
 
model.fit(xs,ys,epochs = 500)
print(model.predict([10]))

 

posted on 2021-02-04 17:11  hhh_ml  阅读(82)  评论(0编辑  收藏  举报