<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by vineel sindiri on Medium]]></title>
        <description><![CDATA[Stories by vineel sindiri on Medium]]></description>
        <link>https://medium.com/@vinneelaero?source=rss-390bca5173fc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*znB5dY5UXy_HFQMbOsxVDg.jpeg</url>
            <title>Stories by vineel sindiri on Medium</title>
            <link>https://medium.com/@vinneelaero?source=rss-390bca5173fc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 20:07:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vinneelaero/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Diamond price prediction based on their cut, colour, clarity, price with PyTorch]]></title>
            <link>https://medium.com/data-science/diamond-price-prediction-based-on-their-cut-colour-clarity-price-with-pytorch-1e0353d2503b?source=rss-390bca5173fc------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e0353d2503b</guid>
            <category><![CDATA[linear-regression]]></category>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning-course]]></category>
            <dc:creator><![CDATA[vineel sindiri]]></dc:creator>
            <pubDate>Mon, 15 Jun 2020 19:10:48 GMT</pubDate>
            <atom:updated>2020-06-16T13:43:32.104Z</atom:updated>
            <content:encoded><![CDATA[<h4>A guide to building a simple Linear Regression model in PyTorch</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*VcjjBv0QmFQ1J_PLmoIfCQ.jpeg" /><figcaption>Source: Opensourceforu.com</figcaption></figure><p>Have you ever asked yourself, how are diamonds priced? Well, this article talks about the diamonds price prediction based on their cut, colour, clarity &amp; other attributes and it also covers the building a simple linear regression model using PyTorch.</p><p>I have started my PyTorch journey with <a href="https://jovian.ml/forum/c/pytorch-zero-to-gans/18">“Deep Learning with PyTorch: Zero to Gans”</a> course and now we are in the second week of this course, till now we have covered the basics and implementation of Linear &amp; Logistic regressions in PyTorch. Please refer to this <a href="https://medium.com/@vinneelaero/introduction-to-basic-pytorch-tensor-functions-51cb5b58713">article</a> for basic PyTorch functions.</p><h3>Intro to Linear Regression:</h3><p>Linear Regression is one of the simplest algorithms in Machine Learning. As per statistics, the term <strong>Regression</strong> is defined as a measure of the relation between an output variable and the input variable(s), hence, Linear Regression assumes a linear relationship between the independent (input) and dependent (output) variable.</p><p>More generally, a linear model makes a prediction by simply computing a weighted sum of the input features, plus a bias (also called the intercept) term. <a href="https://www.oreilly.com/library/view/hands-on-machine-learning/9781492032632/">(Source)</a> as shown in the below equation.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D4&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D4&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd936b15db3b3461eaedd08c0e726e14/href">https://medium.com/media/bd936b15db3b3461eaedd08c0e726e14/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*bV88gfhLSLCc1izXcRePag.png" /><figcaption>Source: CS.Brown.edu</figcaption></figure><p>I have considered the classic Diamonds dataset which contains the prices and other attributes of almost 54,000 diamonds and this dataset is hosted on <a href="https://www.kaggle.com/shivam2503/diamonds">Kaggle</a>. The dataset contains 53940 rows and 10 variables. Before jumping into building the model, let’s have a look into the variables &amp; their definitions.</p><ul><li><strong>Price</strong> is in US dollars</li><li><strong>Carat</strong> weight of the diamond</li><li><strong>Cut</strong> quality of the cut (Fair, Good, Very Good, Premium, Ideal)</li><li><strong>color</strong> diamond colour, from J (worst) to D (best)</li><li><strong>clarity</strong> a measurement of how clear the diamond is (I1 (worst), SI2, SI1, VS2, VS1, VVS2, VVS1, IF (best))</li><li><strong>x</strong> length in mm</li><li><strong>y</strong> width in mm</li><li><strong>z</strong> depth in m</li><li><strong>depth</strong>: The height of a diamond</li><li><strong>table</strong>: The width of the diamond’s table expressed as a percentage of its average diameter</li></ul><h3>Let’s get started to build the linear regression model based on the following steps</h3><ol><li>Import Required Packages</li><li>Load the dataset</li><li>Perform the exploratory data analysis (EDA)</li><li>Prepare the dataset for training</li><li>Create a linear regression model</li><li>Train the model to fit the data</li><li>Make predictions using the trained model</li></ol><h3>Step 1: Import Required Packages</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D9&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D9&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/539536efa2ed76a939d7637c2e0f7b23/href">https://medium.com/media/539536efa2ed76a939d7637c2e0f7b23/href</a></iframe><h3>Step 2: Load the dataset</h3><p>To load the dataset we will be using pd.read_csv()function and it will convert the dataset to a dataframe and have a look into the top 5 rows of dataset using pd.head() function</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D12&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D12&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b57e26a9f2b74b2644fe1210c27ffc3/href">https://medium.com/media/6b57e26a9f2b74b2644fe1210c27ffc3/href</a></iframe><p>Drop the column “Unnamed: 0”, which is unnecessary</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D14&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D14&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/96614ce89fa0e164a88b34aa0695df4b/href">https://medium.com/media/96614ce89fa0e164a88b34aa0695df4b/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D15&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D15&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd84123a8e4c61c89b2f889943021a94/href">https://medium.com/media/fd84123a8e4c61c89b2f889943021a94/href</a></iframe><p>The dataset has 53940 rows &amp; 10 variables</p><h3>Step 3: Exploratory Data Analysis (EDA)</h3><p>Look at the concise summary of the dataset</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D19&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D19&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/6336a02e31bcbf22d8ffbfdd301c54f6/href">https://medium.com/media/6336a02e31bcbf22d8ffbfdd301c54f6/href</a></iframe><p>There is no null data in the dataset and the same can also be checked by using data.isnull().any. The given dataset has 6 numeric columns and three non-numeric (categorical) columns</p><p>Get the descriptive statistics of the dataset using pd.describe()</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D22&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D22&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9ce7a0d6604b6951e8ef25d55ab0ff1/href">https://medium.com/media/f9ce7a0d6604b6951e8ef25d55ab0ff1/href</a></iframe><p>Observed that the minimum value of x (length), y(width) &amp; z(depth) is zero and It doesn’t make any sense to have length\width\depth of a diamond to be zero.</p><p>Let’s drop these rows</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D26&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D26&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/c15dba666c4451cb51d5df32f4d1d71a/href">https://medium.com/media/c15dba666c4451cb51d5df32f4d1d71a/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D27&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D27&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/c647474d9f310b398233efc11843ac7c/href">https://medium.com/media/c647474d9f310b398233efc11843ac7c/href</a></iframe><p>Observed that the minimum values of x,y&amp;z are non-zero values</p><p>Plot the distributions of numerical attributes by using hist() method</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D30&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D30&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/9eb54d2c00bb6b26ca273c7519273dc5/href">https://medium.com/media/9eb54d2c00bb6b26ca273c7519273dc5/href</a></iframe><p>Let&#39;s look at the pair plot of the dataset. Pair plot allows us to see both the distribution of variables and also the relationships between two variables</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D32&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D32&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac1da5edb064bcd9a5b60a37063c9913/href">https://medium.com/media/ac1da5edb064bcd9a5b60a37063c9913/href</a></iframe><p>Observed that x,y&amp;z variables has good correlation with respect to the dependent variable (target) price and let’s quantify that correlation by using .corr() &amp; visualize the same using sns.heatmap() method</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D34&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D34&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/e689fb46087309d7ef58c33d7716bc90/href">https://medium.com/media/e689fb46087309d7ef58c33d7716bc90/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D35&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D35&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/9b2c4ea05a1086e943e7b1cc360a21b5/href">https://medium.com/media/9b2c4ea05a1086e943e7b1cc360a21b5/href</a></iframe><p>We can conclude that carat,x,y &amp; z features have strong correlation w.r.t price variable and depth has a very weak relation w.r.t price variable. Hence, we can drop the depth feature from the final list of input features to the model.</p><p>Let’s have a sense of categorical features with respect to target (price) variable by using box plots</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D38&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D38&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce00f3c2c5f1ff619aa593ba8910a472/href">https://medium.com/media/ce00f3c2c5f1ff619aa593ba8910a472/href</a></iframe><p>I have used the boxplots to compare the data spread, central tendencies (Median), variability amongst the categories of a given categorical variable and these plots also helps to identify the outliers.</p><p>Till now, I have done very preliminary data exploration to understand the features and it&#39;s their relation with respect to the target variable. And the main objective of this article is to implement the linear regression in PyTorch, so let’s stop the data exploration and jump into the main core of the article.</p><p>Before proceeding to build the model, it is good to convert the categorical data to numerical data and there are two ways to convert to numerical form 1. Label Encoder or Integer Encoding 2. One-hot Encoding</p><p>In general, one-hot encoding does a good job and for further details please refer this <a href="https://jovian.ml/outlink?url=https%3A%2F%2Fmachinelearningmastery.com%2Fwhy-one-hot-encode-data-in-machine-learning%2F">link</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D41&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D41&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4016e8125791c22d6260fcd8b2333b1/href">https://medium.com/media/d4016e8125791c22d6260fcd8b2333b1/href</a></iframe><h3>Step 4: Prepare the dataset for training</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D46&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D46&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/e335c7a4ed7beed8acd34a681937bb94/href">https://medium.com/media/e335c7a4ed7beed8acd34a681937bb94/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D47&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D47&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/f87b45235c11ff836f1634f40b087e09/href">https://medium.com/media/f87b45235c11ff836f1634f40b087e09/href</a></iframe><p>We need to convert the data from the Pandas dataframe into PyTorch tensors for training. To do this, the first step is to convert it NumPy arrays</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D49&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D49&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1465e5fab924d9ac0976ff0887856c7/href">https://medium.com/media/b1465e5fab924d9ac0976ff0887856c7/href</a></iframe><p>Now, we need to create PyTorch datasets &amp; data loaders for training &amp; validation. The first step is to create TensorDataset by converting the input &amp; target arrays to tensors by using torch.tensor function</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D52&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D52&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c6a60244e3644a16c993ebd2a91d503/href">https://medium.com/media/8c6a60244e3644a16c993ebd2a91d503/href</a></iframe><p>And now we will be dividing the dataset into training &amp; validation dataset. The training set will be used to train the model and whereas validation set is used to evaluate the model &amp; it also used to tune the hyperparameters (learning rate, epochs, batch size, etc..) for the better generalisation of the trained model.</p><p>We will use the random_split function to split the dataset into train &amp; validation of the desired percent</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D54&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D54&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9a876a994d7fc9534e2b9523019b172/href">https://medium.com/media/b9a876a994d7fc9534e2b9523019b172/href</a></iframe><p>Let’s look at a batch of data to verify everything is working fine so far.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D56&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D56&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/439889f1278413d9b8680f968034f2ec/href">https://medium.com/media/439889f1278413d9b8680f968034f2ec/href</a></iframe><p>The shapes of xb &amp; yb indicate that everything has working fine till now</p><h3>Step 5: Create a linear regression model</h3><p>We will be creating the linear regression model by extending the nn.Module class from PyTorch</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D60&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D60&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/db7d5ea063bf18ea015f3ca7e8d818c4/href">https://medium.com/media/db7d5ea063bf18ea015f3ca7e8d818c4/href</a></iframe><p>Inside the __init__ constructor method, we instantiate the weights and biases using nn.Linear the function. And inside the forward method, which is invoked when we pass a batch of inputs to the model, and it will pass it into self.linear. The defined neural network will look like as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/1*pn0B4bzQ16DAr9-34Q9HpQ.png" /></figure><p>We have defined the model and instantiated the weights &amp; biases. Now, let’s define the cost function.</p><p>The common cost function(J) for linear regression is mean squared error (MSE). This function calculates the difference between the predicted and target values and squares it. Cost function measures to evaluate how good the model performance is.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D63&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D63&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/21d4aa82a155f836b40d64c1141b5f32/href">https://medium.com/media/21d4aa82a155f836b40d64c1141b5f32/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D64&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D64&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/685aedca06772d910ce841fac795d919/href">https://medium.com/media/685aedca06772d910ce841fac795d919/href</a></iframe><p>training_step &amp; validation_step the method computes the predictions &amp; MSE loss for every training &amp; validation batches respectively. validation_epoch_end the method returns the average validation loss for every epoch. Please refer this <a href="https://jovian.ml/forum/t/lecture-2-working-with-images-logistic-regression/1542/333">link</a> to know the difference between epoch &amp; iterations.</p><p>Let’s create a model object by calling DiamondPriceModel() class</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D67&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D67&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/260e7bb96341e3fcde9c1100bbdace5b/href">https://medium.com/media/260e7bb96341e3fcde9c1100bbdace5b/href</a></iframe><h3>Step 6: Train the model to fit data</h3><ul><li>The main objective of linear regression is to minimize the cost function.</li><li><a href="https://jovian.ml/outlink?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DIHZwWFHWa-wis">Gradient Descent</a> is an optimization algorithm which helps to minimize the cost function and its main aim is to find out the global minima. Here, gradient represents the rate of change of a function and it points in the direction of greatest increase of the function. To minimize the cost function, we need to perform the gradient of our cost function (J) with respect to its parameters (weights(w) &amp; biases(b)).</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D70&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D70&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/fec62684bc2ca05d8b7b165765ec1eb5/href">https://medium.com/media/fec62684bc2ca05d8b7b165765ec1eb5/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HrFZV7pKPcc5dzLaWvngtQ.png" /><figcaption>Source : <a href="http://rasbt.github.io/">http://rasbt.github.io/</a></figcaption></figure><p><strong>NOTE</strong>: The learning rate α is a way to control how much we update the weights by. If we choose a small learning rate, it may take a long time for our model to train. However, if we choose a large learning rate, we may overshoot and our training will never converge. The specific learning rate depends on our data and the type of models we use but it’s typically good to explore in the range of [1e−8,1e−1].</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D72&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D72&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/b029325f63e38463f5f6d440bd1fa828/href">https://medium.com/media/b029325f63e38463f5f6d440bd1fa828/href</a></iframe><p>evaluate function, which invokes validation_step &amp; validation_epoch_end methods and returns the average validation loss after every epoch.</p><p>fit function performs the model training by updating the parameters for each step with the help of <a href="https://jovian.ml/outlink?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DW9iWNJNFzQI">stochastic gradient descent</a>(A variant of gradient descent) optimization. It records the validation loss from each epoch and returns a history of the training process.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D74&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D74&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/4700dca0f618ee18084137f5ae5541a3/href">https://medium.com/media/4700dca0f618ee18084137f5ae5541a3/href</a></iframe><p>The initial validation loss very high, which is what one might expect from a randomly initialized model. The objective is to minimize this loss using sufficient epoch and suitable learning rate. This is a trial and error process to generate the best fit for our model.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D76%26hideOutput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D76%26hideOutput%3Dtrue&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/94b092b4c392368385290f8fdcd695af/href">https://medium.com/media/94b092b4c392368385290f8fdcd695af/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D77%26hideOutput%3Dtrue&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D77%26hideOutput%3Dtrue&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/a941fd06905f81d3857e3ea155d2279a/href">https://medium.com/media/a941fd06905f81d3857e3ea155d2279a/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D78&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D78&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/707f7d3425caaee7e60b2c0244fde230/href">https://medium.com/media/707f7d3425caaee7e60b2c0244fde230/href</a></iframe><p>Ran the model for 800 epochs and the validation loss has been reduced to 1276336.0000. Now, let’s test the model with validation data.</p><h3>Step 7: Test the model on validation data</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D83&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D83&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf027f7a5fdc1b46bb1b54890f437dda/href">https://medium.com/media/bf027f7a5fdc1b46bb1b54890f437dda/href</a></iframe><p>predict_single function returns the predicted diamond price value for a given input tensor.</p><p>Test # 1</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D85&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D85&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/d99c932f010421d722e6be62da0b7723/href">https://medium.com/media/d99c932f010421d722e6be62da0b7723/href</a></iframe><p>Test # 2</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D86&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fdiamond-prediction-linear%2Fv%2F3%26cellId%3D86&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/b502d431f67e53f8bbd083742b3d9ef5/href">https://medium.com/media/b502d431f67e53f8bbd083742b3d9ef5/href</a></iframe><p>The model performance can improve by introducing the hidden layers to the current model, and can further improve the optimizer to <a href="https://jovian.ml/outlink?url=https%3A%2F%2Farxiv.org%2Fabs%2F1412.6980">Adam optimizer.</a></p><p><strong>Code Repository: </strong>You can find the notebook at my <a href="https://github.com/vineel369/DeepLearning-with-PyTorch/blob/master/01_Linear%20Regression/Linear_Regression_with_Pytorch_Diamond_Price_prediction_final.ipynb">GitHub repo</a>.</p><p>Well !! we have just completed our first machine learning alogirth using PyTorch. Thanks for Reading !! and try yourself with your own dataset.</p><p>Happy Learning ! Happy coding !</p><h3>References:</h3><ol><li><a href="https://www.youtube.com/watch?v=4ZZrP68yXCI&amp;feature=youtu.be">https://www.youtube.com/watch?v=4ZZrP68yXCI&amp;feature=youtu.be</a></li><li><a href="https://github.com/madewithml/basics/blob/master/notebooks/07_Linear_Regression/07_PT_Linear_Regression.ipynb">https://github.com/madewithml/basics/blob/master/notebooks/07_Linear_Regression/07_PT_Linear_Regression.ipynb</a></li><li><a href="https://cs.brown.edu/courses/csci1951-a/assignments/stats_handout.html">https://cs.brown.edu/courses/csci1951-a/assignments/stats_handout.html</a></li><li><a href="https://jovian.ml/forum/c/pytorch-zero-to-gans/18">https://jovian.ml/forum/c/pytorch-zero-to-gans/18</a></li><li><a href="https://www.kaggle.com/shivam2503/diamonds">https://www.kaggle.com/shivam2503/diamonds</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e0353d2503b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/diamond-price-prediction-based-on-their-cut-colour-clarity-price-with-pytorch-1e0353d2503b">Diamond price prediction based on their cut, colour, clarity, price with PyTorch</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to basic PyTorch tensor functions]]></title>
            <link>https://medium.com/@vinneelaero/introduction-to-basic-pytorch-tensor-functions-51cb5b58713?source=rss-390bca5173fc------2</link>
            <guid isPermaLink="false">https://medium.com/p/51cb5b58713</guid>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[tensor]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[vineel sindiri]]></dc:creator>
            <pubDate>Wed, 03 Jun 2020 12:37:41 GMT</pubDate>
            <atom:updated>2020-06-03T12:37:41.070Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Source : https://engineering.fb.com/ai-research/facebook-accelerates-ai-development-with-new-partners-and-production-capabili" src="https://cdn-images-1.medium.com/max/1024/1*oLcN6Vlpa-PrxnRYJGnXDQ.png" /><figcaption>Source : Facebook AI research</figcaption></figure><p>This article is a part of “<a href="https://jovian.ml/forum/c/pytorch-zero-to-gans/18">Deep Learning with Pytorch : Zero to GANs</a>” course, provided by <a href="http://jovian.ml/">Jovian ML</a> &amp; <a href="https://www.freecodecamp.org/">freeCodeCamp</a> and in its first week of the course, covered the basic PyTorch tensors &amp; linear regression in PyTorch. Objective of this article is to talk about some of the basic tensor operations.</p><h3><strong>Introduction</strong></h3><p>PyTorch is an open source deep learning framework, developed by Facebook’s AI research lab. Tensors are fundamental data structures in PyTorch. Tensor is a data collector and in general it is an array of n- dimensional. For example: Scalar is a 0-D tensor, Vector is a 1-D tensor, Matrices are 2-D tensors and so on. PyTorch tensors are similar to <a href="https://medium.com/numpy.org">Numpy</a> arrays but with a difference that PyTorch tensors can be instantiated on GPUs for parallel computing.</p><p>Let’s get started</p><h3>Function 1 : Torch.Tensor</h3><p>torch.tensor(<em>data</em>, <em>dtype=None</em>, <em>device=None</em>, <em>requires_grad=False</em>, <em>pin_memory=False</em>) → Tensor</p><p>This function converts input data to a tensor and the input data can be a list, tuple, NumPy array, scalar, and other types.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D4&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D4&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d44e112d2fc4dfe22e0c5b48d7008cb/href">https://medium.com/media/3d44e112d2fc4dfe22e0c5b48d7008cb/href</a></iframe><p>This example shows that a list has been converted to a tensor by using torch.tensor() function . The dimension of the tensor can be extracted by using dim() function and the shape of the tensor can be inspected by using .shape() function, which outputs the length of the tensor along each dimension</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D5&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D5&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/8455777a93acd17c4d793e89dd4f9b09/href">https://medium.com/media/8455777a93acd17c4d793e89dd4f9b09/href</a></iframe><p>It shows that, the output tensor is an one dimensional and of size 4.</p><p>Creating tensor from a nested list</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D6&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D6&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/118d2b4c391bfdc3ec6ee2458e1cb128/href">https://medium.com/media/118d2b4c391bfdc3ec6ee2458e1cb128/href</a></iframe><p>Creating a tensor from numpy array</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D7&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D7&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/7dc0d2c83e3d5e9fa94bd69e2e99965c/href">https://medium.com/media/7dc0d2c83e3d5e9fa94bd69e2e99965c/href</a></iframe><h3>Function 2: Torch.Randn</h3><p>torch.randn(<em>*size</em>, <em>out=None</em>, <em>dtype=None</em>, <em>layout=torch.strided</em>, <em>device=None</em>, <em>requires_grad=False</em>) → Tensor</p><blockquote>torch.randn returns a tensor with randomly filled elements from a <a href="https://jovian.ml/outlink?url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FNormal_distribution">normal distribution</a> with mean 0 &amp; standard deviation 1 and the shape of the tensor determined by the size argument</blockquote><pre><em>#Example 1 - working</em><br>tensor_rand = torch.randn((6))<br>tensor_rand<br>## Output ##<br>tensor([-0.8254, -0.2660, -0.7612,  0.7048, -1.8596, -1.2513])</pre><pre><em>#Example 2 - working</em><br>tensor_rand1 = torch.randn((4,5))<br>tensor_rand1<br>## Output ##<br>tensor([[-0.7198,  0.2343, -1.1689, -1.9184, -0.8556],<br>        [ 0.5851,  0.9229, -0.2094,  0.0444,  0.3789],<br>        [-1.7424,  0.0966, -0.3040, -2.2399,  0.1730],<br>        [ 0.9268, -1.5848,  0.3625,  0.8362, -0.4173]])</pre><p>The above examples returns the tensors &amp; their shapes are matched with size argument 6 and all the elements are randomly picked from standard normal distribution. Also, check <a href="https://jovian.ml/outlink?url=https%3A%2F%2Fpytorch.org%2Fdocs%2Fstable%2Ftorch.html%3Fhighlight%3Dtorch%2520rand%23torch.rand">troch.rand</a> function, which returns a tensor filled with random numbers from a uniform distribution on the interval [0,1)</p><h3>Function 3: Torch.Arange</h3><p>torch.arange(<em>start=0</em>, <em>end</em>, <em>step=1</em>, <em>out=None</em>, <em>dtype=None</em>, <em>layout=torch.strided</em>, <em>device=None</em>, <em>requires_grad=False</em>) → Tensor</p><blockquote>torch.arange function returns a 1-D tensor with sequence of evenly spaced values within the given range [start &amp; end). It requires atleast one argument i.e. end and the deafult value of the start &amp; step arguments are 0 &amp; 1 respectively</blockquote><blockquote>This function is similar to <a href="https://jovian.ml/outlink?url=https%3A%2F%2Fnumpy.org%2Fdoc%2Fstable%2Freference%2Fgenerated%2Fnumpy.arange.html">numpy.arange</a> function</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D13&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D13&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ba8d24f75024834826fbd75a86014f6/href">https://medium.com/media/7ba8d24f75024834826fbd75a86014f6/href</a></iframe><p>Returns a 1D tensor of 10 values with evenly spaced of step size 1 and all are integers. This function consider the end point as end- stepsize and so the end point in this example will be 9 (= 10 -1)</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D15&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D15&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/460bfa90a4729ad884c3196632796a28/href">https://medium.com/media/460bfa90a4729ad884c3196632796a28/href</a></iframe><p>Returns a 1D tensor of evenly spaced values starting from 2 to 30. Observed that the tensor elements are rounded, since the given data type is an integer and also noticed that the space between the consecutive elements doesn’t match with the given step size</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D17&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D17&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1e4f04a3af4a6f0c51ab02d01c9cdf1/href">https://medium.com/media/b1e4f04a3af4a6f0c51ab02d01c9cdf1/href</a></iframe><p>In this example the data type has changed to float and now noticed that the space between the consecutive elements were exactly matches with the given step size 2.5</p><h3><strong>Function 4: Torch.Flatten</strong></h3><p>torch.flatten(<em>input</em>, <em>start_dim=0</em>, <em>end_dim=-1</em>) → Tensor</p><blockquote>This function helps to flattens the input(multiple dimensions) to a dimension tensor. It is a combination of <a href="https://jovian.ml/outlink?url=https%3A%2F%2Fpytorch.org%2Fdocs%2Fstable%2Ftorch.html%3Fhighlight%3Dtorch%2520reshape%23torch.reshape">torch.reshape</a> &amp; <a href="https://jovian.ml/outlink?url=https%3A%2F%2Fpytorch.org%2Fdocs%2Fstable%2Ftorch.html%3Fhighlight%3Dtorch%2520squeeze%23torch.squeeze">torch.squeeze</a> functions.</blockquote><blockquote>It requires atleast one argument, i.e. a tensor. Start &amp; end dimensions are optional &amp; default values are 0 &amp; -1 respectively</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D23&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D23&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/68c4c9826e361cd84c4c811c46558399/href">https://medium.com/media/68c4c9826e361cd84c4c811c46558399/href</a></iframe><p>This example returns a input tensor of size (3,2) to a 1-D tensor of size (6), which is equal to number of elements in the input tensor</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D25&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D25&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/80755ed1b4efbdd19bef2219c2bf9b05/href">https://medium.com/media/80755ed1b4efbdd19bef2219c2bf9b05/href</a></iframe><p>First example shows that the whole input tensor flattened to a 1-D tensor, however, it is possible to flattens only specific parts of input tensor, which is shown in 2nd example.</p><p>Input tensor of size (2,2,3) flattens to a size of (2,6).</p><h3>Function 5 — matrix multiplications — (torch.mm/mv)</h3><p>torch.mm(<em>input</em>, <em>mat2</em>, <em>out=None</em>) → Tensor</p><p>torch.mv(<em>input</em>, <em>vec</em>, <em>out=None</em>) → Tensor</p><blockquote>torch.mm - Performs a matrix multiplication of the two matrices and torch.mv - Performs a matrix-vector product of the matrix and vector</blockquote><blockquote>These functions does not do broadcasting</blockquote><p>To perform matrix multiplication, the no. of. columns in matrix_1(input) should be equal to no. of. rows in matrix_2 (mat2).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uzPriRLqmXyFBMtHM_i5uQ.png" /><figcaption>Source : Wikipedia</figcaption></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D32&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D32&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/f62c4e48bfe845d951edae555769b38c/href">https://medium.com/media/f62c4e48bfe845d951edae555769b38c/href</a></iframe><p>This example returns a tensor of size (3,2); matrix_1 is a (3 x 3) tensor &amp; matrix_2 is a (3 x 2) tensor and the resultant matrix multiplication is a (3 x 2) tensor</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D34&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D34&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/50a3cbadcc9ce7b52d20ec687fa8d9d0/href">https://medium.com/media/50a3cbadcc9ce7b52d20ec687fa8d9d0/href</a></iframe><p>This example returns a tensor of size (3); matrix_1 is a (3 x 2) tensor &amp; vec is a 1-D tensor of size 2 and the resultant matrix-vector multiplication is a 1-D tensor of size 3</p><h3>Function 6 — Torch.Argmax</h3><p>torch.argmax(<em>input</em>) → LongTensor</p><blockquote>This function returns the indices of the maximum value of all elements in the input tensor. To get the indices of the minimum value, check <a href="https://pytorch.org/docs/stable/torch.html?highlight=torch%20argmin#torch.argmin">torch.argmin() </a>function</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D40&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D40&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/1de8d3596f83f983e3ad06d022d65e27/href">https://medium.com/media/1de8d3596f83f983e3ad06d022d65e27/href</a></iframe><p>This example returns the indices of the maximum value of the input tensor. Maximum value of the input tensor is 100 &amp; it’s index is 3</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjovian.ml%2Fembed%3Furl%3Dhttps%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D42&amp;dntp=1&amp;display_name=Jovian&amp;url=https%3A%2F%2Fjovian.ml%2Fvineel369%2Fpytorch-zero-to-gan-01-basic-tensor-operations%2Fv%2F2%26cellId%3D42&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fjvn%2Fassets%2Fvineel369%2Fprofile_images%2F10bed6eed7c64d6888a73f34a1e9caf2%2Fmedium.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=jovian" width="800" height="200" frameborder="0" scrolling="no"><a href="https://medium.com/media/f4a2dbee288394fdb6d13f5d054e5fda/href">https://medium.com/media/f4a2dbee288394fdb6d13f5d054e5fda/href</a></iframe><p>This example returns the indices of the maximum value of the input tensor along row axis and the output tensor is a 1-D tensor.</p><h3>Function 7 — Torch.Tensor.Item</h3><p>item() → number</p><blockquote>Returns the value of the tensor as a standard Python number.This only works for tensors with one element. For other cases, see <a href="https://pytorch.org/docs/stable/tensors.html?highlight=torch%20tensor%20item#torch.Tensor.tolist">tolist()</a>.</blockquote><pre><em># Example 1 - working</em><br>t1 = torch.tensor([100])<br>print(t1)<br>t1.item()</pre><pre>##Output##<br>tensor([100])<br>100</pre><pre><em># Example 2 - working</em><br>t2 = torch.tensor([[99]])<br>print(t2)<br>t2.item()<br>##Output##<br>tensor([[99]])<br>99</pre><p>In both the cases .item() returns a standard number from a given tensor input</p><h3>Conclusion</h3><p>We have discussed upon a few basic tensor functions with this, we can start messing around the tensors in PyTorch. For further exploration of these kind of functions on your own, visit the official PyTorch documentation. To learn more about Deep Learning with Pytorch, visit this <a href="https://jovian.ml/forum/c/pytorch-zero-to-gans/18">site</a>.</p><h3>References:</h3><ol><li><a href="https://jovian.ml/vineel369/pytorch-zero-to-gan-01-basic-tensor-operations">https://jovian.ml/vineel369/pytorch-zero-to-gan-01-basic-tensor-operations</a></li><li><a href="https://pytorch.org/docs/stable/tensors.html">PyTorch official documentation</a></li><li><a href="https://jovian.ml/outlink?url=https%3A%2F%2Fdeeplizard.com%2Flearn%2Fvideo%2FfCVuiW9AFzY">https://deeplizard.com/learn/video/fCVuiW9AFzY</a></li></ol><p>I hope you enjoyed reading and learned something new. Eager to see some constructive feedback from you guys on my first blog post and also Let me know any interesting functions you were explored. Any questions, happy to help !!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51cb5b58713" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>