<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Ask Ghassem - Recent questions tagged ai-final</title>
<link>https://ask.ghassem.com/tag/ai-final</link>
<description>Powered by Question2Answer</description>
<item>
<title>How to use Genetic Algorithm to optimize a function?</title>
<link>https://ask.ghassem.com/1010/how-to-use-genetic-algorithm-to-optimize-a-function</link>
<description>&lt;p&gt;Assume the function is defined as $f(x,y)=x^2+y^2-4xy$, and $1\leq x \leq 4,1\leq y \leq 4$. &amp;nbsp;The Genetic Algorithm is selected&amp;nbsp;to maximize the function. If the first population for pairs of $(x,y)$&amp;nbsp;is defined as $S=\{A=(1,2), B=(2,1), C=(2,2), D=(2,3), E=(3,1) \}$.&amp;nbsp;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a) &lt;/strong&gt;Calculate the fitness of each of individuals (A,B,C,D,E) in population if:&amp;nbsp; &amp;nbsp;$\text{fitness function}=f(x,y)$&amp;nbsp;&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;b)&lt;/strong&gt; Calculate the probability of each individual&amp;nbsp;and sort them in descending order. Which individual has the maximum fitness (probability)? $p_{i}=\frac{f_{i}}{\sum_{j=1}^{N} f_{j}}$&lt;br&gt;
&lt;strong&gt;c) &lt;/strong&gt;Draw&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;the roulette wheel and calculate&amp;nbsp;the boundaries for each individual&lt;br&gt;
&lt;strong&gt;d) &lt;/strong&gt;If we use two individuals and their arithmetic mean for crossover each time,&amp;nbsp;and for mutation, we add 0.1 to x and subtract 0.1 from y for each individual created after crossover, what will be the next population with five members?&lt;br&gt;
For part (d), use the following random numbers in order whenever you need them in the selection process:&lt;br&gt;
$\text{random numbers} =&amp;nbsp; \{0.780,0.220,0.776,0.507,0.822,0.765,0.288,0.881,0.895,0.421\}$&lt;br&gt;
&amp;nbsp;&lt;/p&gt;</description>
<category>Artificial Intelligence</category>
<guid isPermaLink="true">https://ask.ghassem.com/1010/how-to-use-genetic-algorithm-to-optimize-a-function</guid>
<pubDate>Tue, 07 Dec 2021 23:53:51 +0000</pubDate>
</item>
<item>
<title>How to create a Decision Tree using the ID3 algorithm?</title>
<link>https://ask.ghassem.com/1008/how-to-create-a-decision-tree-using-the-id3-algorithm</link>
<description>&lt;p&gt;NASA wants to be able to discriminate between Martians (M) and Humans (H) based on the&lt;br&gt;
following characteristics: Green ∈{N, Y }, Legs ∈{2, 3}, Height ∈{S, T}, Smelly ∈{N, Y }.&lt;br&gt;
Our available training data is as follows:&lt;/p&gt;

&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://i.imgur.com/3bC391L.png&quot;&gt;https://i.imgur.com/3bC391L.png&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a)&amp;nbsp;&lt;/strong&gt;Greedily learn a decision tree using the ID3 algorithm and draw the tree.&lt;br&gt;
&lt;strong&gt;b)&amp;nbsp;&lt;/strong&gt;Write the learned concept for Martian as a set of conjunctive rules (e.g., if (green=Y&lt;br&gt;
and legs=2 and height=T and smelly=N), then Martian; else if ... then Martian; ...; else&lt;br&gt;
Human).&lt;/p&gt;</description>
<category>Machine Learning</category>
<guid isPermaLink="true">https://ask.ghassem.com/1008/how-to-create-a-decision-tree-using-the-id3-algorithm</guid>
<pubDate>Wed, 01 Dec 2021 11:26:02 +0000</pubDate>
</item>
<item>
<title>How to calculate the class probabilities and classify using Naive Bayes classifier?</title>
<link>https://ask.ghassem.com/899/calculate-class-probabilities-classify-using-classifier</link>
<description>&lt;p&gt;We have data on 1000 pieces of fruit. The fruit being a Banana, Orange or some Other fruit and imagine we know 3 features of each fruit, whether it’s long or not, sweet or not and yellow or not, as displayed in the table below:&lt;/p&gt;

&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://i.imgur.com/gOFzVXL.png&quot;&gt;https://i.imgur.com/gOFzVXL.png&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A&amp;nbsp;piece of an unknown fruit with these features are provided:&amp;nbsp;Long, Sweet and Yellow.&amp;nbsp;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Calculate probability of each of these 3 classes based on Naive Bayes Classification algorithm and report the class.&lt;/strong&gt;&lt;/p&gt;</description>
<category>Machine Learning</category>
<guid isPermaLink="true">https://ask.ghassem.com/899/calculate-class-probabilities-classify-using-classifier</guid>
<pubDate>Mon, 10 Aug 2020 21:26:28 +0000</pubDate>
</item>
<item>
<title>How to calculate Accuracy, Precision, Recall or F1?</title>
<link>https://ask.ghassem.com/789/how-to-calculate-accuracy-precision-recall-or-f1</link>
<description>&lt;p&gt;In the following example, calculate&amp;nbsp;Accuracy, Precision, Recall or F1?&lt;/p&gt;

&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://i.imgur.com/OezFpqC.png&quot;&gt;https://i.imgur.com/OezFpqC.png&lt;/a&gt;&lt;/p&gt;</description>
<category>Machine Learning</category>
<guid isPermaLink="true">https://ask.ghassem.com/789/how-to-calculate-accuracy-precision-recall-or-f1</guid>
<pubDate>Mon, 27 Jan 2020 19:22:26 +0000</pubDate>
</item>
<item>
<title>How to calculate the class probabilities and classify using Naive Bayes classifier for NLP?</title>
<link>https://ask.ghassem.com/654/calculate-class-probabilities-classify-using-classifier</link>
<description>&lt;p&gt;We want to use Naive Bayes for tagging documents. It is a classification task that we want to assign a class (tag) to each string. We currently have two tags: &lt;strong&gt;Sport &lt;/strong&gt;and&lt;strong&gt; &lt;/strong&gt;&lt;strong&gt;Not Sport&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Which tag does the sentence&amp;nbsp;&lt;strong&gt;&lt;em&gt;A very close game&lt;/em&gt;&amp;nbsp;&lt;/strong&gt;belong to? Using Naive Bayes classifier, calculate the class probability for &lt;strong&gt;Sport&lt;/strong&gt; and &lt;strong&gt;Not sport &lt;/strong&gt;for this sentence based on&amp;nbsp;the dataset and decide about the tag.&lt;/p&gt;

&lt;table border=&quot;1px&quot; cellpadding=&quot;1px&quot; style=&quot;width:500px&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Text&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Tag&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;“A great game”&lt;/td&gt;
&lt;td&gt;Sports&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;“The election was over”&lt;/td&gt;
&lt;td&gt;Not sports&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;“Very clean match”&lt;/td&gt;
&lt;td&gt;Sports&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;“A clean but forgettable game”&lt;/td&gt;
&lt;td&gt;Sports&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;“It was a close election”&lt;/td&gt;
&lt;td&gt;Not sports&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;</description>
<category>Machine Learning</category>
<guid isPermaLink="true">https://ask.ghassem.com/654/calculate-class-probabilities-classify-using-classifier</guid>
<pubDate>Wed, 26 Jun 2019 19:43:41 +0000</pubDate>
</item>
<item>
<title>How to calculate convolutions on a CONV layer for a Convolutional Neural Network?</title>
<link>https://ask.ghassem.com/650/calculate-convolutions-layer-convolutional-neural-network</link>
<description>&lt;p&gt;Assume we have a $5\times5$ px&amp;nbsp;RGB image with 3&amp;nbsp;channels respectively for R, G, and B. If&lt;/p&gt;

&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; style=&quot;height:100px; width:100px&quot;&gt;
&lt;caption&gt;R&lt;/caption&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; style=&quot;height:100px; width:100px&quot;&gt;
&lt;caption&gt;G&lt;/caption&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; style=&quot;height:100px; width:100px&quot;&gt;
&lt;caption&gt;B&lt;/caption&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;We have one&amp;nbsp;$3\times3$ px kernel (filter) with 3 channels as follows:&lt;/p&gt;

&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; style=&quot;height:100px; width:100px&quot;&gt;
&lt;caption&gt;Filter - R&lt;/caption&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; style=&quot;height:100px; width:100px&quot;&gt;
&lt;caption&gt;Filter - G&lt;/caption&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;-1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;-1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; style=&quot;height:100px; width:100px&quot;&gt;
&lt;caption&gt;Filter - B&lt;/caption&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;-1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;-1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; If&amp;nbsp;&lt;strong&gt;Stride = 2&lt;/strong&gt;,&lt;strong&gt; &lt;/strong&gt;and&lt;strong&gt;&amp;nbsp;Zero-padding = 1&lt;/strong&gt;, and &lt;strong&gt;Bias&amp;nbsp;= 1&lt;/strong&gt;, what will be the result of convolution?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;b)&lt;/strong&gt; What is the result after applying a &lt;strong&gt;ReLU&amp;nbsp;layer ($max(z,0)$)&lt;/strong&gt;on the result with the same size of the reuslt&amp;nbsp;in part a?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;c)&lt;/strong&gt; Calculate the output&amp;nbsp;by applying &lt;strong&gt;max-pooling&lt;/strong&gt; layer with the size of $2\times2$ on the output of part b, and &lt;strong&gt;Stride = 1&lt;/strong&gt;. (hint: max-pooling layer here and&amp;nbsp;usually do not include any zero-paddings)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;d)&lt;/strong&gt; What is the result after applying &lt;strong&gt;flatten&lt;/strong&gt; on the output of part c and creating a vector?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;e)&lt;/strong&gt; Assume the vector you created contains m elements. Consider it as the input vector for a &lt;strong&gt;Softmax&lt;/strong&gt; &lt;strong&gt;Regression classifier&amp;nbsp;&lt;/strong&gt;(without any hidden layers and biases and it is fully connected). Assume there are 2 classes of 0 and 1. For all the weights from&amp;nbsp;each element in the feature vector, the optimized weights are 1 for odd elements and 2 for even elements. For example, if the feature vector is [10,11,12,13,14], all the weights &lt;strong&gt;from &lt;/strong&gt;10 are 1 (because 10 is element 1 and 1 is odd), all the weights &lt;strong&gt;from&lt;/strong&gt; 11 are 2, all the weights &lt;strong&gt;from&lt;/strong&gt; 12 are&amp;nbsp;1, all the weights &lt;strong&gt;from&lt;/strong&gt; 13 are&amp;nbsp;2 and all the weights &lt;strong&gt;from&lt;/strong&gt; 14 are 1 and so on. Draw the&amp;nbsp;Softmax&amp;nbsp;Regression network and calculate the class should be 0 or 1?&lt;/p&gt;

&lt;p&gt;Hint:&amp;nbsp;&lt;br&gt;
&lt;strong&gt;Softmax Regression:&lt;/strong&gt;&amp;nbsp;$p_{i}=\frac{e^{z_{i}}}{\sum_{i=1}^{c} e^{z_{i}}}$&lt;br&gt;
Where $p_{i}$ is the probability of class $i$ anc $c$ is the number of classes.&lt;/p&gt;</description>
<category>Deep Learning</category>
<guid isPermaLink="true">https://ask.ghassem.com/650/calculate-convolutions-layer-convolutional-neural-network</guid>
<pubDate>Wed, 26 Jun 2019 08:54:12 +0000</pubDate>
</item>
<item>
<title>How to calculate Softmax Regression probabilities in this example?</title>
<link>https://ask.ghassem.com/605/calculate-softmax-regression-probabilities-this-example</link>
<description>&lt;p&gt;The scatter plot of Iris Dataset is shown in the figure below. Assume&lt;strong&gt;&amp;nbsp;Softmax Regression&lt;/strong&gt;&amp;nbsp;is used to classify Iris to Setosa, Versicolor, or Viriginica&amp;nbsp;using just petal length and petal width. If&amp;nbsp; weights required for Softmax&amp;nbsp;Regression initialized to 1 for class Setosa, 2 for class Versicolor, and 3 for Virginica,&lt;/p&gt;

&lt;p&gt;1) What will be the probability of an iris with petal&amp;nbsp;length = 4.6&amp;nbsp; and petal width = 1.7 to be classified as Virginica?&amp;nbsp;&lt;/p&gt;

&lt;p&gt;2) What will be the probability of Virginica, if we use all features&amp;nbsp;petal&amp;nbsp;length = 4.6&amp;nbsp; and petal width = 1.7, sepal length = 5.5 and sepal width = 3.0&amp;nbsp;with the same weight initialization?&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; src=&quot;https://i.imgur.com/CezSTPM.png&quot;&gt;&lt;/p&gt;</description>
<category>Machine Learning</category>
<guid isPermaLink="true">https://ask.ghassem.com/605/calculate-softmax-regression-probabilities-this-example</guid>
<pubDate>Thu, 04 Apr 2019 18:20:53 +0000</pubDate>
</item>
<item>
<title>How to calculate Softmax Regression probabilities?</title>
<link>https://ask.ghassem.com/591/how-to-calculate-softmax-regression-probabilities</link>
<description>&lt;p&gt;The scatter plot of Iris Dataset is shown in the figure below. Assume Softmax Regression is used to classify Iris to Setosa, Versicolor, or Viriginica using just petal length and petal width. If all the weights required for Softmax Regression initialized to 0.5 and the network includes bias nodes:&lt;br&gt;
&lt;br&gt;
1) Write the weight vectors and equations for calculating the class probabilities.&lt;br&gt;
&lt;br&gt;
2) We have a new iris and we have measured petal length = 4.5 &amp;nbsp;and petal width = 1.6. Using the above initial model, what would be the result of classification?&lt;br&gt;
&lt;br&gt;
3) If we change all the weights related to the class blue to 1 and keep all other weights 0.5, what will be the predicted class?&lt;/p&gt;

&lt;p&gt;&lt;img alt=&quot;&quot; src=&quot;https://i.imgur.com/CezSTPM.png&quot;&gt;&lt;/p&gt;</description>
<category>Machine Learning</category>
<guid isPermaLink="true">https://ask.ghassem.com/591/how-to-calculate-softmax-regression-probabilities</guid>
<pubDate>Thu, 21 Mar 2019 16:11:09 +0000</pubDate>
</item>
<item>
<title>What is the difference between a batch and an epoch in a Neural Network?</title>
<link>https://ask.ghassem.com/497/what-the-difference-between-batch-and-epoch-neural-network</link>
<description>Both of the batch size and number of epochs are integer values and seem to do the same thing in Stochastic gradient descent. What are these two hyper-parameters of this learning algorithm?</description>
<category>Machine Learning Interview Questions</category>
<guid isPermaLink="true">https://ask.ghassem.com/497/what-the-difference-between-batch-and-epoch-neural-network</guid>
<pubDate>Tue, 30 Oct 2018 14:45:56 +0000</pubDate>
</item>
</channel>
</rss>