Deep Learning(3)

Linear Units in Keras

The easiest way to create a model in Keras is through 'keras.Sequential', which creates a stack of layers from a neural network. Of course, we can also use a dense layer to create the model.

We can define a linear model that takes three input features ('sugars', 'fiber', and 'protein') and then generate a simgle output ('calories') like this:

python 复制代码
from tensorflow import keras
from tensorflow.keras import layers

# Create a network with 1 linear unit
model = keras.Sequential([
    layers.Dense(units=1, input_shape=[3])
])

With the first parameter, 'units' , we define how many outputs we want. In this case, we're just predicting 'calories', so we'll use 'units = 1'.

With the second parameter, 'input_shape', we tell Keras the dimension of the inputs. Setting 'input_shape=[3]' ensures that the model will accept three features as input ('sugars', 'fiber', and 'protein').

This model is now ready to be fit to training data

相关推荐
用户693717500138431 分钟前
Google 推 AppFunctions:手机上的 AI 终于能自己干活了
android·前端·人工智能
章鱼丸-36 分钟前
DAY41简单 CNN
人工智能·深度学习·cnn
AI视觉网奇1 小时前
CosyVoice 加速实践
人工智能·深度学习
用户69371750013841 小时前
AI让编码变简单,真正拉开差距的是UI设计和产品思考
android·前端·人工智能
badhope1 小时前
概率论如何让机器学习不再玄学
人工智能·深度学习·机器学习·数据挖掘·github
wx_xkq12881 小时前
营销智脑V3重磅迭代:从工具到平台,AI营销进入“全能时代“
人工智能
阿钱真强道1 小时前
02 从 MLP 到 LeNet:数据、标签和任务:机器学习到底在解决什么问题?
人工智能·深度学习·机器学习·cnn·分类算法·lenet
天蓝色的鱼鱼1 小时前
别慌!AI时代,记住这12个新名词,你就赢了一半的人
人工智能
秋91 小时前
《世界的本质》的深度分析与解读,给出了如何“顺天应人”以实现个人价值最大化的行动指南
人工智能