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

相关推荐
SkyWalking中文站7 分钟前
看清 Claude Code 的用量与文件变更
人工智能·ai编程·claude
陈年老古董29 分钟前
PyTorch食物图像分类实战:从数据集制作到CNN模型训练全流程详解
pytorch·深度学习·学习·机器学习·分类·cnn
飞哥数智坊39 分钟前
TraeCode 180积分帮我做了一套系统,全程我感觉自己有点多余
人工智能·ai编程
AI人工智能集结号40 分钟前
GEO优化公司怎么选?从检测、诊断到执行判断服务是否完整
人工智能
酒旅Agent开发实战41 分钟前
开发者如何选择API和MCP
人工智能·大模型·酒店预订·ai agent·mcp
人民广场吃泡面1 小时前
什么是AI Agent?它又能给前端带来哪些效率提升?
前端·人工智能
沈管家AI数字员工1 小时前
自研 AI 智能体 vs 采购数字员工平台:成本、风险与周期的真实对比
人工智能
集成电路芯片封装设备1 小时前
除氧型真空共晶设备技术详解:从原理到应用
人工智能
武汉星际互动1 小时前
咨询量大、时段受限、口语化难识别,政务AI数字人如何承接大厅导办?
人工智能·政务
资讯综合1 小时前
500亿招聘市场悖论:AI技术能否填平行业的信任深坑
大数据·人工智能