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

相关推荐
feasibility.2 分钟前
“美版DeepSeek”等海外开放模型,能夺回生态入口吗?——中国开放权重领先下的2026全球AI分水岭
人工智能·开源·大模型·llm·minimax·deepseek·beam
AI大模型-小华4 分钟前
AI 编程进入深度开发阶段:什么时候普通方案不够,需要更高算力支持?
人工智能·chatgpt·ai编程·vs code·codex·codex cli
思维新观察5 分钟前
三星 Galaxy Tab S12 系列:大屏 AI 平板,兼顾轻薄与生产力
数据结构·人工智能·电脑
能源探索家9 分钟前
能源资讯[26M10W2] 本周热点复盘:电力交易放量、六张网底座建设、浙江储能入市
人工智能·能源·新型电力系统·十五五规划·能源信息化·能源资讯
工具派14 分钟前
Agent 不是玄学:用 Java 状态机思维理解 LangGraph
java·人工智能·python
szxinmai主板定制专家17 分钟前
基于RK3588+FPGA+AI的储能电站边缘网关,实现电力数据采集与智能预警
arm开发·人工智能·fpga开发·rk3576·半导体设备
阿里云大数据AI技术22 分钟前
阿里云 Milvus 磁盘索引新利器:百万级Topk高性能召回
人工智能
独立开发者阿乐22 分钟前
llms.txt 是什么?为什么 AI 爬虫需要这个文件
人工智能·爬虫·geo优化·ai爬虫·llms.txt·ai收录·robots.txt
czq_26867194871 小时前
Python打卡第36天
pytorch·python·深度学习
福兮说1 小时前
秋招简历让 AI 写了一版:它替我加了 JWT,还把课程设计写成了「高并发」
人工智能·课程设计·秋招·求职·简历