main

2024/05/06

How to Supercharge Your Python Classes with Class Methods

 How to Supercharge Your Python Classes with Class Methods | by Siavash Yasini | May, 2024 | Towards Data Science


As we just mentioned, a class method is a method that is bound to the class itself and not the instance of the class. This means it can change the state of the class such that it applies across all current or future instances of the class. A famous and practical example is when you want to create a singleton class. 

Singleton is a design pattern that allows you to constrain a class to only have one instance. Here’s an implementation:



And that’s the whole idea behind classmethods. They allow us to define methods in a class that are bound to the class itself, not its instances, therefore they allow us to modify the class behavior and make it more flexible.




















2023/10/11

pandas tricks

 a list of aggregation function for groupby:

min, max, mean, median, sum, count, std, var, size, describe, nuniaue, idxmax, idxmin.


df.groupby([‘airline’, ‘weekday’])[‘cancelled’,’diverted’].agg([‘sum’,’mean’]).head()


df.groupby([‘airline’, ‘weekday’])[‘cancelled’,’diverted’].agg({“dist”:[‘sum’,’mean’]).head()

pandas tricks

 df.style. highlight_max(axis=‘colums’)

2023/10/08

pandas tricks 3

 df.sort_values(["a","b","C", ascending=[True, False, True)

df.nlargest(10, 'a').nsmallest(5,"b)

pandas tricks 2

 df.select_dtypes(include=['int'])

df.select_dtypes(include=['number'])

df.selected_dytpes(include=['np.number'])

df.get_dtype_counts()

pandas tricks (1)

search column using filter: 

df.filter(like="good")

df.filter(regex="\d")



2023/04/02

MLOps-Tips and Tricks-75 Code Snippets MLOps and Data Engineering

 

MLOps-Tips and Tricks-75 Code Snippets



https://towardsdatascience.com/mlops-tips-and-tricks-75-code-snippets-b8f04036d0a0

2023/01/06

Comparison among best Text to Image AI generation with examples

Comparison among bestText to Image AI generation 

 Here are some results for "every success starts from small steps"


1) Dalle E 2, https://openai.com/dall-e-2/



2) pixray, https://replicate.com/pixray/text2image

This website has the engineering feeling. It outputs training result while generating images. 

3:  DeepAI, https://deepai.org/machine-learning-model/cyberpunk-generator




4: fotor: https://www.fotor.com/features/ai-image-generator/



5) Night Cafe, https://creator.nightcafe.studio/my-creations



6)  Craiyon,(Formerly DALL-E Mini), https://www.craiyon.com/



7) StarryAI, https://starryai.com/app/my-creations

Their UI is a little crappy. It did not generate an image at my first try.








2023/01/02

D3.js load error

 The error is:

Access to XMLHttpRequest at 'file:///D:/project/my_project/templates/data.csv' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.

1) Go to the developer tools (F12 in the browser), then select the three dots in the upper right corner, and go to Settings.

Then, look for Sources, and disable the options:

  • "Enable JavaScript source maps"
  • "Enable CSS source maps"
2) Disable AdBlock.

My chrome does not have settings as approach 1. 
The second approach works on my computer.


In terms of file folder and file path, check this youtube: https://www.youtube.com/watch?v=0XWyw4mbGEM

2022/12/24

D3.JS tutorial

after playing with google Looker for my project, I decided to warm up my D3.js skill in case there is a need.

With D3.js and flask, we can build a beautiful website easily.

 https://d3-graph-gallery.com/about.html

How to Supercharge Your Python Classes with Class Methods

  How to Supercharge Your Python Classes with Class Methods | by Siavash Yasini | May, 2024 | Towards Data Science As we just mentioned, a c...