#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File : 自实现一个线性回归.py
# @Author: 赵路仓
# @Date : 2020/4/12
# @Desc :
# @Contact : 398333404@qq.com
import os
import tensorflow as tf
def linear_regression():
"""
自实现一个线性回归
:return:
"""
# 命名空间
with tf.variable_scope("prepared_data"):
# 准备数据
x = tf.random_normal(shape=[100, 1], name="Feature")
y_true = tf.matmul(x, [[0.08]]) + 0.7
# x = tf.constant([[1.0], [2.0], [3.0]])
# y_true = tf.constant([[0.78], [0.86], [0.94]])
with tf.variable_scope("create_model"):
# 2.构造函数
# 定义模型变量参数
weights = tf.Variable(initial_value=tf.random_normal(shape=[1, 1], name="Weights"))
bias &