今天在linux虚拟机上装了Anaconda和所需的Tensorflow模块,开始机器学习的学习
安装好后,我开了一个环境:
conda activate pytorch
写了个脚本:
nano frist.py
//frist.py的代码
import tensorflow as tf
import numpy as np
from tensorflow import keras
model = tf.keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])
model.compile(optimizer='sgd', loss='mean_squared_error')
xs = np.array([-1.0, 0.0, 1.0, 2.0, 3.0, 4.0], dtype=float)
ys = np.array([-3.0, -1.0, 1.0, 3.0, 5.0, 7.0], dtype=float)
model.fit(xs, ys, epochs=50000)//训练5w次
print(model.predict([0.0]))
啪的一下,结果就出来了,虽然还是有些不准(训练了5w次,还是原题啊kora!)