Python Library Functions
Python Library Functions
DataFrame Basics:
Page | 2
Author: Muhammad Omar Akhlaq
date_range(): Generates date-time indices.
2. NUMPY
Array Creation:
Array Manipulation:
Array Operations:
Random Sampling:
Linear Algebra:
Page | 3
Author: Muhammad Omar Akhlaq
np.linalg.inv(): Computes the inverse of a matrix.
np.linalg.det(): Computes the determinant of a matrix.
np.linalg.solve(): Solves a system of linear equations.
3. SciKit-Learn
Data Preprocessing:
StandardScaler: Standardizes features by removing the mean and scaling to unit variance.
MinMaxScaler: Scales features to a given range (typically 0 to 1).
OneHotEncoder, LabelEncoder: Converts categorical variables into numerical representations.
train_test_split: Splits datasets into training and testing subsets for model evaluation.
Supervised Learning:
Regression:
LinearRegression, Ridge, Lasso, ElasticNet: Linear regression and regularized versions.
Classification:
LogisticRegression, SVC, RandomForestClassifier, KNeighborsClassifier: Classifiers for different
algorithms.
DecisionTreeClassifier, GradientBoostingClassifier: Decision tree-based models.
Unsupervised Learning:
Clustering:
KMeans, DBSCAN, AgglomerativeClustering: Algorithms for clustering data.
Dimensionality Reduction:
PCA, TruncatedSVD, FactorAnalysis: Methods for reducing dimensions while preserving important
information.
Ensemble Methods:
VotingClassifier, VotingRegressor: Combines multiple models' predictions for improved performance.
BaggingClassifier, RandomForestClassifier: Bootstrap aggregating methods for classification.
GradientBoostingClassifier, AdaBoostClassifier: Boosting methods for classification.
Page | 4
Author: Muhammad Omar Akhlaq
Text Analysis:
CountVectorizer, TfidfVectorizer: Convert text data into numerical feature vectors.
TfidfTransformer: Applies Term Frequency-Inverse Document Frequency transformation.
Model Serialization:
pickle: Built-in Python module for serializing and deserializing scikit-learn models.
4. TENSOR FLOW
Core Components:
Tensors: Fundamental data structures in TensorFlow, similar to multi-dimensional arrays.
Operations: Functions that manipulate tensors, perform computations, and define the computational
graph.
Graph: The computational graph defines the operations and dependencies between tensors.
Model Building:
Keras API: High-level API within TensorFlow for building and training neural networks easily.
tf.keras.layers: Module containing various layers like Dense, Conv2D, LSTM, etc., for building neural
network architectures.
tf.keras.Sequential: Allows the sequential stacking of layers to create a model.
Data Handling:
tf.data.Dataset: A powerful API for creating input pipelines to handle large datasets efficiently.
tf.data.experimental: Module containing experimental features for data pipeline handling.
Page | 5
Author: Muhammad Omar Akhlaq
Miscellaneous:
tf.math: Module containing mathematical operations on tensors.
tf.image: Module for image processing operations in TensorFlow.
tf.strings: Module for string manipulation operations.
5. KERAS
Model Building:
Sequential: A linear stack of layers for building sequential models.
Functional API (tf.keras.Model): Allows creating complex models with shared layers and multiple inputs
or outputs.
Dense, Conv2D, LSTM, Dropout, etc.: Various layer types for constructing neural network architectures.
Page | 6
Author: Muhammad Omar Akhlaq
6. PyTorch
Tensor Operations:
torch.Tensor: The core data structure, supports various tensor operations similar to NumPy arrays.
Math operations: Element-wise operations, matrix multiplications, and other mathematical functions.
Indexing and Slicing: Accessing and manipulating tensor elements.
Autograd and Dynamic Computation Graph:
torch.autograd: Automatic differentiation engine for computing gradients.
torch.autograd.Function: Base class for defining custom autograd operations.
backward(): Computes gradients of tensors with respect to a given computational graph.
Miscellaneous:
torch.cuda: Module for GPU-related functionalities and operations.
torchvision: Module containing datasets, model architectures, and image transformation utilities for
computer vision tasks.
torchtext: Module for text-related utilities and datasets.
Page | 7
Author: Muhammad Omar Akhlaq
7. MatPlotLib
Basic Plotting:
plt.plot(): Creates line plots.
plt.scatter(): Generates scatter plots.
plt.bar(), plt.barh(): Creates vertical and horizontal bar plots.
plt.hist(): Generates histograms.
plt.boxplot(): Creates boxplots to visualize data distributions.
Specialized Plots:
plt.pie(): Generates pie charts.
plt.stem(): Creates stem plots.
plt.violinplot(): Displays violin plots.
3D Plotting (with mpl_toolkits.mplot3d):
Page | 8
Author: Muhammad Omar Akhlaq
Axes3D: Provides 3D axes for plotting.
plot_surface(): Plots 3D surfaces.
scatter(): Creates 3D scatter plots.
Categorical Data:
sns.catplot(): Creates categorical plots (scatter, strip, box, violin, etc.) based on data types.
sns.swarmplot(): Visualizes categorical data along with the distribution of observations.
Distribution Visualization:
sns.histplot(), sns.kdeplot(): Displays histograms and kernel density estimation plots.
sns.rugplot(): Shows individual data points as dashes on a plot axis.
Relationship Plots:
sns.pairplot(): Creates a matrix of scatterplots for examining pairwise relationships in a dataset.
sns.heatmap(): Generates a heatmap to visualize matrix-like data.
Statistical Estimation:
Page | 9
Author: Muhammad Omar Akhlaq
sns.pointplot(): Visualizes point estimates and confidence intervals.
sns.barplot(): Displays the central tendency of a numeric variable.
9. Ploty
Basic Plotting:
go.Scatter(): Generates scatter plots.
go.Bar(): Creates bar charts.
go.Histogram(): Displays histograms.
go.Box(): Generates box plots.
go.Surface(): Generates 3D surface plots.
Specialized Visualizations:
go.Scatter3d(): Generates 3D scatter plots.
go.Choropleth(): Creates choropleth maps.
go.FigureWidget(): Enables interactive figures with widgets for live updating.
Dash Integration:
dash_core_components.Graph(): Integrates Plotly graphs into Dash web applications.
dash_html_components.Div(): Creates HTML div elements for organizing the layout in Dash apps.
Page | 10
Author: Muhammad Omar Akhlaq
Themes and Styling:
plotly.io.templates: Provides built-in templates for different plot styles.
update_traces(): Allows customization of individual traces within a plot.
10. NLTK
Corpus and Text Processing:
nltk.corpus: Module for accessing built-in corpora and lexical resources.
nltk.word_tokenize(): Tokenizes text into words or sentences.
nltk.sent_tokenize(): Tokenizes text into sentences.
Part-of-Speech Tagging:
nltk.pos_tag(): Assigns parts of speech (POS) tags to words in a text.
WordNet Interface:
nltk.WordNet: Interface to access WordNet, a lexical database for English.
nltk.synsets(): Retrieves synsets (sets of synonyms) from WordNet.
Text Classification:
nltk.classify: Module containing various classifiers for text classification.
nltk.NaiveBayesClassifier(), nltk.DecisionTreeClassifier(): Examples of classifiers.
Page | 11
Author: Muhammad Omar Akhlaq
Tokenization and Chunking:
nltk.chunk: Module for chunking and extracting phrases from sentences.
nltk.RegexpParser(): Creates chunk parsers using regular expressions.
Sentiment Analysis:
nltk.sentiment: Module providing sentiment analysis tools and lexicons.
Page | 12
Author: Muhammad Omar Akhlaq