Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 548 of 2109
Python - Implementation of Polynomial Regression
Polynomial Regression is a form of linear regression in which the relationship between the independent variable x and dependent variable y is modeled as an nth degree polynomial. Polynomial regression fits a nonlinear relationship between the value of x and the corresponding conditional mean of y, denoted E(y |x). Unlike simple linear regression that creates a straight line, polynomial regression can capture curved relationships in data by using polynomial terms like x², x³, etc. Creating Sample Data First, let's create some sample data to demonstrate polynomial regression ? import numpy as np import matplotlib.pyplot as ...
Read MorePython - Image Classification using keras
Image classification is a fundamental computer vision task that categorizes images into predefined classes. Keras provides powerful tools to build convolutional neural networks (CNNs) for this purpose. There are two main approaches ? Training a small network from scratch Fine tuning the top layers of the model using VGG16 Setting Up the Environment First, we import the necessary libraries and define basic parameters ? # Importing all necessary libraries from keras.preprocessing.image import ImageDataGenerator from keras.models import Sequential from keras.layers import Conv2D, MaxPooling2D from keras.layers import Activation, Dropout, Flatten, Dense from keras import backend ...
Read MorePython - How and where to apply Feature Scaling?
Feature scaling is a crucial data preprocessing step applied to independent variables or features. It normalizes data within a particular range, ensuring all features contribute equally to machine learning algorithms. Why Feature Scaling is Important Most datasets contain features with vastly different magnitudes, units, and ranges. For example, age (20-80) versus income (20, 000-100, 000). Machine learning algorithms that use Euclidean distance treat these differences literally ? import numpy as np from sklearn.preprocessing import StandardScaler # Example: Age vs Income (unscaled) data = np.array([[25, 50000], [30, 75000], [35, 100000]]) print("Original data:") print("Age | Income") for ...
Read MoreMaximum factors formed by two numbers in Python
We are given an array of integers and need to find the maximum number of factors formed by multiplying any two distinct numbers from the array. This involves calculating all possible products of pairs and then counting factors for each product. Problem Understanding Example 1 For array [3, 2, 10] ? Input: [3, 2, 10] Products: 3×2=6, 3×10=30, 2×10=20 Factors: 6→{1, 2, 3, 6} (4 factors), 30→{1, 2, 3, 5, 6, 10, 15, 30} (8 factors), 20→{1, 2, 4, 5, 10, 20} (6 factors) Output: Maximum factors = 8 Example 2 For ...
Read MoreFind bitonic point in given bitonic sequence in Python
A bitonic sequence is a sequence of numbers that first increases strictly, reaches a peak (the bitonic point), then decreases strictly. We need to find this peak element efficiently using binary search. The bitonic point is the maximum element where the left neighbor is smaller and the right neighbor is also smaller. Algorithm We use binary search to find the bitonic point in O(log n) time ? Compare the middle element with its neighbors If array[mid-1] < array[mid] > array[mid+1], we found the bitonic point If array[mid] < array[mid+1], the peak is in the right ...
Read MoreFind array with k number of merge sort calls in Python
Sometimes we need to construct an array that requires exactly k recursive calls when sorted using merge sort. This problem involves understanding how merge sort's recursive structure works and manipulating an array to achieve the desired call count. Given two numbers a and b, we need to find an array containing values in range [1, a] that requires exactly b number of recursive merge sort calls. Understanding the Problem Merge sort makes recursive calls by dividing the array into halves. The total number of calls follows a pattern based on the array structure and element positions. ...
Read MoreFind an element which divides the array in two subarrays with equal product in Python
Given an array of integers, we need to find an element that divides the array into two subarrays with equal product. If no such element exists, return -1. For example, in the array [2, 5, 3, 2, 5], the element 3 at index 2 divides it into subarrays [2, 5] and [2, 5], both having product 10. Algorithm We use prefix and suffix product arrays to efficiently calculate products of left and right subarrays ? Create a prefix product array storing cumulative products from left Create a suffix product array storing cumulative products from right ...
Read MoreFind an element in an array such that elements form a strictly decreasing and increasing sequence in Python
In Python, we can find an element in an array where elements form a strictly decreasing sequence followed by a strictly increasing sequence. The element we seek is the transition point between these two sequences. Problem Requirements The solution must satisfy these conditions: Both decreasing and increasing sequences must have minimum length 2 The last value of the decreasing sequence is the first value of the increasing sequence No duplicate elements are allowed (strictly decreasing/increasing) For example, in array [5, 4, 3, 4], the sequence [5, 4, 3] is strictly decreasing and [3, 4] ...
Read MoreFind all strings formed from characters mapped to digits of a number in Python
When working with digit-to-character mappings, we often need to generate all possible string combinations from a given number. This is similar to how old mobile phone keypads worked, where each digit mapped to multiple letters. Problem Understanding Given a mapping where each digit (1-9) corresponds to a list of characters, we need to find all possible strings that can be formed from a number. The key constraint is that we must use the same character for every occurrence of a digit in the number. 1 → ['A', 'B', 'C'] 2 → ['D', 'E', 'F'] ...
Read MoreFind all rectangles filled with 0 in Python
Finding all rectangles filled with 0s in a binary 2D matrix is a common problem in computer vision and image processing. We need to identify the starting and ending coordinates of each rectangular region containing only zeros. The problem requires us to find rectangles that are separated (don't touch each other) but can touch array boundaries. Each rectangle is represented by four coordinates: [start_row, start_col, end_row, end_col]. Input Example Consider this binary matrix where 1 represents filled cells and 0 represents empty cells ? 1011101 1101111 1011001 1011001 1011011 1010000 1110001 1011101 Algorithm ...
Read More