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

相关推荐
Anastasiozzzz3 小时前
深入研究RAG: 在线阶段-查询&问答
数据库·人工智能·ai·embedding
tq10864 小时前
资本主义的时间贴现危机:AI时代的结构性淘汰机制
人工智能
砍材农夫4 小时前
spring-ai 第四多模态API
java·人工智能·spring
土豆12506 小时前
LangGraph TypeScript 版入门与实践
人工智能·llm
土豆12507 小时前
OpenSpec:让 AI 编码助手从"乱猜"到"照单执行"
人工智能·llm
Thomas.Sir7 小时前
第二章:LlamaIndex 的基本概念
人工智能·python·ai·llama·llamaindex
m0_694845577 小时前
Dify部署教程:从AI原型到生产系统的一站式方案
服务器·人工智能·python·数据分析·开源
LS_learner7 小时前
VS Code 终端默认配置从 PowerShell 改为 CMD
人工智能
小毅&Nora8 小时前
【人工智能】【大模型】大模型“全家桶”到“精兵简政”:企业AI落地的理性进化之路
人工智能·大模型·平安科技
KaneLogger8 小时前
如何把AI方面的先发优势转化为结构优势
人工智能·程序员·架构