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

相关推荐
网易云信39 分钟前
销冠跑了,经验留下:AI Agent 如何进入医美机构的日常工作?
人工智能
武子康1 小时前
驾驶轨迹换个坐标,就能给移动机器人用吗?
人工智能·算法·机器学习
jay神1 小时前
基于深度学习的交通流量预测系统(Web 版)
前端·人工智能·深度学习·yolo·计算机毕业设计
kaixin_啊啊1 小时前
【零基础学AI】第 25 章——计算机怎样处理文字
人工智能
一知半解仙1 小时前
乌镇2026:当“智能互联网”第一次被数据照进现实
人工智能·物联网·机器人·开源
泯泷2 小时前
AI 最坑的失败:不是不会做,而是"假装做完了"
人工智能·llm·agent