I found this to be quite useful, and it might be beneficial for you as well. There's a YouTube video course available, along with a GitHub page focusing on R and Python.
PDF can be found here: @reza_jafari_ai
PDF can be found here: @reza_jafari_ai
Vectorizing in JAX
# 135 µs ± 171 ns per loop
# 543 µs ± 1.38 µs per loop
Adding JIT
Notebook
ویرگول
def dot(v1, v2):1️⃣ Naively vectorizing
return jax.numpy.dot(v1, v2)
dot_naive =[dot(v1, v2) for v1, v2 in zip(v1s, v2s)]2️⃣ Manual vectorizing
def dot_vectorized(v1s, v2s):3️⃣ Automatic vectorizing
return jnp.einsum("ij,ij->i", v1s, v2s)
dot_vmapped = jax.vmap(dot)⏰ Timing
%timeit [dot(v1, v2) for v1, v2 in zip(v1s, v2s)]# 5.15 ms ± 54.3 µs per loop
%timeit dot_vectorized(v1s, v2s).block_until_ready()
%timeit dot_vmapped(v1s, v2s).block_until_ready()
# 135 µs ± 171 ns per loop
# 543 µs ± 1.38 µs per loop
Adding JIT
dot_vectorized_jitted = jax.jit(dot_vectorized)Timing
dot_vmapped_jitted = jax.jit(dot_vmapped)
bash
6.5 µs ± 12.9 ns per loop
6.39 µs ± 13.4 ns per loop
Notebook
ویرگول
Here are some of the most important and frequently used commands in scikit-learn (sklearn):
1. Model Selection:
-
-
-
-
2. Preprocessing:
-
-
-
3. Model Building:
-
-
-
-
-
-
-
4. Model Evaluation:
-
-
-
-
5. Pipeline and Feature Union:
-
-
6. Dimensionality Reduction:
-
-
7. Clustering:
-
-
These are just a few of the many functionalities provided by scikit-learn for machine learning tasks.
1. Model Selection:
-
train_test_split()
: Split arrays or matrices into random train and test subsets.-
cross_val_score()
: Evaluate a score by cross-validation.-
GridSearchCV()
: Exhaustive search over specified parameter values for an estimator.-
StratifiedKFold()
: Provides train/test indices to split data into train/test sets while maintaining class distribution.2. Preprocessing:
-
StandardScaler()
: Standardize features by removing the mean and scaling to unit variance.-
MinMaxScaler()
: Transform features by scaling each feature to a given range.-
OneHotEncoder()
: Encode categorical integer features as one-hot numeric arrays.3. Model Building:
-
LinearRegression()
: Ordinary least squares Linear Regression.-
LogisticRegression()
: Logistic Regression (for classification tasks).-
RandomForestClassifier()
: Random Forest Classifier.-
RandomForestRegressor()
: Random Forest Regressor.-
GradientBoostingClassifier()
: Gradient Boosting Classifier.-
GradientBoostingRegressor()
: Gradient Boosting Regressor.-
DecisionTreeClassifier()
: Decision Tree Classifier.4. Model Evaluation:
-
accuracy_score()
: Accuracy classification score.-
precision_score()
, recall_score()
, f1_score()
: Compute precision, recall, F-measure, and support for classification.-
mean_squared_error()
: Mean squared error regression loss.-
r2_score()
: R^2 (coefficient of determination) regression score function.5. Pipeline and Feature Union:
-
Pipeline()
: Chain multiple estimators into one.-
FeatureUnion()
: Combine several transformer objects into a new transformer.6. Dimensionality Reduction:
-
PCA()
: Principal Component Analysis.-
TruncatedSVD()
: Dimensionality reduction using truncated singular value decomposition.7. Clustering:
-
KMeans()
: K-Means clustering.-
AgglomerativeClustering()
: Agglomerative hierarchical clustering.These are just a few of the many functionalities provided by scikit-learn for machine learning tasks.
👍1
Seaborn is a popular Python visualization library built on top of Matplotlib. Here are some of the most frequently used functions in Seaborn:
1. Data Visualization:
-
-
-
-
-
-
-
-
-
-
-
2. Styling and Aesthetics:
-
-
-
3. Categorical Data Visualization:
-
-
4. Matrix Plots:
-
-
5. Time Series Visualization:
-
6. Faceting:
-
7. Regression Plots:
-
-
8. Distribution Plots:
-
-
1. Data Visualization:
-
sns.scatterplot()
: Scatter plot.-
sns.lineplot()
: Line plot.-
sns.barplot()
: Bar plot.-
sns.countplot()
: Count plot.-
sns.boxplot()
: Box plot.-
sns.violinplot()
: Violin plot.-
sns.heatmap()
: Heatmap.-
sns.pairplot()
: Pairwise plot.-
sns.jointplot()
: Joint plot.-
sns.distplot()
: Distribution plot.-
sns.regplot()
: Regression plot.2. Styling and Aesthetics:
-
sns.set_style()
: Set aesthetic style of plots.-
sns.set_context()
: Set the context for plot elements.-
sns.set_palette()
: Set the color palette for the plot.3. Categorical Data Visualization:
-
sns.catplot()
: Figure-level interface for drawing categorical plots.-
sns.factorplot()
: Draw categorical plots onto a FacetGrid.4. Matrix Plots:
-
sns.clustermap()
: Plot a matrix dataset as a hierarchically-clustered heatmap.-
sns.heatmap()
: Plot rectangular data as a color-encoded matrix.5. Time Series Visualization:
-
sns.tsplot()
: Time series plot.6. Faceting:
-
sns.FacetGrid()
: Multi-plot grid for plotting conditional relationships.7. Regression Plots:
-
sns.lmplot()
: Plot data and regression model fits across a FacetGrid.-
sns.regplot()
: Plot data and a linear regression model fit.8. Distribution Plots:
-
sns.distplot()
: Flexibly plot a univariate distribution of observations.-
sns.kdeplot()
: Fit and plot a univariate or bivariate kernel density estimate.*️⃣ Data Science Dojo has added more than 43 data sets to this repository.
1️⃣ The repository carries a diverse range of themes, difficulty levels, sizes and attributes.
2️⃣ They offer hands-on practice to boost their skills in exploratory data analysis, data visualization, data wrangling and machine learning.
3️⃣ The data sets below have been sorted with increasing level of difficulty for convenience (Beginner, Intermediate, Advanced).
https://code.datasciencedojo.com/datasciencedojo/datasets
1️⃣ The repository carries a diverse range of themes, difficulty levels, sizes and attributes.
2️⃣ They offer hands-on practice to boost their skills in exploratory data analysis, data visualization, data wrangling and machine learning.
3️⃣ The data sets below have been sorted with increasing level of difficulty for convenience (Beginner, Intermediate, Advanced).
https://code.datasciencedojo.com/datasciencedojo/datasets
Code
Data Science Dojo / datasets
Data Sets to Uplift your Skills
Python examples for beginners.📌📌.pdf
418.2 KB
Python 100 programs.
Partial functions allow us to fix a certain number of arguments of a function and generate a new function
from functools import partial
def add(a, b, c):
return 100 * a + 10 * b + c
# A partial function with b = 1 and c = 2
add_part = partial(add, c = 2, b = 1)
# Calling partial function, input is a
print(add_part(3))
👍2
Post-doctoral in Marseille.
Project Title: Higher-order interactions in human brain networks supporting causal learning
Project Title: Higher-order interactions in human brain networks supporting causal learning
I have a package let's call it my_package in python. how to implement a function to call it like my_package.tests() to run all tests?
## Create a
1. In your
2. Inside the
3. Create a new Python file, e.g.,
## Define the
1. In the
2. Define a function called
Here's an example using the
test_module1.py is something like this:
In this example, the
## Import the
1. In your
Now, you can call the
This will run all the tests in your
## Create a
tests
Module1. In your
my_package
directory, create a new directory called tests
.2. Inside the
tests
directory, create an empty __init__.py
file to make it a Python package.3. Create a new Python file, e.g.,
test_suite.py
, where you will define your test suite.## Define the
tests()
Function1. In the
test_suite.py
file, import the necessary testing framework (e.g., unittest
or `pytest`).2. Define a function called
tests()
that will run all the tests in your package.Here's an example using the
unittest
framework:
import unittest
from . import test_module1, test_module2
def tests():
suite = unittest.TestSuite()
suite.addTests(unittest.TestLoader().loadTestsFromModule(test_module1))
suite.addTests(unittest.TestLoader().loadTestsFromModule(test_module2))
runner = unittest.TextTestRunner(verbosity=2)
runner.run(suite)
test_module1.py is something like this:
import unittest
import numpy as np
class test_module_add(unittest.TestCase):
def test_add(self):
self.assertEqual(np.add(1, 2), 3)
In this example, the
tests()
function creates a TestSuite
object, adds tests from the test_module1
and test_module2
modules, and then runs the test suite using a TextTestRunner
.## Import the
tests()
Function1. In your
my_package/__init__.py
file, import the tests()
function from the test_suite.py
file:
from .tests.test_suite import tests
Now, you can call the
tests()
function from your package like this:
import my_package
my_package.tests()
This will run all the tests in your
my_package
package.Pre-commit:
The pre-commit package is a tool used in software development to manage and maintain code quality. It allows developers to set up and run a series of checks on their code before committing it to version control systems like Git. These checks can include formatting, syntax, style, and even running tests to ensure that the code meets predefined standards and doesn't introduce any errors or bugs. By catching issues early in the development process, pre-commit helps to ensure that the codebase remains clean, consistent, and maintainable.
how to install and set up:
https://pre-commit.com/
you need to put a
then just run to check and correct over all files:
The pre-commit package is a tool used in software development to manage and maintain code quality. It allows developers to set up and run a series of checks on their code before committing it to version control systems like Git. These checks can include formatting, syntax, style, and even running tests to ensure that the code meets predefined standards and doesn't introduce any errors or bugs. By catching issues early in the development process, pre-commit helps to ensure that the codebase remains clean, consistent, and maintainable.
how to install and set up:
https://pre-commit.com/
you need to put a
.pre-commit-config.yaml
at the root of your project.then just run to check and correct over all files:
bash
pre-commit install
pre-commit run --all-files
Scientific Programming
Pre-commit: The pre-commit package is a tool used in software development to manage and maintain code quality. It allows developers to set up and run a series of checks on their code before committing it to version control systems like Git. These checks can…
An example of configuration file:
yaml
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.3
hooks:
- id: ruff
- id: ruff-format
args: [--diff]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix=lf]
- id: trailing-whitespace
I had trouble installing R and 'tidyverse' on Ubuntu because the standard repositories offer older versions of R, which caused some packages not to install properly.
This resolved the issue:
Link
This resolved the issue:
Link
Medium
Installing R and the Tidyverse on Ubuntu 20.04
Installing R should be a relatively quick and painless process with Ubuntu. While the standard repositories often offer older versions of…