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

相关推荐
HelloWorld__来都来了几秒前
【每日学术速报】2026-06-15
人工智能·具身智能
H__Rick6 分钟前
自动对焦学习-3
人工智能·学习·计算机视觉
SpaceAIGlobal13 分钟前
AI 生成 PPT 工具深度评测与选型指南
人工智能·powerpoint
移动云开发者联盟15 分钟前
移动云HaishanDB焕新出发!
人工智能
用户16931761726617 分钟前
多端复用一套对话逻辑,我抽了个 useChat hook
人工智能
johnny23320 分钟前
开源AI助手项目汇总:OpenHuman、nexu、Moltis、Eclaire、ChatClaw、Frona
人工智能
于先生吖35 分钟前
SpringBoot对接大模型开发AI命理测算系统:八字排盘与AI解析接口源码全解
人工智能·spring boot·后端
AI创界者41 分钟前
PilotTTS 一键整合包(Win/Mac):8G 显存畅跑,实测解锁情绪与副语言的精准控制
人工智能·macos·aigc·音视频
DaLi Yao44 分钟前
【无标题】
人工智能·安全