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

相关推荐
niaonao15 分钟前
企业级AI Agent本地化部署实战:基于讯飞星辰与Astron的实战详解(附避坑清单)
人工智能·agent·科大讯飞·astron
ModelWhale23 分钟前
实训赋能,平台支撑:和鲸科技助力南京大学人工智能基础课落地
人工智能·科技
胡萝卜3.027 分钟前
C++现代模板编程核心技术精解:从类型分类、引用折叠、完美转发的内在原理,到可变模板参数的基本语法、包扩展机制及emplace接口的底层实现
开发语言·c++·人工智能·机器学习·完美转发·引用折叠·可变模板参数
java1234_小锋27 分钟前
Transformer 大语言模型(LLM)基石 - Transformer架构详解 - 掩码机制(Masked)原理介绍以及算法实现
深度学习·语言模型·transformer
Codebee1 小时前
OODER图生代码框架:Java注解驱动的全栈实现与落地挑战
人工智能
中冕—霍格沃兹软件开发测试1 小时前
测试用例库建设与管理方案
数据库·人工智能·科技·开源·测试用例·bug
TextIn智能文档云平台1 小时前
什么是多模态信息抽取,它和传统OCR有什么区别?
大数据·人工智能
Linux后台开发狮1 小时前
DeepSeek-R1 技术剖析
人工智能·机器学习
拾荒的小海螺2 小时前
开源项目:AI-Writer 小说 AI 生成器
人工智能
Xiaoxiaoxiao02092 小时前
情感 AI:让机器真正理解人的下一代智能——以 GAEA 为例的情绪计算探索
人工智能