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

相关推荐
测试界的小码农4 分钟前
【让 AI 生成的测试用例变成 pytest API 自动化脚本】
人工智能·测试用例·pytest
天天代码码天天27 分钟前
我开源了一个家庭备份工具:把手机照片和视频,存回自己的电脑
人工智能
AI源码29 分钟前
基于机器学习的古籍文字识别与断句校正系统
人工智能·机器学习
用户83390496069538 分钟前
记账大师 AIUI购物记账与交互可靠性实践
人工智能
数智人生局40 分钟前
配置驱动的通用 ETL 执行引擎:告别"每个需求写一个 Spark 作业"(改配置不发版)
人工智能
Neurocoda1 小时前
基于 NumPy 从零实现 Tiny-AlexNet 在 MNIST 数据集上的验证
人工智能·深度学习
youcans_1 小时前
【嵌入式软件AI编程】(3)面向 AI 协同开发的 STM32 硬件信息标准化
人工智能·stm32·嵌入式硬件·ai编程
AOI小白新手上路1 小时前
深度学习算力购置方案分析:本地 RTX 4090 服务器 vs 云端租赁
服务器·人工智能·深度学习
QXWZ_IA1 小时前
北斗高精度定位在泛自然资源行业的技术演进与应用方向
大数据·人工智能
坐吃山猪1 小时前
果蝇AI06-Mac部署实操
人工智能·深度学习·机器学习·果蝇ai