簡體   English   中英

使用神經網絡心態的簡單邏輯回歸

[英]Simple Logistic Regression with Neural Networks Mindset

得到了這個簡單的練習,我必須在邏輯回歸的幫助下構建一個神經網絡。 我的數據集是這樣構建的:

您將獲得一個數據集(“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)最大的問題是,由於站點問題,我無法下載此數據庫,為了進行練習,我想了解它是如何構建的。 有人能直觀地告訴我它是如何構建的嗎?

我假設此代碼片段來自 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 文件的代碼片段

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
  1. 數據集可以在這個位置下載,(感謝安德森!)

  2. 然后構建@taurz 的 lr_utils 函數,放入 sys.path() 任何目錄,但請確保從 train_dataset = h5py.File('datasets/train_catvnoncat.h5', "r") 中刪除 'datasets/'

  3. str(train_set_y[:,index]) 是標簽,>> train_set_y ,你可以看到所有的特征, train_set_y.shape = (1,209), train_set_y[:,25][0] = 1 ,這意味着它是貓。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM