tensorflow2安装与入门 简单介绍

环境 Anacondo python3.7 tensorflow2.2

1.升级pip
python -m pip install --upgrade pip

2.安装tensorflow
pip install tensorflow-cpu==2.2.0 -i https://pypi.douban.com/simple/

3.验证是否安装成功
import tensorflow as tf
tf.version

4.步骤

#导包
import tensorflow as tf
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
#读取数据
data = pd.read_csv('dataset/Iris_Data.csv') 
#设置x,y
x = data.iloc[:,-1]
y = data.iloc[:,-1]
#建立模型
model = tf.keras.Sequential([tf.keras.layers.Dense(10,input_shape=(3,),activation='relu'),
                            tf.keras.layers.Dense(1)])
model.summary()
#编译模型
model.compile(optimizer='adam',
             loss='mse')
#训练
model.fit(x,y,epochs=100)
#predict
model.predict(test)

函数API

tensorflow2安装与入门 简单介绍_第1张图片

你可能感兴趣的:(深度学习,tensorflow,python,深度学习)