【问题标题】:Simple Logistic Regression with Neural Networks Mindset具有神经网络思维的简单逻辑回归
【发布时间】:2018-09-06 07:55:35
【问题描述】:

得到了这个简单的练习,我必须在逻辑回归的帮助下构建一个神经网络。我的数据集是这样构建的:

给你一个数据集(“data.h5”),其中包含:

  • 标记为猫 (y=1) 或非猫 (y=0) 的 m_train 图像训练集
  • 标记为猫或非猫的 m_test 图像的测试集
  • 每个图像的形状为 (num_px, num_px, 3),其中 3 表示 3 个通道 (RGB)。因此,每个图像都是正方形的(高度 = num_px)并且 (宽度 = num_px)。

为了显示数据库中的图像,文本给了我一个例子:

# Example of a picture# Examp 
index = 25
plt.imshow(train_set_x_orig[index])
print ("y = " + str(train_set_y[:,index]) + ", it's a '" + classes[np.squeeze(train_set_y[:,index])].decode("utf-8") +  "' picture.")

我有两个问题:

1) 我不明白这是如何工作的:str(train_set_y[:,index])

2) 最大的问题是,由于站点问题,我无法下载此数据库,为了进行练习,我想了解它是如何构建的。谁能直观地告诉我它的结构?

【问题讨论】:

    标签: python neural-network logistic-regression


    【解决方案1】:

    我假设这段代码 sn-p 来自 Coursera 深度学习课程 1。

    "train_set_y" 是一个形状为 (1, 209) 的向量,即它具有标签对于所有 209 个训练示例,为 0 或 1,"train_set_y[:,25]" 从向量 train_set_y 的第 25 位开始给出整数标签 0 或 1。因为我们正在连接字符串 ("y = " + str(train_set_y[:,index]))。我们需要使用 str 将其转换为字符串。

    检查笔记本中的 lr_utils.py 文件,它会让您清楚地了解数据集是如何加载和转换的。

    下面是 lr_utils.py 文件中的代码 sn-p

    def load_dataset():
       train_dataset = h5py.File('datasets/train_catvnoncat.h5', "r")
       train_set_x_orig = np.array(train_dataset["train_set_x"][:]) # your train set features
       train_set_y_orig = np.array(train_dataset["train_set_y"][:]) # your train set labels
    
       test_dataset = h5py.File('datasets/test_catvnoncat.h5', "r")
       test_set_x_orig = np.array(test_dataset["test_set_x"][:]) # your test set features
       test_set_y_orig = np.array(test_dataset["test_set_y"][:]) # your test set labels
    
       classes = np.array(test_dataset["list_classes"][:]) # the list of classes
    
       train_set_y_orig = train_set_y_orig.reshape((1, train_set_y_orig.shape[0]))
       test_set_y_orig = test_set_y_orig.reshape((1, test_set_y_orig.shape[0]))
    
       return train_set_x_orig, train_set_y_orig, test_set_x_orig, test_set_y_orig, classes
    

    【讨论】:

      【解决方案2】:
      1. 数据集可以在这个位置下载,(感谢安德森!)

      2. 然后构建 @taurz 的 lr_utils 函数,放入 sys.path() 任何目录,但确保从 train_dataset = h5py.File('datasets/train_catvnoncat.h5', " r")

      3. str(train_set_y[:,index]) 是标签,>> train_set_y,可以看到所有的特征, train_set_y.shape = (1,209), train_set_y[:,25][0] = 1 表示是猫。

      【讨论】:

        猜你喜欢
        • 2018-03-05
        • 2019-01-27
        • 2017-11-12
        • 2021-09-13
        • 1970-01-01
        • 2019-02-05
        • 2022-01-08
        • 1970-01-01
        • 2020-10-24
        相关资源
        最近更新 更多