Home Article Practice tf1

tf1

2021-06-02 17:13  views:600  source:小键人879686    

import tensorflow as tf
from sklearn import datasets
from pandas import DataFrame
import pandas as pd
import numpy as np
x_data = datasets.load_iris().data
y_data = datasets.load_iris().target
np.random.seed(9)
np.random.shuffle(x_data)
np.random.seed(9)
np.random.shuffle(y_data)
tf.random.set_seed(9)
x_train = x_data[:-30]
y_train = y_data[:-30]
x_test = x_data[-30:]
y_test = y_data[-30:]
x_train = tf.cast(x_train,tf.float32)
x_test = tf.cast(x_test,tf.float32)
train_db = tf.data.Dataset.from_tensor_slices((x_train,y_train)).batch(32)
test_db = tf.data.Dataset.from_tensor_slices((x_test,y_test)).batch(32)
w1 = tf.Variable(tf.random.truncated_normal([4,3],stddev=0.1, seed=1))
b1 = tf.Variable(tf.random.truncated_normal([3],stddev=0.1,seed=1))
lr = 0.1
train_loss_result = []
test_acc = []
epoch = 500
loss_all = 0



Disclaimer: The above articles are added by users themselves and are only for typing and communication purposes. They do not represent the views of this website, and this website does not assume any legal responsibility. This statement is hereby made! If there is any infringement of your rights, please contact us promptly to delete it.

字符:    改为:
去打字就可以设置个性皮肤啦!(O ^ ~ ^ O)