<jupyter_start><jupyter_text>tensorflow学习,基本用法<jupyter_code>import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
#生成测试数据,共100个点
x = np.float32(np.random.rand(2, 1000))
y = np.dot([0.1, 0.2], x) + 0.3

print(y.size)
#y = wx + b线性模型，x为2*100的矩阵,w为1*2的矩阵
b = tf.Variable(tf.zeros([1]))
w = tf.Variable(tf.random_uniform([1, 2], -1.0, 1.0))
yy = tf.matmul(w, x) + b

print(y)
#最小化方差损失函数
#定义计算方式
loss = tf.reduce_mean(tf.square(yy - y))
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)
#初始化变量然后启动图开始计算
init = tf.initialize_all_variables()
#启动图(graph)
sess = tf.Session()
sess.run(init)

for step in range(0, 201):
    sess.run(train)
    if step % 20 == 0:
        print("step:{},w:{},b:{}".format(step, sess.run(w), sess.run(b)))
#使用plt作图显示拟合结果
fig = plt.figure(figsize=(9, 6))
ax = fig.gca(projection = '3d')
plt.scatter(x[0,:], x[1,:], y)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18705035971223022, 'fraction_numerical': 0.046248715313463515, 'mean_word_length': 5.243589743589744, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '557715', 'license': 'MIT', 'n_tokens_mistral': 501, 'n_tokens_neox': 494, 'n_words': 81, 'path': 'tutorial.ipynb', 'repo_name': 'owlsn/ML', 'size': '973'}