GANUMPDT
GANUMPDT
Explanation:
import random
def fitness(chromosome):
x = int(''.join(map(str, chromosome)), 2)
return x**2
# Parameters
pop_size = 6
chrom_length = 5 # x: 0-31
generations = 5
Explanation:
A library for numerical computing with support for arrays, matrices, and mathematical
functions.
Code Example:
import numpy as np
# Create arrays
a = np.array([1, 2, 3, 4])
b = np.arange(12).reshape(3, 4)
print("Array a:\n", a)
print("Matrix b:\n", b)
# Operations
dot_product = np.dot(a, b.T) # Matrix multiplication
mean = np.mean(b)
sum_col = np.sum(b, axis=0)
Explanation:
Code Example:
import pandas as pd
# Create DataFrame
data = {'Name': ['Alice', 'Bob', 'Charlie'],
'Age': [25, 30, 35],
'Salary': [50000, 70000, 90000]}
df = pd.DataFrame(data)
# Data operations
filtered = df[df['Age'] > 25]
df['Bonus'] = df['Salary'] * 0.1
grouped = df.groupby('Age').mean()
4. Decision Tree
Explanation:
# Split data
X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size=0.2, random_state=42)
# Train model
clf = DecisionTreeClassifier(max_depth=3)
clf.fit(X_train, y_train)
# Evaluate
y_pred = clf.predict(X_test)
print(f"Accuracy: {accuracy_score(y_test, y_pred ):.2f}")
Genetic
Feature Algorithm NumPy Pandas Decision Tree
(GA)
Solve
Numerical
optimization
computation Data Classification/Re
Primary problems
s with manipulation and gression via
Purpose using
arrays/matri analysis hierarchical splits
evolutionary
ces
principles
- Population-
-
based - N-
DataFrame/Series
- Stochastic dimensional - Recursive
structures
operators arrays partitioning
- Data
Key Features (crossover, - Vectorized - Feature
cleaning/aggregati
mutation) operations importance
on
- Fitness- - Linear - Interpretability
- Time-series
driven algebra tools
support
selection
- NP-hard - Matrix
- CSV/Excel data - Customer
problems math
handling segmentation
Typical Use (e.g., TSP) - Signal
- Data wrangling - Medical
Cases - Parameter processing
- Exploratory diagnosis
tuning -
analysis - Fraud detection
- Robotics Simulations
- Handles
non- - Fast array - Intuitive data - Easy to visualize
differentiable/ operations handling - No need for
non-convex - Memory - Merge/join feature scaling
Strengths
functions efficiency operations - Handles non-
- Global - Integration - Missing data linear
search with C/C++ tools relationships
capability
-
Computation - Limited to
ally intensive numerical
- Memory-heavy - Prone to
- No data
for large datasets overfitting
guarantee of - Steeper
Weaknesses - Slower than - Unstable (small
optimal learning
NumPy for pure data changes →
solution curve for
math ops different tree)
- advanced
Hyperparame features
ter-sensitive
scikit-learn,
Libraries/Tool DEAP, PyGAD,
numpy pandas XGBoost,
s pymoo
LightGBM
Key Takeaways:
1. Genetic Algorithm:
a. Best for optimization where traditional methods fail (e.g.,
complex, noisy search spaces).
b. Example: Optimizing delivery routes for minimal fuel
consumption.
2. NumPy:
a. Foundation for numerical computing in Python.
b. Example: Solving linear equations Ax = b using
np.linalg.solve().
3. Pandas:
a. Ideal for tabular data (e.g., CSV, Excel).
b. Example: Aggregating sales data by region/month.
4. Decision Tree:
a. Simple interpretable models for classification/regression.
b. Example: Predicting loan defaults based on income/credit
score.