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

相关推荐
weixin_408099671 分钟前
身份证正反面合并+识别OCR接口调用
java·人工智能·后端·python·ocr·api·身份证ocr
CHPCWWHSU1 分钟前
深入 llama.cpp:词汇表与分词——从文本到 Token (4)
人工智能·llm·llama·cpp·cudatoolkit
昨夜见军贴06162 分钟前
AI报告编审解决方案全面升级:IA-Lab AI检测报告生成助手与IACheck让报告生产进入“轻松高效”新阶段
人工智能
vx_biyesheji00012 分钟前
计算机毕业设计:Python汽车市场智能决策系统 Flask框架 可视化 机器学习 AI 大模型 大数据(建议收藏)✅
大数据·人工智能·python·算法·django·汽车·课程设计
源码之家4 分钟前
计算机毕业设计:Python汽车销量智能可视化与预测系统 Flask框架 可视化 机器学习 AI 大模型 大数据(建议收藏)✅
大数据·人工智能·python·机器学习·信息可视化·汽车·课程设计
Dfreedom.4 分钟前
神经网络算法全景解析
人工智能·神经网络·算法
特别关注外国供应商7 分钟前
Netskope 安全与网络重塑人工智能
网络·人工智能·安全·零信任·访问控制·sase·netskope
财经资讯数据_灵砚智能8 分钟前
基于全球经济类多源新闻的NLP情感分析与数据可视化(夜间-次晨)2026年4月2日
大数据·人工智能·python·信息可视化·语言模型·自然语言处理·ai编程
F_U_N_9 分钟前
研发效率革命:AI如何重构环境配置与团队协作?
人工智能·重构·ai编程