Tensorflow是Google提供的一种机器学习框架。它是一个开放源代码框架,与Python结合使用以实现算法,深度学习应用程序等等。它用于研究和生产目的。它具有优化技术,可帮助快速执行复杂的数学运算。这是因为它使用NumPy和多维数组。这些多维数组也称为“张量”。
该框架支持使用深度神经网络。它具有高度的可扩展性,并附带许多流行的数据集。它使用GPU计算并自动进行资源管理。它带有大量的机器学习库,并且得到了很好的支持和记录。该框架具有运行深度神经网络模型,对其进行训练以及创建可预测各个数据集相关特征的应用程序的能力。
可以使用下面的代码行在Windows上安装'tensorflow'软件包-
pip install tensorflow
Tensor是TensorFlow中使用的数据结构。它有助于连接流程图中的边缘。该流程图称为“数据流程图”。张量不过是多维数组或列表。
以下是一个例子-
def linear_reg(x): return A * x + b def mean_square_error(y_pred, y_true): return tf.reduce_mean(tf.square(y_pred - y_true)) optimizer = tf.optimizers.SGD(learning_rate) def run_optimization(): with tf.GradientTape() as g: pred = linear_reg(X) loss = mean_square_error(pred, Y) gradients = g.gradient(loss, [A, b]) optimizer.apply_gradients(zip(gradients, [A, b]))
代码信用-https://github.com/aymericdamien/TensorFlow-Examples/blob/master/tensorflow_v2/notebooks/2_BasicModels/linear_regression.ipynb
输出结果
A linear regression function that is defined, is called on the data. Once the optimal data points have been computed, the mean square error function is calculated. The radient descent function is used to find the optimal weights. These values are displayed on the console.
“ weight”和“ bias”值是随机初始化的。培训完成后,它们将更新为最佳值。
线性方程的一般格式为“ Ax + b”,其中“ A”为“权重”,“ b”为“偏置”值。
定义了计算均方误差的函数。
还定义了随机梯度下降优化器。
定义了一个优化功能,该功能可以计算梯度并更新权重和偏差的值。
训练数据指定的步骤数。