Find Interview Questions for Top Companies
Relinns Technologies Interview Questions and Answers
Ques:- What are axes and figures in Matplotlib’s object-oriented API?
Right Answer:

In Matplotlib's object-oriented API, a **figure** is the overall window or page that contains all the elements of a plot, such as axes, titles, and labels. An **axes** is a specific area within the figure where data is plotted, and it includes the x and y axes, grid, and any data visualizations like lines or bars.

Ques:- How do you add a legend to a plot?
Right Answer:

To add a legend to a plot in Matplotlib, use the `plt.legend()` function after plotting your data. You can specify labels for each plot using the `label` parameter in the plotting functions. For example:

“`python
import matplotlib.pyplot as plt

plt.plot(x, y1, label='Line 1')
plt.plot(x, y2, label='Line 2')
plt.legend()
plt.show()
“`

Ques:- How do you label the x-axis, y-axis, and title of a plot?
Right Answer:

You can label the x-axis, y-axis, and title of a plot in Matplotlib using the following commands:

“`python
import matplotlib.pyplot as plt

plt.xlabel('X-axis Label')
plt.ylabel('Y-axis Label')
plt.title('Plot Title')
“`

Ques:- How do you adjust tick labels, ticks, and gridlines?
Asked In :- Relinns Technologies,
Right Answer:

You can adjust tick labels, ticks, and gridlines in Matplotlib using the following methods:

1. **Set ticks**: Use `plt.xticks()` and `plt.yticks()` to set the positions and labels of the ticks.
2. **Adjust tick labels**: Pass a list of labels to `plt.xticks()` and `plt.yticks()` to customize the tick labels.
3. **Show/hide gridlines**: Use `plt.grid(True)` to show gridlines and `plt.grid(False)` to hide them. You can also customize gridline properties with parameters like `color`, `linestyle`, and `linewidth`.

Ques:- How do you create bar charts, histograms, and pie charts in Matplotlib?
Right Answer:

To create bar charts, histograms, and pie charts in Matplotlib, you can use the following functions:

1. **Bar Chart**: Use `plt.bar(x, height)` where `x` is the list of categories and `height` is the list of values.

“`python
import matplotlib.pyplot as plt
plt.bar(x, height)
plt.show()
“`

2. **Histogram**: Use `plt.hist(data, bins)` where `data` is the list of values and `bins` is the number of bins.

“`python
plt.hist(data, bins)
plt.show()
“`

3. **Pie Chart**: Use `plt.pie(sizes, labels)` where `sizes` is the list of values and `labels` is the list of category names.

“`python
plt.pie(sizes, labels=labels)
plt.show()
“`

Ques:- How does backpropagation work in TensorFlow
Right Answer:
Backpropagation in TensorFlow works by calculating the gradients of the loss function with respect to the model's parameters using the chain rule. When you call `model.fit()` or use `tf.GradientTape()`, TensorFlow automatically computes these gradients during the forward pass and updates the weights during the backward pass to minimize the loss. This process involves propagating the error from the output layer back through the network to adjust the weights accordingly.
Ques:- What are TensorFlow Lite and TensorFlow.js and how do they differ
Right Answer:
TensorFlow Lite is a lightweight version of TensorFlow designed for mobile and embedded devices, enabling on-device machine learning with reduced model size and optimized performance. TensorFlow.js, on the other hand, is a JavaScript library that allows developers to run machine learning models directly in the browser or on Node.js, making it suitable for web applications. The main difference is that TensorFlow Lite is for mobile and embedded systems, while TensorFlow.js is for web and server-side applications.
Ques:- What is TensorFlow and what are its main features
Right Answer:
TensorFlow is an open-source machine learning framework developed by Google. Its main features include:

1. **Flexibility**: Supports various machine learning models and algorithms.
2. **Scalability**: Can run on multiple CPUs and GPUs, making it suitable for large-scale applications.
3. **Ecosystem**: Offers a rich ecosystem of tools and libraries, such as TensorBoard for visualization and TensorFlow Lite for mobile and embedded devices.
4. **Automatic Differentiation**: Facilitates easy computation of gradients for optimization.
5. **Deployment Options**: Allows deployment on various platforms, including cloud, mobile, and edge devices.
Ques:- What is the purpose of dropout in neural networks
Right Answer:
The purpose of dropout in neural networks is to prevent overfitting by randomly setting a fraction of the neurons to zero during training, which helps the model generalize better to new data.
Ques:- What are callbacks in Keras? Can you name a few commonly used ones?
Right Answer:

Callbacks in Keras are functions or methods that are called at certain points during the training process, allowing you to customize the training behavior. Commonly used callbacks include:

1. **ModelCheckpoint** – Saves the model after every epoch.
2. **EarlyStopping** – Stops training when a monitored metric has stopped improving.
3. **ReduceLROnPlateau** – Reduces the learning rate when a metric has stopped improving.
4. **TensorBoard** – Enables visualization of training metrics in TensorBoard.
5. **CSVLogger** – Logs training metrics to a CSV file.

Ques:- What are the advantages of using Keras?
Right Answer:

The advantages of using Keras include:

1. **User-Friendly**: Keras has a simple and intuitive API, making it easy to learn and use.
2. **Modularity**: It allows for easy model building with reusable components.
3. **Flexibility**: Keras supports multiple backends (like TensorFlow, Theano, and CNTK) and can be run on both CPUs and GPUs.
4. **Rapid Prototyping**: It enables quick experimentation and iteration on models.
5. **Extensive Documentation**: Keras has comprehensive documentation and a large community for support.
6. **Pre-trained Models**: It provides access to many pre-trained models for transfer learning.
7. **Integration**: Keras integrates well with other libraries and tools in the TensorFlow ecosystem.

Ques:- How do you evaluate a Keras model’s performance?
Right Answer:

You can evaluate a Keras model's performance using the `evaluate()` method, which takes the test data and labels as input and returns the loss and metrics specified during the model compilation. For example:

“`python
loss, accuracy = model.evaluate(test_data, test_labels)
“`

Ques:- What is Keras, and how does it differ from TensorFlow?
Right Answer:

Keras is an open-source neural network library written in Python that provides a high-level interface for building and training deep learning models. It is designed to be user-friendly and modular. Keras can run on top of various backends, including TensorFlow, which is a more comprehensive framework for machine learning and deep learning that provides lower-level operations and more control over model training and deployment. In summary, Keras simplifies the process of building models, while TensorFlow offers more extensive capabilities and flexibility for complex tasks.

Ques:- How do you apply data transformations using torchvision
Right Answer:
You can apply data transformations using `torchvision.transforms` by creating a composition of transformations with `transforms.Compose()`. For example:

```python
from torchvision import transforms

transform = transforms.Compose([
transforms.Resize((256, 256)),
transforms.ToTensor(),
transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
])
```

Then, you can apply this transform to your dataset when loading it, for example with `ImageFolder` or `Dataset`.
Ques:- How do you perform transfer learning in PyTorch
Right Answer:
To perform transfer learning in PyTorch, follow these steps:

1. **Load a Pre-trained Model**: Use a model from `torchvision.models`, e.g., `model = torchvision.models.resnet18(pretrained=True)`.

2. **Modify the Final Layer**: Replace the final layer to match the number of classes in your dataset:
```python
num_classes = 10 # Example for 10 classes
model.fc = torch.nn.Linear(model.fc.in_features, num_classes)
```

3. **Freeze Layers (Optional)**: Freeze the weights of the earlier layers if you want to retain their learned features:
```python
for param in model.parameters():
param.requires_grad = False
for param in model.fc.parameters():
param.requires_grad = True
```

4. **Set Up the Loss Function and Optimizer**:
```python
criterion = torch.nn.CrossEntropyLoss()
optimizer = torch.optim.SGD
Ques:- What are custom datasets and how do you create one in PyTorch
Right Answer:
Custom datasets in PyTorch are user-defined classes that inherit from `torch.utils.data.Dataset`. To create one, you need to implement three methods: `__init__()` to initialize the dataset, `__len__()` to return the size of the dataset, and `__getitem__()` to retrieve a data sample at a given index. Here's a simple example:

```python
import torch
from torch.utils.data import Dataset

class CustomDataset(Dataset):
def __init__(self, data, labels):
self.data = data
self.labels = labels

def __len__(self):
return len(self.data)

def __getitem__(self, idx):
return self.data[idx], self.labels[idx]
```

You can then create an instance of `CustomDataset` and use it with a DataLoader for batching.
Ques:- How do you create and manipulate tensors in PyTorch
Right Answer:
To create a tensor in PyTorch, use `torch.tensor()`, `torch.zeros()`, `torch.ones()`, or `torch.rand()`. For example:

```python
import torch

# Create a tensor from a list
tensor_a = torch.tensor([[1, 2], [3, 4]])

# Create a tensor filled with zeros
tensor_b = torch.zeros((2, 2))

# Create a tensor filled with ones
tensor_c = torch.ones((2, 2))

# Create a tensor with random values
tensor_d = torch.rand((2, 2))
```

To manipulate tensors, you can use operations like:

- Addition: `tensor_a + tensor_b`
- Multiplication: `tensor_a * tensor_b`
- Reshaping: `tensor_a.view(4)` or `tensor_a.reshape(4, 1)`
- Slicing: `tensor_a[0]` or `tensor_a[:, 1]`

You can also
Ques:- How do you visualize training progress and metrics in PyTorch
Right Answer:
You can visualize training progress and metrics in PyTorch using libraries like Matplotlib or TensorBoard. For Matplotlib, you can plot loss and accuracy graphs during training by storing metrics in lists and then plotting them after training. For TensorBoard, you can use `torch.utils.tensorboard` to log metrics and visualize them in the TensorBoard interface by calling `SummaryWriter` to write scalars, histograms, and images.
AmbitionBox Logo

What makes Takluu valuable for interview preparation?

1 Lakh+
Companies
6 Lakh+
Interview Questions
50K+
Job Profiles
20K+
Users