Programming Articles

Page 464 of 2547

How can transfer learning be implemented in Python using Keras?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 395 Views

Transfer learning is a powerful technique where a pre-trained model is adapted for a new but related task. In Keras, this involves loading a pre-trained model, freezing some layers, and fine-tuning others on your specific dataset. Keras is a high-level deep learning API written in Python that runs on top of TensorFlow. It provides essential abstractions and building blocks for developing machine learning solutions quickly and efficiently. What is Transfer Learning? Transfer learning involves taking a model trained on one task and adapting it for a related task. Instead of training from scratch, you leverage pre-learned features, ...

Read More

How can Keras be used to extract features from only one layer of the model using Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 2K+ Views

Keras is a high-level deep learning API that runs on top of TensorFlow. Sometimes you need to extract features from a specific intermediate layer of a trained model, rather than using the final output. This is useful for transfer learning, feature visualization, or building feature extractors. Installation TensorFlow (which includes Keras) can be installed using ? pip install tensorflow Importing Required Libraries import tensorflow as tf from tensorflow import keras from tensorflow.keras import layers Creating a Sequential Model First, let's create a CNN model with multiple layers. We'll name ...

Read More

How can Keras be used for feature extraction using a sequential model using Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 2K+ Views

Keras is a high-level deep learning API built on top of TensorFlow that simplifies building and training neural networks. One powerful application is feature extraction, where we extract intermediate layer outputs from a trained model to use as features for other tasks. What is Feature Extraction? Feature extraction involves using a pre-trained or partially trained model to extract meaningful representations from data. Instead of using the final output, we capture intermediate layer outputs that contain learned features. Installation Install TensorFlow which includes Keras − pip install tensorflow Creating a Sequential Model for ...

Read More

What is a common debugging workflow while creating a model using Keras in Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 183 Views

When developing machine learning models with Keras, a structured debugging workflow helps identify and resolve issues efficiently. Keras, part of TensorFlow, provides excellent tools for monitoring model construction and troubleshooting common problems during development. The TensorFlow package can be installed using the following command − pip install tensorflow Keras can be imported and accessed through TensorFlow − import tensorflow as tf from tensorflow import keras from tensorflow.keras import layers Common Debugging Workflow The most effective debugging approach is to build models incrementally, checking each step. Here's a practical workflow − ...

Read More

How can Keras be used to create a model where the input shape of model is specified in advance?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 233 Views

Keras is a high-level deep learning API that runs on top of TensorFlow. When building neural networks, layers need to know the input shape to initialize their weights properly. Keras provides flexible ways to specify input shapes in advance. Understanding Layer Weight Initialization Keras layers create weights only when they know the input shape. This happens either when data is first passed through the layer or when the input shape is explicitly specified ? import tensorflow as tf from tensorflow import keras from tensorflow.keras import layers print("Creating a dense layer without specifying input shape") layer ...

Read More

Check whether two strings are anagram of each other in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 475 Views

Two strings are anagrams if they contain the same characters with the same frequency, just rearranged. For example, "bite" and "biet" are anagrams because both contain one 'b', one 'i', one 't', and one 'e'. We'll explore three different methods to check if two strings are anagrams in Python. Method 1: Using Sorting The simplest approach is to sort both strings and compare them ? def check_anagram_sorting(s, t): if len(s) != len(t): return False ...

Read More

Check whether triangle is valid or not if sides are given in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 1K+ Views

To check if three sides can form a valid triangle, we use the triangle inequality theorem. This states that the sum of any two sides must be greater than the third side for all three combinations. For three sides a, b, and c, a triangle is valid if: a + b > c a + c > b b + c > a However, we can simplify this by sorting the sides first. If the sum of the two smaller sides is greater than the largest side, then all conditions are automatically satisfied. Algorithm ...

Read More

Check whether the two numbers differ at one-bit position only in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 548 Views

Suppose we have two numbers x and y. We have to check whether these two numbers differ at one-bit position or not in their binary representation. So, if the input is like x = 25 and y = 17, then the output will be True because x = 11001 in binary and y = 10001. Only one-bit position is different. Algorithm To solve this, we will follow these steps ? Calculate z = x XOR y Count the number of set bits in z ...

Read More

Check whether the sum of prime elements of the array is prime or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 236 Views

When working with arrays containing numbers, we often need to identify prime numbers and perform operations on them. This problem requires us to find all prime elements in an array, sum them up, and check if that sum is also prime. So, if the input is like nums = [1, 2, 4, 5, 3, 3], then the output will be True as sum of all primes are (2+5+3+3) = 13 and 13 is also prime. Understanding Prime Numbers A prime number is a natural number greater than 1 that has no positive divisors other than 1 and ...

Read More

Check whether the sum of absolute difference of adjacent digits is Prime or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 277 Views

Sometimes we need to check if the sum of absolute differences between adjacent digits in a number results in a prime number. This involves calculating differences between consecutive digits and testing if their sum is prime. Problem Understanding Given a number n, we need to ? Calculate the absolute difference between each pair of adjacent digits Sum all these differences Check if the sum is a prime number For example, if n = 574, then |5−7| + |7−4| = 2 + 3 = 5, which is prime, so the result is True. Algorithm ...

Read More
Showing 4631–4640 of 25,466 articles
« Prev 1 462 463 464 465 466 2547 Next »
Advertisements