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

相关推荐
朝新_7 小时前
【Spring AI 】图像与语音模型实战
java·人工智能·spring
Yuanxl9037 小时前
神经网络-Sequential 应用与实战
人工智能·深度学习·神经网络
火山引擎开发者社区7 小时前
Seedance 2.0 1080P 生成能力正式上线
人工智能
冬奇Lab7 小时前
一天一个开源项目(第79篇):生化危机女主角亲自开源的 AI 记忆系统 MemPalace
人工智能·开源·资讯
冬奇Lab8 小时前
Android 开发要变天了:Google 专为 Agent 重建工具链,Token 减少 70%、速度提升 3 倍
android·人工智能·ai编程
慧一居士8 小时前
Open WebUI 和Ollama 区别对比和关系
人工智能
云安全助手8 小时前
2026年AI安全大模型实战指南:快快云安全AI能力全景解析
人工智能·网络安全·claude
fuquxiaoguang8 小时前
当AI开始改写自己的“进化引擎”:从DGM到HyperAgents
人工智能·hyperagents
bKYP953cL8 小时前
构建自己的AI编程助手:基于RAG的上下文感知实现方案
数据库·人工智能·ai编程
数字供应链安全产品选型8 小时前
在供应链攻击激增200%的时代,如何用AI原生安全重塑防御边界?
人工智能