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

相关推荐
小李同学_LHY15 分钟前
第一章:从人工智能到大语言模型:概念梳理与关系辨析
人工智能·语言模型·自然语言处理
虎鲸不是鱼16 分钟前
【虎鲸进化论 09】活下去:自启、守护、探活
人工智能·自动化·大模型·llm·自进化agent
派小心.35 分钟前
网站统计采样数据的误差核对
大数据·服务器·前端·数据库·人工智能·小程序·数据分析
TMT星球1 小时前
云从科技参编两项人工智能操作系统国家标准正式发布
人工智能·科技
johnsong1 小时前
AI 前沿日报 2026-10-14:边界渗透
人工智能
阿里云大数据AI技术1 小时前
在 EMR Serverless Spark 中访问 Fluss
人工智能·spark
Dawson Zhu1 小时前
《Agentic Design Patterns》第 21 章导读:探索与发现
人工智能·语言模型·架构·aigc·agi
龙腾AI白云1 小时前
数字孪生、具身智能、世界模型三者交叉
数据库·人工智能·机器学习·flask·pygame
JAVA_AI人工智能项目实战1 小时前
大模型结构演进.学习笔记
大数据·人工智能·语言模型·架构
商业数据派1 小时前
京东11.11:首日下单用户数同比双位数增长、超百项服务首次全景亮相
人工智能