pytorch回归_PyTorch:用岭回归检查泰坦尼克号下沉
pytorch回歸
In this notebook, we shall use this dataset containing data about passengers from the Titanic. Based on this data, we will use a Ridge Regression model which just means a Logistic Regression model that uses L2 Regularization for predicting whether a person survived the sinking based on their passenger class, sex, the number of their siblings/spouses aboard, the number of their parents/children aboard and the fare they payed.
在這款筆記本上,我們將使用這種含有大約從泰坦尼克號(hào)的乘客數(shù)據(jù)集。 基于此數(shù)據(jù),我們將使用Ridge回歸模型,該模型僅表示使用L2正則化的Logistic回歸模型,根據(jù)乘客的等級(jí),性別,同胞/配偶的人數(shù),人數(shù)來預(yù)測(cè)某人是否沉沒。他們的父母/孩子和他們支付的車費(fèi)。
First, we import everything we need for plotting data and creating a great model to make predictions on the data.
首先,我們導(dǎo)入繪制數(shù)據(jù)和創(chuàng)建出色模型以對(duì)數(shù)據(jù)進(jìn)行預(yù)測(cè)所需的一切。
數(shù)據(jù)探索 (Data Exploration)
Here, we can see what the data actually looks like. The first column indicates whether the person survived with a 1 or a 0, where the 1 stands for survival and the 0 for death. The rest of the columns are all our input columns used to predict the survival. We will, however, forget about as it does not hold important information needed to predict survival. You can also see below that we have 887 persons with their data and 8 total columns where 6 of them will be the input values and 1 of them (the Survived column) the corresponding label.
在這里,我們可以看到數(shù)據(jù)的實(shí)際外觀。 第一列表示該人是生存還是生存1或0,其中1代表生存,0代表死亡。 其余的列都是我們用來預(yù)測(cè)生存率的所有輸入列。 但是,我們將忘記它,因?yàn)樗痪邆漕A(yù)測(cè)生存所需的重要信息。 您還可以在下面看到,我們有887個(gè)人及其數(shù)據(jù),共有8列,其中6個(gè)為輸入值,其中1個(gè)(生存列)為相應(yīng)的標(biāo)簽。
To get a little bit more familiar with the data we can do some computations with it and plot it. First we print how big the part of the survivors is which can also be described as the total probability of survival.
為了更熟悉數(shù)據(jù),我們可以對(duì)其進(jìn)行一些計(jì)算并繪制出圖表。 首先,我們打印幸存者部分的大小,這也可以描述為生存的總概率。
When we look at how likely different people from different classes and of different sexes are to survive we can see a clear trend that the higher the class the higher the survival probability and also that women are more likely to survive. Ever wondered why is this the case? The answer is quite simple.
當(dāng)我們觀察來自不同階級(jí)和性別的不同人的生存可能性時(shí),我們可以清楚地看到一個(gè)趨勢(shì),即階級(jí)越高,生存的可能性就越高,而且女性生存的可能性就越大。 有沒有想過為什么會(huì)這樣呢? 答案很簡(jiǎn)單。
When the Titanic began to sink, women and children would go off-board in the lifeboats first before the men. The lower class passengers were not treated equally at the time of sinking as there were so many people in the lower class that not all could not be informed by the stewardesses. Subsequently, it took much longer for them to get to the deck for rescue while first and second class passengers were already boarding the lifeboats. Also, the sailors fastened down the hatchways leading to the third-class section. They said they wanted to keep the air down there so the vessel could stay up longer. It meant all hope was gone for the passengers still down there.
當(dāng)泰坦尼克號(hào)沉沒時(shí),婦女和兒童將首先在救生艇上駛離船上,然后才駛向男子。 在下沉?xí)r,下層旅客沒有得到同等的對(duì)待,因?yàn)橄聦勇每吞?#xff0c;因此乘務(wù)員并不能告知所有人。 隨后,當(dāng)頭等艙和二等艙乘客已經(jīng)登上救生艇時(shí),他們花了更長的時(shí)間才能到達(dá)甲板上進(jìn)行救援。 此外,水手們將艙口固定在通往三等艙的艙口上。 他們說,他們希望將空氣保持在那里,以便船只可以停留更長的時(shí)間。 這意味著所有仍在那里的乘客的希望已蕩然無存。
Another reason why so many people died was the missing safety measures onboard the Titanic. For example, there were not enough boats for the passengers to escape the ship. The lifeboats would have only been sufficient for half the people onboard and due to bad organization not all of them were completely filled. More than half of the passengers were left behind. One good aspect, however, is that the laws for a ship’s safety have become more strict since this disaster. If you want to read about the sinking in detail, have a look at this: https://en.wikipedia.org/wiki/Sinking_of_the_RMS_Titanic
如此之多的人死亡的另一個(gè)原因是泰坦尼克號(hào)上缺少安全措施。 例如,沒有足夠的船只供乘客逃脫。 救生艇僅能滿足船上一半人的需要,而且由于組織不善,并非所有人都被完全裝滿。 一半以上的乘客被拋在后面。 但是,一個(gè)好的方面是,自這場(chǎng)災(zāi)難以來,船舶安全的法律變得更加嚴(yán)格。 如果您想詳細(xì)了解下沉,請(qǐng)查看以下內(nèi)容: https : //en.wikipedia.org/wiki/Sinking_of_the_RMS_Titanic
Looking at the prices, which are all measured in pounds, we can see the total average fare and then the different ones from the different classes. Note that due to inflation these numbers measured in pounds today would be a lot higher.
查看全部以磅為單位的價(jià)格,我們可以看到總平均票價(jià),然后是不同類別的票價(jià)。 請(qǐng)注意,由于通貨膨脹,今天這些以磅為單位的數(shù)字會(huì)高得多。
There are also people from all ages on board while the average age is 30 years.
船上還有各個(gè)年齡段的人,平均年齡為30歲。
To see the difference of survival probability already mentioned and explained above more visually, we can plot them like the following plots show. Here, you can see the difference between the different classes and sex very well.
為了更直觀地看到上面已經(jīng)提到和解釋的生存概率的差異,我們可以像下面的圖所示繪制它們。 在這里,您可以很好地看到不同階級(jí)和性別之間的差異。
Let’s now look at the fare distribution and the costs from the different classes.
現(xiàn)在,讓我們看一下不同類別的票價(jià)分配和費(fèi)用。
In the following we can clearly see that most passengers did not have any siblings/spouses or parents/children aboard.
在下面的內(nèi)容中,我們可以清楚地看到,大多數(shù)乘客沒有兄弟姐妹/配偶,也沒有父母/子女。
Lastly we look at the distribution of the ages of the passengers.
最后,我們看看乘客的年齡分布。
資料準(zhǔn)備 (Data Preparation)
Now to be able to train our model we want to convert our pandas dataframe into PyTorch Tensors. To do this we define the dataframe_to_arrays method which does the conversion to NumPy arrays. To use the function we need to specify 3 kinds of columns namely input columns, categorical columns (columns that do not contain numbers but rather a string standing for a category) and output columns so that it can properly create a NumPy array for input data and labels with all input data from the input columns (by first converting the categorical columns to numerical ones) and the labels from the output columns. Then we can easily convert them to PyTorch Tensors and specify the desired data types so that we are ready to define the model to be ready for the training on the data. Note also that the normalize parameter is set to True which makes the function normalize the input data by squishing all values in a range between 0 and 1 with Min Max Normalization for the model to be able to better learn from the data as it is more uniform now.
現(xiàn)在要能夠訓(xùn)練我們的模型,我們想將熊貓數(shù)據(jù)框轉(zhuǎn)換為PyTorch張量。 為此,我們定義了dataframe_to_arrays方法,該方法可以轉(zhuǎn)換為NumPy數(shù)組。 要使用該函數(shù),我們需要指定3種列,即輸入列,分類列(不包含數(shù)字,而是代表類別的字符串的列)和輸出列,以便它可以正確地為輸入數(shù)據(jù)和輸入創(chuàng)建NumPy數(shù)組。標(biāo)簽,其中包含來自輸??入列的所有輸入數(shù)據(jù)(首先將分類列轉(zhuǎn)換為數(shù)字列),以及來自輸出列的標(biāo)簽。 然后,我們可以輕松地將它們轉(zhuǎn)換為PyTorch張量并指定所需的數(shù)據(jù)類型,以便我們準(zhǔn)備定義模型以進(jìn)行數(shù)據(jù)訓(xùn)練。 另請(qǐng)注意,將normalize參數(shù)設(shè)置為True ,這會(huì)使函數(shù)通過使用Min Max Normalization擠壓0到1之間范圍內(nèi)的所有值來對(duì)輸入數(shù)據(jù)進(jìn)行歸一化,以便模型可以更好地從數(shù)據(jù)中學(xué)習(xí),因?yàn)樗y(tǒng)一現(xiàn)在。
Now that we have the PyTorch Tensors for the input data and the labels we put them into a PyTorch TensorDataset which contains pairs of inputs and labels.
現(xiàn)在我們有了用于輸入數(shù)據(jù)和標(biāo)簽的PyTorch張量,我們將它們放入包含輸入和標(biāo)簽對(duì)的PyTorch TensorDataset中。
Another thing we have to do is to split the original dataset into one for training the model and another one for validating that the model is learning something. This means that the validation dataset contains data that the model has never seen before and by making predictions on it we can see how well the model can perform on unknown data. This accuracy from the validation data will be used as a metric for all training epochs as well as the loss on the validation data.
我們要做的另一件事是將原始數(shù)據(jù)集分為一個(gè)用于訓(xùn)練模型的數(shù)據(jù)集,另一個(gè)用于驗(yàn)證模型正在學(xué)習(xí)某些東西的數(shù)據(jù)集。 這意味著驗(yàn)證數(shù)據(jù)集包含模型從未見過的數(shù)據(jù),并且通過對(duì)其進(jìn)行預(yù)測(cè),我們可以看到模型對(duì)未知數(shù)據(jù)的性能如何。 驗(yàn)證數(shù)據(jù)的準(zhǔn)確性將用作所有訓(xùn)練時(shí)期以及驗(yàn)證數(shù)據(jù)損失的度量。
Last thing we do with our data is to put it into a DataLoader (one for the validation data and one for the training data) which will be used to train the model with shuffled and batched data.
我們對(duì)數(shù)據(jù)做的最后一件事是將其放入DataLoader (一個(gè)用于驗(yàn)證數(shù)據(jù),另一個(gè)用于訓(xùn)練數(shù)據(jù)),該數(shù)據(jù)將用于使用混排和批處理的數(shù)據(jù)來訓(xùn)練模型。
定義模型結(jié)構(gòu) (Defining Model Structure)
Now we can create our model which is just a simple Logistic Regression model with a linear layer that accepts 6 inputs and outputs 1 value between 0 and 1 which basically makes the model’s forward method return the probability of survival it predicts by using the sigmoid activation function. This is necessary as then we can train the model to output a 1 when it thinks that the person would survive and a 0 when it does think that the person will not survive even though the model will probably never return a 1 or a 0 but it will predict a probability closer to 1 or 0 after some time of training. Moreover we define some other methods in our model for training and computing accuracies or printing them. One more thing to note is that as a loss function in training_step we use the Binary Cross Entropy loss. Lastly, we create an instance of the TitanicModel called model which we will train on the training data.
現(xiàn)在我們可以創(chuàng)建我們的模型,它只是一個(gè)簡(jiǎn)單的Logistic回歸模型,該模型具有一個(gè)線性層,該層可以接受6個(gè)輸入并輸出0到1之間的1值,這基本上使該模型的forward方法返回使用S形激活函數(shù)預(yù)測(cè)的生存概率。 這是必要的,因?yàn)檫@樣我們可以訓(xùn)練模型,當(dāng)模型認(rèn)為某人可以生存時(shí)輸出1,而當(dāng)模型認(rèn)為該人可能永遠(yuǎn)不會(huì)返回1或0時(shí)卻認(rèn)為該人將無法生存,則輸出0。經(jīng)過一段時(shí)間的訓(xùn)練,將預(yù)測(cè)接近1或0的概率。 此外,我們?cè)谀P椭卸x了一些其他方法來訓(xùn)練和計(jì)算精度或打印它們。 還有一點(diǎn)要注意的是,作為training_step的損失函數(shù),我們使用了二進(jìn)制交叉熵?fù)p失。 最后,我們創(chuàng)建稱為model的TitanicModel實(shí)例,我們將在訓(xùn)練數(shù)據(jù)上進(jìn)行訓(xùn)練。
訓(xùn)練模型 (Training the Model)
Now comes the cool part — the actual training! For this we need to make a fit_one_cycle function to do the training for our model. Like any usual fit functions this one uses an optimizer to adjust the models parameters with a certain learning rate according to the gradients (the gradients are just the partial derivatives for each parameter with respect to the loss) which are obtained by backpropagating the loss backwards through the model. Here however there are some things about the fit function I want to point out that are not just the usual computing loss and then adjusting weights and biases thing.
現(xiàn)在是最酷的部分-實(shí)際訓(xùn)練! 為此,我們需要?jiǎng)?chuàng)建一個(gè)fit_one_cycle函數(shù)來對(duì)我們的模型進(jìn)行訓(xùn)練。 像任何通常的擬合函數(shù)一樣,該函數(shù)使用優(yōu)化器根據(jù)梯度(梯度只是每個(gè)參數(shù)相對(duì)于損耗的偏導(dǎo)數(shù))以一定的學(xué)習(xí)率調(diào)整模型參數(shù),這些梯度是通過反向傳播損耗而獲得的。該模型。 但是,在這里我要指出一些關(guān)于擬合函數(shù)的問題,這些事情不僅是通常的計(jì)算損失,而且還有調(diào)整權(quán)重和偏差的事情。
Learning rate scheduling: This is a technique replacing the fixed learning rate usually done by changing the learning rate after every batch of training. This can be done several ways but the way we will do it is with the “One Cycle Learning Policy” which starts with a smaller learning rate and then starts to gradually increase for the first 30% of epochs and then decreasing it again for optimal learning. For this scheduler we just need to set the maximum learning rate to which it will increase over time. If you want to go deeper into this topic, I suggest you read this: https://sgugger.github.io/the-1cycle-policy.html
學(xué)習(xí)率安排 :這是一種通常通過在每批培訓(xùn)后更改學(xué)習(xí)率來代替固定學(xué)習(xí)率的技術(shù)。 這可以通過多種方式完成,但是我們將采用“單周期學(xué)習(xí)策略”來實(shí)現(xiàn) ,該策略以較小的學(xué)習(xí)率開始,然后在前30%的時(shí)期開始逐漸增加,然后再次降低以實(shí)現(xiàn)最佳學(xué)習(xí)。 對(duì)于此調(diào)度程序,我們只需要設(shè)置隨時(shí)間增加的最大學(xué)習(xí)率即可。 如果您想更深入地研究這個(gè)主題,建議您閱讀以下內(nèi)容: https : //sgugger.github.io/the-1cycle-policy.html
Weight decay / L2 Regularization: Another thing we use is weight decay which adds the sum of the weights squared to the loss function so that bigger weights will be punished as bigger weights are usually a sign of overfitting. Thereby we make the model able to generalize better and achieve better results on unknown data as the weights are being lowered. See this for more information about weight decay: https://towardsdatascience.com/this-thing-called-weight-decay-a7cd4bcfccab
權(quán)重衰減/ L2正則化 :我們使用的另一種方法是權(quán)重衰減,它會(huì)將權(quán)重的平方和加到損失函數(shù)上,以便懲罰更大的權(quán)重,因?yàn)楦蟮臋?quán)重通常表示過度擬合。 因此,隨著權(quán)重的降低,我們使模型能夠更好地泛化并在未知數(shù)據(jù)上獲得更好的結(jié)果。 請(qǐng)參閱此以獲取有關(guān)體重減輕的更多信息: https : //towardsdatascience.com/this-thing-叫做-weight-decay- a7cd4bcfccab
Gradient clipping: Lastly there is gradient clipping. This is actually quite simple but still very useful. The way gradient clipping works is that it just limits the gradient to a certain value so that if the gradient would take the model in the wrong direction it is limited to a certain size which means that the model can’t be hurt due to large gradient values. Here is an interesting post about it: https://towardsdatascience.com/what-is-gradient-clipping-b8e815cdfb48
漸變裁剪 :最后是漸變裁剪。 這實(shí)際上很簡(jiǎn)單,但仍然非常有用。 漸變裁剪的工作方式是將漸變限制為某個(gè)值,因此,如果漸變將模型沿錯(cuò)誤的方向放置,則將其限制為一定的大小,這意味著不會(huì)因大漸變而傷害模型價(jià)值觀。 這是關(guān)于它的一個(gè)有趣的帖子: https : //towardsdatascience.com/what-is-gradient-clipping-b8e815cdfb48
Now, we should be all set to start the training. First, we compute the accuracy and loss on the validation data to see how good the model initially performed vs how it performs after the training. For the training itself we define the hyperparameters like maximum learning rate, epochs to train for, weigh decay value, gradient clipping and the optimizer which will be the adam optimizer.
現(xiàn)在,我們都應(yīng)該開始培訓(xùn)了。 首先,我們計(jì)算驗(yàn)證數(shù)據(jù)的準(zhǔn)確性和損失,以查看模型最初執(zhí)行的效果與訓(xùn)練后的執(zhí)行效果。 對(duì)于訓(xùn)練本身,我們定義了超參數(shù),例如最大學(xué)習(xí)率,要訓(xùn)練的時(shí)期,權(quán)重衰減值,梯度削波以及將作為亞當(dāng)優(yōu)化器的優(yōu)化器。
After this brief training, our model should be very good at predicting survival for Titanic passengers (Note that it can never be perfect as there is always a component of luck involved in the individual probability for survival). You can also see this when you look at the accuracy and the loss on the validation data and compare it to the one computed before the training. To verify this further, let’s plot the accuracies on the validation data over the course of the training phase as well as the loss on both training data and validation data. This last thing can also show us how much the model is overfitting since as soon as the training data loss decreases, the validation data loss increases or stays the same. We are overfitting since we are getting better and better on the training data, but worse on the validation data which is definitely not what we want. However, the model does not seem to be overfitting, which is great!
經(jīng)過簡(jiǎn)短的培訓(xùn)后,我們的模型應(yīng)該非常擅長預(yù)測(cè)泰坦尼克號(hào)乘客的生存(注意,由于運(yùn)氣總是與個(gè)人生存概率有關(guān),因此它永遠(yuǎn)不可能是完美的)。 當(dāng)您查看驗(yàn)證數(shù)據(jù)的準(zhǔn)確性和損失并將其與訓(xùn)練之前計(jì)算出的值進(jìn)行比較時(shí),也可以看到這一點(diǎn)。 為了進(jìn)一步驗(yàn)證這一點(diǎn),讓我們?cè)谟?xùn)練階段的過程中繪制驗(yàn)證數(shù)據(jù)的準(zhǔn)確性,以及訓(xùn)練數(shù)據(jù)和驗(yàn)證數(shù)據(jù)的損失。 這最后一件事還可以向我們顯示模型有多適合,因?yàn)橐坏┯?xùn)練數(shù)據(jù)丟失減少,驗(yàn)證數(shù)據(jù)丟失就會(huì)增加或保持不變。 我們正在過度擬合,因?yàn)槲覀冊(cè)谟?xùn)練數(shù)據(jù)上越來越好,但在驗(yàn)證數(shù)據(jù)上卻越來越差,這絕對(duì)不是我們想要的。 但是,該模型似乎并不過分?jǐn)M合,這太棒了!
保存模型 (Save the Model)
Now we need to save our model by writing its state which means all of its parameters to a file and log our hyperparameters, final accuracy and final loss so we can later easily compare different model architectures and different choices of hyperparameters to see how well they perform.
現(xiàn)在我們需要通過寫入模型的狀態(tài)來保存模型,這意味著將其所有參數(shù)寫入文件并記錄我們的超參數(shù),最終精度和最終損失,以便稍后可以輕松比較不同的模型架構(gòu)和不同的超參數(shù)選擇,以查看它們的性能如何。
Note that when looking at the weights from the model.state_dict() output we can see how important each of the input values is. For example, we can see that the class is associated with a negative value which is good since people from a class described with a higher number like class 3 were less likely to survive. The next weight shows the extreme importance of the sex for prediction as it is associated with the largest negative value which can be understood, if you know that a man is represented with 1 and a woman with 0. What we can also deduce from the last weight is that the larger the fare paid the higher the survival probability which makes sense, too.
請(qǐng)注意,當(dāng)查看來自model.state_dict()輸出的權(quán)重時(shí),我們可以看到每個(gè)輸入值的重要性。 例如,我們可以看到該類別與一個(gè)負(fù)值相關(guān)聯(lián),這是一個(gè)很好的值,因?yàn)閬碜栽擃悇e的人們用較高的數(shù)字(例如第3類)描述的生存可能性較小。 下一個(gè)權(quán)重顯示了性別對(duì)于預(yù)測(cè)的極端重要性,因?yàn)樗c可以理解的最大負(fù)值相關(guān),如果您知道男人用1表示,女人用0表示。我們也可以從上一個(gè)推論得出權(quán)重是,票價(jià)越高,生存率越高,這也是有道理的。
在樣品上測(cè)試模型 (Test the Model on Samples)
Having the training phase behind us, we can do some testing on various single examples from the validation data to get a feeling for how well the model performs. Therefore, we need to make a function which will return the models prediction for a given dataset element as well as what the person’s data is and whether the person actually survived or not. As you can see in order to display the data it is important that we denormalize our data again by putting all values from the range between 0 and 1 back to their initial range and converting the categorical column Sex back to the strings female and male from the numbers 0 and 1 as which they were represented in the dataset.
有了培訓(xùn)階段,我們可以對(duì)來自驗(yàn)證數(shù)據(jù)的各個(gè)示例進(jìn)行一些測(cè)試,以了解模型的性能。 因此,我們需要?jiǎng)?chuàng)建一個(gè)函數(shù),該函數(shù)將返回給定數(shù)據(jù)集元素的模型預(yù)測(cè),以及該人的數(shù)據(jù)是什么,以及該人是否實(shí)際幸存。 如您所見,為了顯示數(shù)據(jù),重要的是我們?cè)俅螌?duì)數(shù)據(jù)進(jìn)行非規(guī)范化,方法是將0到1之間的所有值都放回其初始范圍,然后將分類列Sex轉(zhuǎn)換為從在數(shù)據(jù)集中表示的數(shù)字0和1。
As expected, the model gets most predictions right with a survival probability that makes complete sense when looking at the input data. Even though it was wrong on the first prediction, this is not a bad sign since there is also always a component of luck involved which makes a case like this not perfectly predictable. If we recall the survival probabilities for the persons of different sexes and of different classes, we can see that the prediction is actually pretty close to that, which I think is a good sign.
正如預(yù)期的那樣,該模型可以通過查看輸入數(shù)據(jù)時(shí)完全有意義的生存概率正確地進(jìn)行大多數(shù)預(yù)測(cè)。 即使在第一個(gè)預(yù)測(cè)中是錯(cuò)誤的,但這也不是一個(gè)壞兆頭,因?yàn)榭倳?huì)有涉及運(yùn)氣的因素,這使得這種情況無法完全預(yù)測(cè)。 如果我們回想起不同性別和不同階級(jí)的人的生存概率,我們可以看到預(yù)測(cè)實(shí)際上與該預(yù)測(cè)非常接近,我認(rèn)為這是一個(gè)好兆頭。
Don’t you want to find out as well whether you would have survived the Titanic disaster. To do this we have a nice function that asks you to input your data and then returns its prediction after converting the categorical values to numericals and normalizing the input data. Just think of a fare reasonable for your chosen class (or not and try to break the predictions). You can, of course, completely make up data to test the model and see which people would have survived.
您是否也不想找出是否可以在泰坦尼克號(hào)災(zāi)難中幸存下來。 為此,我們有一個(gè)很好的函數(shù),要求您輸入數(shù)據(jù),然后在將分類值轉(zhuǎn)換為數(shù)值并對(duì)輸入數(shù)據(jù)進(jìn)行歸一化后返回其預(yù)測(cè)。 只需考慮適合您所選班級(jí)的票價(jià)(否則,請(qǐng)嘗試打破預(yù)期)。 當(dāng)然,您可以完全組成數(shù)據(jù)來測(cè)試模型,并查看哪些人可以幸免。
Lastly we can make a submission .csv file for the Titanic competition on kaggle to become first place p ;).
最后,我們可以為kaggle上的泰坦尼克號(hào)比賽提交.csv文件,以成為第一名p;)。
See the entire notebook here.
在這里查看整個(gè)筆記本。
總結(jié)和未來工作的機(jī)會(huì) (Summary and Opportunities for future work)
Lastly, I want to summarize the amazing things I learned from this nice project at Jovian. The first major takeaway was how to deal with Pandas dataframes and data in general which was usually done for me when I was provided a starter notebook. Now that I did this project from scratch I read about the pandas library and its various functions so I was able to use this data for my project very well. I also learned quite a bit about data normalization.
最后,我想總結(jié)一下我從Jovian的一個(gè)不錯(cuò)的項(xiàng)目中學(xué)到的令人驚奇的事情。 第一個(gè)主要的收獲是如何處理Pandas數(shù)據(jù)框和一般數(shù)據(jù),這在為我提供入門筆記本時(shí)通常為我完成。 現(xiàn)在,我從頭開始做這個(gè)項(xiàng)目,我了解了pandas庫及其各種功能,因此我能夠很好地將這些數(shù)據(jù)用于我的項(xiàng)目。 我還學(xué)到了很多有關(guān)數(shù)據(jù)標(biāo)準(zhǔn)化的知識(shí)。
Another thing I took away from this was a lot of knowledge about Logistic Regression as I read quite a lot on the various approaches. For example, I read about why you would use 1 output neuron vs 2 output neurons for binary classification and came to the result that the usage of 1 output neuron is less prone to overfitting as it has less parameters which makes totally sense. This is also why I used this for my model with the Binary Cross Entropy. Moreover, I learned the math behind regularization to be able to better understand it and implement it which helped a lot when implementing regularization and choosing the weight decay hyperparameter.
我從中學(xué)到的另一件事是關(guān)于邏輯回歸的大量知識(shí),因?yàn)槲覍?duì)各種方法學(xué)到了很多東西。 例如,我讀到了為什么要使用1個(gè)輸出神經(jīng)元而不是2個(gè)輸出神經(jīng)元進(jìn)行二進(jìn)制分類,并且得出的結(jié)果是,使用1個(gè)輸出神經(jīng)元具有較少的參數(shù)就不太容易過擬合,因?yàn)檫@完全有意義。 這也是為什么我將其用于具有二進(jìn)制交叉熵的模型的原因。 此外,我了解了正則化背后的數(shù)學(xué)知識(shí),以便能夠更好地理解它并實(shí)現(xiàn)它,這在實(shí)現(xiàn)正則化和選擇權(quán)重衰減超參數(shù)時(shí)很有幫助。
Not to forget are also the things I learned about the disaster by examining the data and also from additional research, which was very interesting.
我也不要忘記通過檢查數(shù)據(jù)以及從其他研究中學(xué)到的有關(guān)災(zāi)難的知識(shí),這非常有趣。
To sum up, I cannot stress enough on how great such projects are for learning as by doing everything yourself you can learn much better. I feel more comfortable with the PyTorch library and Machine Learning now.
綜上所述,我不能過多強(qiáng)調(diào)此類項(xiàng)目對(duì)學(xué)習(xí)的意義,因?yàn)槟约鹤龅囊磺卸伎梢允鼓鷮W(xué)得更好。 現(xiàn)在,我對(duì)PyTorch庫和機(jī)器學(xué)習(xí)感到更加自在。
I can’t wait to work on more challenging projects in future with other datasets and compete in various interesting Kaggle challenges with all the newly-learned things to deepen my knowledge in the world of AI and have fun. I am really looking forward to doing the thousands of projects that I have in my mind!
我迫不及待地希望將來與其他數(shù)據(jù)集一起從事更具挑戰(zhàn)性的項(xiàng)目,并與所有新近學(xué)習(xí)的知識(shí)一起競(jìng)爭(zhēng)各種有趣的Kaggle挑戰(zhàn),以加深我在AI世界中的知識(shí)并從中獲得樂趣。 我真的很想做我腦海中成千上萬的項(xiàng)目!
翻譯自: https://medium.com/jovianml/https-jovian-ml-undefined-none-titanic-logistic-regression-v-105-cellid-55-bb7b2b1b5de1
pytorch回歸
總結(jié)
以上是生活随笔為你收集整理的pytorch回归_PyTorch:用岭回归检查泰坦尼克号下沉的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 做梦梦到小孩子和狗是什么预兆
- 下一篇: 梦到鸡蛋破碎什么意思