Original Source Here

## 01. How could multi-label classification improve the usability of the bear classifier?

**Multi-Label Classification:** An `image classification`

task where each image has zero or more instances of two or more labels. It uses the `sigmoid`

function in the `final`

layer of the deep learning model to convert the `predicted`

values in the `input`

tensor into `probability`

values that range between the `0.0`

and `1.0`

float. It also treats each label as its own `binary classification`

task that’s calculated separately from the other labels.

- The bear classifier uses the
`multi-class`

classification model to predict whether an image contains a grizzly, black, or teddy bear. It predicts one of those three classes even when there are none in the image. It would also be helpful to have a class to represent when no classes are present.

## 02. How do we encode the dependent variable in a multi-label classification problem?

**One-Hot Encoding: **A `preprocessing`

technique that converts `categorical`

data into `numerical`

data. It converts each `label`

value into a `list`

object that contains multiple `0`

integers that represent all the unique `label`

values in `alphabetical`

order. It also represents the `label`

value as the `1`

integer.

`Dependent`

variables are encoded as`0`

and`1`

integers in the`list`

object.

## 03. How do you access the rows and columns of a DataFrame as if it was a matrix?

**Iloc:** A property that selects the data in the specified rows and columns in the `DataFrame`

object using the `slice`

operator. It sets the `start`

parameter in the `slice`

operator to the `integer`

value to specify the rows. It sets the `stop`

parameter in the `slice`

operator to the `integer`

value to specify the columns. It also returns the selected data in the `Series`

or `DataFrame`

object.

`data_frame.iloc[rows_selection, column_selection]`

## 04. How do you get a column by name from a DataFrame?

**Indexing:** A modified operator that selects the data in the specified column in the `DataFrame`

using the column name. It sets the `colname`

parameter in the modified `index`

operator to the `string`

value to specify the column name. It also returns the selected data in the `Series`

or `DataFrame`

object.

`data_frame["column_name"]`

## 05. What is the difference between a `Dataset`

and `DataLoader`

?

The `Datasets`

and `DataLoader`

objects perform complementary tasks:

- The
`Datasets`

object loads the the custom dataset into memory. It pre-processes the dataset to produce the`input`

and`label`

values in the subsets. It also splits the data into the`training`

and`validation`

sets. - The
`DataLoaders`

object separates the data in the`Datasets`

object into mini-batches. It can shuffle the data before the data is separated. It can also pass the mini-batches to the`Learner`

object using`multi`

processing.

## 06. What does a `Datasets`

object normally contain?

**Datasets:** A class that preprocesses the custom dataset by applying the specified `transformation`

functions to the specified `input`

data. It sets the `items`

parameter to the data in the `list`

object to specify the `input`

data. It sets the `tfms`

parameter to the `input`

and `label`

functions in the `list`

objects in the `list`

object to specify the `transformation`

functions. It also returns the `input`

and `label`

values in the `tuple`

objects in the `training`

and `validation`

sets in the `Datasets`

objects in the `Datasets`

object.

- It contains the training and validation
`Datasets`

objects.

`Datasets(items = data, tfms = [[input_functions], [label_functions]]`

## 07. What does a DataLoaders object normally contain?

**DataLoaders: **A class that separates the data in the `Datasets`

object into mini-batches. It can shuffle the data before the data is separated. It can pass the mini-batches to the `Learner`

object using `multi`

processing. It sets the `dataset`

parameter to the `Datasets`

object to specify the data. It also returns the mini-batches in the `DataLoader`

objects in the `DataLoaders`

object.

- It contains the training and validation
`DataLoader`

objects.

## 08. What does `lambda`

do in Python?

**Lambda:** A keyword that defines an `anonymous`

function with no function name. It can use `multiple`

parameters to perform `1`

expression using `1`

line of code. It can be passed to the parameter in other functions. It can also return the result of the expression without using the `return`

statement.

The Lambda keyword can’t be exported to use in deployment or production.

`lambda parameters: expression`

## 09. What are the methods to customize how the independent and dependent variables are created with the data block API?

**Independent Variable:** A variable that represents the `input`

values that are passed to the model to predict the `output`

values. It directly affects the `output`

value as its value changes. It doesn’t depend on any other variables in the equation. It also gets represented as the `X`

letter in the equation.

**Dependent Variable:** A variable that represents the `label`

values that are passed to the model to predict the `output`

values. It changes as the value of the `independent`

variable changes. It depends on the `independent`

variable in the equation. It also gets represented as the `Y`

letter in the equation.

**Get_X:**A function that creates the`independent`

variables. It defines the preprocessing steps to apply to the data that’s passed to the`DataBlock`

object. It also gets passed to the`get_x`

parameter in the`DataBlock`

class.**Get_Y:**A function that creates the`dependent`

variables. It defines the preprocessing steps to apply to the data that’s passed to the`DataBlock`

object. It also gets passed to the`get_y`

parameter in the`DataBlock`

class.

## 10. Why is softmax not an appropriate output activation function when using a one hot encoded target?

**Softmax:** A function that’s commonly used as the `final`

layer in the deep learning model to convert the `predicted`

values into `probability`

values. It calculates the `probability`

values by dividing the exponential of the `predicted`

values by the sum of the exponential of the `predicted`

values. It also returns the `probability`

values as `float`

values in the `output`

tensor.

- The
`Softmax`

function isn’t appropriate to use with the`One-Hot Encoding`

preprocessing technique when performing`multi-label classification`

tasks. This is because it can’t handle images with`multiple`

or`no`

labels.

The

`and`

softmax`functions are used to calculate the`

nll_loss`value within the`

loss`loss function. These functions are only designed for`

cross entropy`tasks where each image has a definite label.`

multi-class classification

## 11. Why is `nll_loss`

not an appropriate loss function when using a one-hot-encoded target?

**Negative Log Likelihood Loss:** A function that calculates the loss using the log of the `probability`

values that are returned by the `softmax`

function. It calculates the mean using the log of the `probability`

values for the `label`

values. It also returns the mean as the `float`

value in the `output`

tensor.

- The
`NLL_Loss`

function isn’t appropriate to use with the`One-Hot Encoding`

preprocessing technique when performing`multi-label classification`

tasks. This is because it can’t handle images with`multiple`

or`no`

labels.

The

`and`

softmax`functions are used to calculate the`

nll_loss`value within the`

loss`loss function. These functions are only designed for`

cross entropy`tasks where each image has a definite label.`

multi-class classification

## 12. What is the difference between `nn.BCELoss`

and `nn.BCEWithLogitsLoss`

?

**Binary Cross Entropy Loss:** A function that calculates the loss using the log of the `probability`

values that are returned by the `sigmoid`

function. It calculates the mean using the log of the `probability`

values for the `label`

values. It also returns the mean as the `float`

value in the `output`

tensor.

- The
`BCELoss`

function doesn’t include the`sigmoid`

function. It expects the`input`

tensor to contain the`probability`

values that are returned by the`sigmoid`

function. - The
`BCEWithLogitsLoss`

function does include the`sigmoid`

function. It expects the`input`

tensor to contain the`predicted`

values that are returned by the model.

The

`loss function is designed for`

binary cross entropy`tasks where each image has`

multi-label classification`or`

multiple`labels.`

no

## 13. Why can’t we use regular accuracy in a multi-label problem?

**Accuracy:** A function that calculates the percentage of correct predictions using the `probability`

values that are returned by the `softmax`

function. It calculates the number of correct predictions by comparing the indexes of the largest `probability`

values to the `label`

values. It calculates the mean using the number of correct predictions that have been converted to `float`

values. It also returns the mean as the `float`

value in the `output`

tensor.

- The
`accuracy`

function uses the`argmax`

function to get the index of the largest`probability`

value in each prediction. It can’t handle predictions with`probability`

values for multiple`label`

values in the same image.

`def accuracy(input_values, label_values, axis=-1):`

predictions = input_values.argmax(dim=axis)

return (predictions == label_values).float().mean()

## 14. When is it okay to tune a hyperparameter on the validation set?

There’s a concern from students that using the `validation`

set to tune the hyperparameters produces results that perform well on the `validation`

set but poorly on the `test`

set. This can occur when the results appear bumpy based on the changes to the hyperparameters. It also represents picking a randomly good value that only accidentally works on the `validation`

set.

- This isn’t a concern when the results appear to be a smooth curve. This indicates the results change gradually based on changes to the hyper-parameters. It also suggests the hyperparameters would produce similar results even when the validation and test sets are slightly different.

## 15. How is y_range implemented in fastai? (See if you can implement it yourself and test it without peeking!)

**Y_Range:** A parameter that specifies the `minimum`

and `maximum`

value that’s used to generate the `predicted`

values when performing `regression`

tasks. It also sets the `sigmoid_range`

function as the `final`

layer in the deep learning model to predict `continuous`

values instead of `categorial`

values.

- The
`Y_Range`

parameter is applied using the`sigmoid_range`

function.

`def sigmoid_range(input, minimum, maximum): `

return torch.sigmoid(input) * (maximum - minimum) + minimum

## 16. What is a regression problem? What loss function should you use for such a problem?

**Regression:** A subcategory of supervised learning that uses `regression`

algorithms to discover the patterns in the dataset to predict `continuous`

values. It identifies the line or curve that best represents the relationship between the `independent`

and `dependent`

variables. It also predicts how the `dependent`

variable changes as one or more `independent`

variables change.

- The
`mean squared error`

loss function is usually used for regression.

## 17. What do you need to do to make sure the fastai library applies the same data augmentation to your inputs images and your target point coordinates?

**PointBlock:** A class that sets the data type of the `input`

or `output`

values in the `DataBlock`

class to two `continuous`

values that represent the `x`

and `y`

coordinate values in an image. It gets passed to the `blocks`

parameter in the `DataBlock`

class to set the data type. It also instructs the `DataBlock`

class to receive or return two `continuous`

values in the `input`

or `output`

tensor.

- The
`PointBlock`

class needs to be passed to the`blocks`

parameter.

AI/ML

Trending AI/ML Article Identified & Digested via Granola by Ramsey Elbasheer; a Machine-Driven RSS Bot