Skip to content

Instantly share code, notes, and snippets.

View AayushSameerShah's full-sized avatar
🤨
Hmm...

Aayush Shah AayushSameerShah

🤨
Hmm...
View GitHub Profile
@AayushSameerShah
AayushSameerShah / sum_limits_upper_lower.md
Last active July 24, 2022 09:43
Set perfect limits in the sum in latex jupyer

Many times you want to write the formulae in which the limits need to be written up side and low side of the sigma. But the problem happens when it is not written as expected.

In such times, just add \displaystyle brfore the sum:

The problem:

$$\varrho(\tau) = \frac{ \sum_{t=1}^{T-\tau} (y_t - \mu) (y_{t + \tau} - \mu)} {(T - \tau)\varrho^2}$$

The solution

$$\varrho(\tau) = \frac{\displaystyle \sum_{t=1}^{T-\tau} (y_t - \mu) (y_{t + \tau} - \mu)} {(T - \tau)\varrho^2}$$

@AayushSameerShah
AayushSameerShah / convert_to_ROW_from_List.java
Created July 22, 2022 08:43
When you are struggling for making the dataframe from List<List<Object>> get here.
// suppose we have the list like this (not to run but just idea)
List<List<Integer>> data = [
[1, 2, 3],
[2, 3, 4],
[3, 4, 5]
];
// Now to convert each List<Integer> to Row so that can be used to make DF
List<Row> rows = new ArrayList<>();
for (List<Integer> that_line : data){
@AayushSameerShah
AayushSameerShah / RRMSE.py
Last active April 18, 2024 04:38
Relative Root Mean Squared Error (RRMSE)
def relative_root_mean_squared_error(true, pred):
n = len(true) # update
num = np.sum(np.square(true - pred)) / n # update
den = np.sum(np.square(pred))
squared_error = num/den
rrmse_loss = np.sqrt(squared_error)
return rrmse_loss
@AayushSameerShah
AayushSameerShah / MissForest_Imputer.py
Created July 4, 2022 10:54
This is the code snippet from the article pasted as a link in the column, where we can impute the NaN values throught Randomforest
#pip install misspy for installation
from missingpy import MissForest
imputer = MissForest()
X_imputed = imputer.fit_transform(X)
@AayushSameerShah
AayushSameerShah / add_column_from_anotherDF.java
Created June 8, 2022 09:55
This will help adding a column from a table to another when we "just" want to glue it without the same column. Here, we would need to use the "row_index" which will behave like a same column.
import static org.apache.spark.sql.functions.*;
result = result.withColumn("row_index", row_number().over(Window.orderBy(monotonically_increasing_id())));
DF = DF.withColumn("row_index", row_number().over(Window.orderBy(monotonically_increasing_id())));
result = result.join(DF.withColumn("realBMI",col("BMI")).select("row_index", "realBMI"), result.col("row_index").equalTo(DF.col("row_index")));
result = result.drop("row_index");
result.show();
@AayushSameerShah
AayushSameerShah / outlier_indices.py
Created April 12, 2022 10:46
Simply pass the column names of which you want to find the outliers from. YOU NEED TO HAVE THE DATAFRAME NAMED "DF".
def get_outlier_indices(columns_list):
indices = []
for column in columns_list:
feature = df[column]
Q1, Q3 = feature.quantile([0.25, 0.75]).values
IQR = Q3 - Q1
lower = Q1 - (1.5 * IQR)
upper = Q3 + (1.5 * IQR)
inds = list(df[(df[column] < lower) | (df[column] > upper)].index.values)
@AayushSameerShah
AayushSameerShah / set_patch_colors_when_unordered_bars.py
Created January 18, 2022 07:33
We are setting the custome cm colors in the matplotlib, most of the time the bars are sorted. But sometimes when the xticks are in the format of Date. Then, the bars are not sorted by their values. So, giving the custome cm will break. Here I am presenting the code which will help to give the custom colors when the bars are ordered by dates.
# Need to make axes
ax = plt.axes()
# Bar plot with sorted index (where the bars will be like |li|liii| ← unsorted
df.value_counts().plot.bar(ax=ax)
# Store individual heights
heights = []
for patch in ax.patches:
heights.append(patch.get_height())
heights = np.array(heights)
@AayushSameerShah
AayushSameerShah / triggers_sql.md
Last active December 11, 2021 07:58
The triggers here... pretty simple stuff

Here, I will talk about the triggers. As I have learnt triggers way back when I was doing my graduation, it seem like a boring or more complex stuff... but now as I can understand it, it is pretty pretty simple and easy stuff to implement and to understand.

What it is?

It is a way to automatically trigger a query (run a query) when certain event has happened. Like, if I am adding a new user, then automatically new table should be created, or let's

@AayushSameerShah
AayushSameerShah / get_row_in_groupby_sql.md
Last active March 14, 2022 16:47
This is the most complex query that I was struggling with... here is the solution

This is the data...

Title Author Pages
A man from sky Aayush 334
I know, what miracle is. Aayush 3134
album001 Sameer 134
How to feel happiness? Sameer 534
The secrets of woderland Sameer 834
An Adventurous Guy Baa 1234
@AayushSameerShah
AayushSameerShah / MySQL_small_snippets.md
Last active December 10, 2021 07:50
This gist covers various small chunks of MySQL commands which might be useful later... you know somewhere!

This time, I am gonna write the small, new things which I learnt before but by the time forgot them. Following the course on MySQL I will be noting down the stuff. As you might have noticed it is in the gist format, so the notes will not be much comprehensive, but they will be in such a form that you can refer back again. Like a cheat sheet!

See which database you are in?

SELECT database();

See columns of a table with query!

SHOW COLUMNS FROM table_name;