Skip to content

Instantly share code, notes, and snippets.

@shaan-shah
shaan-shah / soundpreprocessing.ipynb
Created May 21, 2020 17:27
Notebook for converting sound to graphs
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@shaan-shah
shaan-shah / Sound -Dataloader.ipynb
Last active May 22, 2020 08:01
The gist for making a dataloader for sound dataset for training.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@shaan-shah
shaan-shah / training1.ipynb
Created May 22, 2020 08:32
The gist for training a neural network to sound image data.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@shaan-shah
shaan-shah / training2.ipynb
Created May 22, 2020 09:12
The gist for training a neural net on sound spectograms.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@shaan-shah
shaan-shah / sound-confusion-matrix.ipynb
Created May 22, 2020 09:21
The confusion matrix for the sound dataset.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@shaan-shah
shaan-shah / rf-explanation1.py
Last active August 18, 2020 08:54
This is a gist to demonstrate some code on medium.
def split_vals(a,n):
return a[:n].copy(), a[n:].copy()
def rmse(x,y): return math.sqrt(((x-y)**2).mean())
def print_score(m,X_train,y_train,X_valid,y_valid):
res = [rmse(m.predict(X_train), y_train), rmse(m.predict(X_valid), y_valid),
m.score(X_train, y_train), m.score(X_valid, y_valid)]
if hasattr(m, 'oob_score_'): res.append(m.oob_score_)
print(res)
@shaan-shah
shaan-shah / rf-explanation2.py
Last active August 18, 2020 09:26
This was made to demonstrate code on medium.
def data_trainer(Target_Variable,data_raw,n_valid,date_column=None):
df_raw=data_raw
reset_rf_samples()
''' This if statement is to reduce the date part'''
if date_column:
add_datepart(df_raw,date_column)
train_cats(df_raw)
df,y,nas=proc_df(df_raw,Target_Variable)
n_trn=len(df)-n_valid
@shaan-shah
shaan-shah / rf-explanation3.py
Last active August 18, 2020 14:04
This gist was made to demonstrate code on medium.
''' from here we are doing the feature engineering'''
print(min_leaf_a)
reset_rf_samples()
z=RandomForestRegressor(n_jobs=-1,min_samples_leaf= min_leaf_a,max_features= max_feature_a,oob_score=False,n_estimators=40)
z.fit(X_train,y_train)
fi=rf_feat_importance(z,df)
score=0
final_feature_importance_value=0
feature_importance_value_list=[0,0.001,0.002,0.0025,0.003,0.0035]
for feature_importance_value in feature_importance_value_list:
@shaan-shah
shaan-shah / rf-explanation4.py
Created August 18, 2020 13:57
This gist was made to demonstrate code on medium.
def auto_applyer(leaf_value,feature_value,feature_list,df_raw1,df_test,target_column,date_column=None):
reset_rf_samples()
if date_column:
if date_column in df_test:
add_datepart(df_test,date_column)
if date_column in df_raw1:
add_datepart(df_raw1,date_column)
'''First we will pre process both test and raw data'''
train_cats(df_raw1)
@shaan-shah
shaan-shah / rf-explanation5.py
Created August 18, 2020 14:04
This made to demonstrate code on medium.
def auto_predictor(Target_Variable,data_raw,n_valid,data_to_predict,date_column=None):
if date_column:
data_raw['{}'.format(date_column)]= pd.to_datetime(data_raw['{}'.format(date_column)])
data_to_predict['{}'.format(date_column)]= pd.to_datetime(data_to_predict['{}'.format(date_column)])
intermed=data_trainer(Target_Variable=Target_Variable,data_raw=data_raw,n_valid=n_valid,date_column=date_column)
return(auto_applyer(leaf_value=intermed[0],feature_value=intermed[1],feature_list=intermed[2],df_raw1=data_raw,df_test=data_to_predict,target_column=Target_Variable,date_column=date_column))
else:
intermed=data_trainer(Target_Variable=Target_Variable,data_raw=data_raw,n_valid=n_valid)
return(auto_applyer(leaf_value=intermed[0],feature_value=intermed[1],feature_list=intermed[2],df_raw1=data_raw,df_test=data_to_predict,target_column=Target_Variable))