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

相关推荐
冬哥聊AI1 分钟前
多模态诅咒:给大模型装上眼睛,文本推理为什么反而变笨了?
人工智能
东风破_2 分钟前
LLM 是怎么预测下一个词的?从 Token 到 Transformer 的完整过程
人工智能
日是故乡明5 分钟前
Claude Code 正在用隐写术标记请求
人工智能
网易云信8 分钟前
Anthropic研究百万对话,情感陪伴AI正在成为基础设施
人工智能·aigc·agent
掘金一周10 分钟前
对车完全小白,不知买油买电还是买混动,求建议| 沸点周刊 7.2
前端·人工智能·后端
转转技术团队27 分钟前
从神经元到大语言模型,回顾机器学习发展史
人工智能
天风之翼1 小时前
搭建一个轻量 Agent Harness——让 AI Agent 安全地执行命令、读写文件
人工智能
雪隐2 小时前
个人电脑玩AI-09让5060 Ti给你打工——让 AI 读懂你的资料
人工智能·后端
大模型真好玩2 小时前
LangChain DeepAgents 速通指南(十)—— DeepAgents Code 智能体服务核心源码解读
人工智能·langchain·agent
网易云信2 小时前
「帝王蟹」企业AI落地实战营西安站落幕:共探“人工智能+”落地深水区
人工智能·agent·产品