id int64 0 7.95k | code_block stringlengths 1 52.9k | too_long stringclasses 2
values | marks int64 1 5 | graph_vertex_id float64 1 88 | graph_vertex_class stringclasses 12
values | graph_vertex_subclass stringclasses 70
values | kernel_id float64 25.8k 14.7M ⌀ | sqale_rating float64 1 4 | maintainability_rating stringclasses 4
values | code_smells int64 0 36 | complexity float64 0 15 ⌀ | cognitive_complexity int64 0 33 | bugs int64 0 7 | sqale_index int64 0 125 | ncloc float64 0 101 ⌀ | mlscent_analysis_status stringclasses 3
values | mlscent_smell_count int64 0 31 | mlscent_unique_smell_count int64 0 12 | mlscent_findings_json stringlengths 2 7.76k | mlscent_ml_rating stringclasses 5
values | mlscent_ml_rating_basis stringclasses 52
values | mlscent_ml_findings_json stringclasses 50
values | mlscent_ignored_findings_json stringclasses 199
values | context_line_count int64 0 33 | combined_rating stringclasses 5
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
205 | cat_cols = train.dtypes[train.dtypes=='object'].keys()
cat_cols | No | 5 | 77 | Other | define_variables | null | 1 | A | 0 | 0 | 0 | 1 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
206 | for cat_col in cat_cols:
train[cat_col].fillna('no_value', inplace = True) | No | 5 | 17 | Data_Transform | correct_missing_values | null | 1 | A | 0 | 1 | 1 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
207 | train['place'] = train['Province_State']+'_'+train['Country_Region']
#vcheck = train[(train['Date']>='2020-03-12')] | No | 5 | 8 | Data_Transform | feature_engineering | null | 3 | C | 1 | 0 | 0 | 0 | 5 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
208 | for cat_col in ['place']:
#train[cat_col].fillna('no_value', inplace = True) #train[cat_col].value_counts().idxmax()
le = preprocessing.LabelEncoder()
le.fit(train[cat_col])
train[cat_col]=le.transform(train[cat_col]) | No | 5 | 20 | Data_Transform | categorify | null | 1 | A | 0 | 1 | 1 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
209 | train.keys() | No | 5 | 40 | Debug | show_table_attributes | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
210 | drop_cols = ['Id','ForecastId', 'ConfirmedCases','Date', 'Fatalities',
'day_dist', 'Province_State', 'Country_Region'] #,'day_dist','shift_22_ft','shift_23_ft','shift_24_ft','shift_25_ft','shift_26_ft'] | No | 5 | 77 | Other | define_variables | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
211 | #val = train[(train['Id']).isnull()==True]
#train = train[(train['Id']).isnull()==False]
val = train[(train['Date']>='2020-03-12')&(train['Id'].isnull()==False)]
#test = train[(train['Date']>='2020-03-12')&(train['Id'].isnull()==True)]
#train = train[(train['Date']<'2020-03-22')&(train['Id'].isnull()==False)] | No | 5 | 14 | Data_Transform | filter | null | 4 | D | 2 | 0 | 0 | 0 | 10 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
212 | val | No | 5 | 53 | Other | something_strange | null | 1 | A | 0 | 0 | 0 | 1 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
213 | y_ft = train["Fatalities"]
y_val_ft = val["Fatalities"]
y_cc = train["ConfirmedCases"]
y_val_cc = val["ConfirmedCases"]
#train.drop(drop_cols, axis=1, inplace=True)
#test.drop(drop_cols, axis=1, inplace=True)
#val.drop(drop_cols, axis=1, inplace=True) | No | 5 | 21 | Data_Transform | prepare_x_and_y | null | 1 | A | 1 | 0 | 0 | 0 | 5 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
214 | #
def rmsle (y_true, y_pred):
return np.sqrt(np.mean(np.power(np.log1p(y_pred) - np.log1p(y_true), 2)))' | No | 5 | 84 | Other | not_enough_vertices | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
215 | def mape (y_true, y_pred):
return np.mean(np.abs(y_pred -y_true)*100/(y_true+1)) | No | 5 | 84 | Other | not_enough_vertices | null | 1 | A | 0 | 1 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
216 | dates = dates[dates>'2020-03-31'] | No | 5 | 14 | Data_Transform | filter | 8,687,334 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}] | A | no applicable ML-specific findings | [] | ["Column Selection Checker"] | 3 | A |
217 | train[train['Date']==date] | No | 5 | 14 | Data_Transform | filter | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
218 | test[test['Country_Region']=='Italy'] | No | 5 | 14 | Data_Transform | filter | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
219 | test[(test['Country_Region']=='China')&(test['Province_State']=='Zhejiang')] | No | 5 | 14 | Data_Transform | filter | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
220 | y_pred.mean() | No | 5 | 40 | Debug | show_table_attributes | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
221 | print(len(test)) | No | 5 | 58 | Debug | show_shape | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
222 | train_sub = pd.read_csv("../input/covid19-global-forecasting-week-2/train.csv") | No | 5 | 45 | Data_Extraction | load_from_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
223 | test.head() | No | 5 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
224 | test.loc[test['ConfirmedCases_x'].isnull()==True] | No | 5 | 14 | Data_Transform | filter | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
225 | test.loc[test['ConfirmedCases_x'].isnull()==True, 'ConfirmedCases_x'] =test.loc[test['ConfirmedCases_x'].isnull()==True, 'ConfirmedCases_y'] | No | 5 | 14 | Data_Transform | filter | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
226 | test.loc[test['Fatalities_x'].isnull()==True, 'Fatalities_x'] = test.loc[test['Fatalities_x'].isnull()==True, 'Fatalities_y'] | No | 5 | 14 | Data_Transform | filter | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
227 | dates | No | 5 | 53 | Other | something_strange | null | 1 | A | 0 | 0 | 0 | 1 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
228 | last_amount = test.loc[(test['Country_Region']=='Italy')&(test['Date']=='2020-03-31'),'ConfirmedCases_x'] | No | 5 | 14 | Data_Transform | filter | 8,687,334 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}] | A | no applicable ML-specific findings | [] | ["Column Selection Checker"] | 3 | A |
229 | last_fat = test.loc[(test['Country_Region']=='Italy')&(test['Date']=='2020-03-31'),'Fatalities_x'] | No | 5 | 14 | Data_Transform | filter | 8,687,334 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}] | A | no applicable ML-specific findings | [] | ["Column Selection Checker"] | 3 | A |
230 | last_fat.values[0] | No | 5 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
231 | test.loc[(test['Country_Region']=='Italy')] #&(test['Date']==date),'ConfirmedCases_x' | No | 5 | 14 | Data_Transform | filter | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
232 | for date in dates:
k = k-1
i = i+1
test.loc[(test['Country_Region']=='Italy')&(test['Date']==date),
'ConfirmedCases_x']=last_amount.values[0] + i*(5000-(100*i))
test.loc[(test['Country_Region']=='Italy')&(test['Date']==date),
'Fatalities_x'] = last_fat.values[0]+i*(800-(10*i)) | No | 5 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | 1 | 1 | 0 | 0 | 7 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
233 | last_amount = test.loc[(test['Country_Region']=='China')&(test['Province_State']!='Hubei')&(test['Date']=='2020-03-31'),'ConfirmedCases_x']
last_fat = test.loc[(test['Country_Region']=='China')&(test['Province_State']!='Hubei')&(test['Date']=='2020-03-31'),'Fatalities_x'] | No | 5 | 77 | Other | define_variables | 8,687,334 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}] | A | no applicable ML-specific findings | [] | ["Column Selection Checker"] | 3 | A |
234 | i = 0
k = 30
for date in dates:
k = k-1
i = i+1
test.loc[(test['Country_Region']=='China')&(test['Province_State']!='Hubei')&(test['Date']==date),
'Fatalities_x']= last_fat.values
test.loc[(test['Country_Region']=='China')&(test['Province_State']!='Hubei')&(test['Date']==date),
... | No | 5 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | 1 | 1 | 0 | 0 | 9 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
235 | last_amount = test.loc[(test['Country_Region']=='China')&(test['Province_State']=='Hubei')&(test['Date']=='2020-03-31'),'ConfirmedCases_x']
last_fat = test.loc[(test['Country_Region']=='China')&(test['Province_State']=='Hubei')&(test['Date']=='2020-03-31'),'Fatalities_x'] | No | 5 | 14 | Data_Transform | filter | 8,687,334 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}] | A | no applicable ML-specific findings | [] | ["Column Selection Checker"] | 3 | A |
236 | k=30
i=0
for date in dates:
k = k-1
i = i+1
test.loc[(test['Country_Region']=='China')&(test['Province_State']=='Hubei')&(test['Date']==date),'ConfirmedCases_x']= last_amount.values[0]
test.loc[(test['Country_Region']=='China')&(test['Province_State']=='Hubei')&(test['Date']==date),'Fatalities_x']= last... | No | 5 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | 1 | 1 | 0 | 0 | 7 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
237 | sub | No | 5 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 1 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
238 | sub.loc[sub['ConfirmedCases']<0,'ConfirmedCases']=0 | No | 5 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
239 | sub.loc[sub['Fatalities']<0, 'Fatalities']=0 | No | 5 | 14 | Data_Transform | filter | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
240 | sub['Fatalities'].describe() | No | 5 | 40 | Debug | show_table_attributes | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
241 | sub['ConfirmedCases'].describe() | No | 5 | 40 | Debug | show_table_attributes | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
242 | sub.to_csv('submission.csv',index=False) | No | 5 | 25 | Data_Export | save_to_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
243 | # customize loss function which is aligned with kaggle evaluation
def root_mean_squared_log_error(y_true, y_pred):
return K.sqrt(K.mean(K.square(K.log(y_pred + 1) - K.log(y_true + 1)))) | No | 3 | 28 | Model_Train | compute_train_metric | null | 1 | A | 0 | 1 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
244 | #declaring only one model
def GRU_model(n_1, input_dim, output_dim):
model = Sequential()
model.add(GRU(n_1,input_shape=(1, input_dim), activation='relu'))
model.add(Dropout(0.1))
model.add(Dense(output_dim, activation='relu'))
model.compile(loss=root_mean_squared_log_error, optimizer='adam')
pr... | No | 5 | 4 | Model_Train | choose_model_class | 8,678,201 | 1 | A | 1 | 1 | 0 | 0 | 10 | 8 | ok | 1 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Missing docstring for function: GRU_model. Consider adding documentation for parameters and return values.", "fix": "Not specified", "benefits": "Not specified", "location": "Line 6"}] | A | no applicable ML-specific findings | [] | ["Missing function docstring"] | 4 | A |
245 | #TODO: debug sometimes it's getting inf. Suspect bad input
model_cc = GRU_model(4, X_train_cc.shape[-1], y_train_cc.shape[-1])
model_ft = GRU_model(4, X_train_ft.shape[-1], y_train_ft.shape[-1])
early_stop = EarlyStopping(monitor='loss', patience=5, verbose=0, mode='min') | No | 5 | 4 | Model_Train | choose_model_class | 8,678,201 | 1 | A | 1 | 0 | 0 | 0 | 0 | 3 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 4 | A |
246 | groups_dict =dfg.groups
for group, indexes in groups_dict.items():
print(group)
tempdf = df.loc[indexes[0]:indexes[-1]]
print(tempdf.shape)
if False:
tempdf["Growth"] = tempdf.ConfirmedCases/tempdf.ConfirmedCases.shift(1)
tempdf["FGrowth"] = tempdf.Fatalities/tempdf.Fatalities.shift(1)
... | No | 2 | 21 | Data_Transform | prepare_x_and_y | 8,667,455 | 1 | A | 1 | 2 | 3 | 0 | 2 | 9 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}] | A | no applicable ML-specific findings | [] | ["Column Selection Checker"] | 3 | A |
247 | b"dfa = df[df.Country_Region == 'Spain'][df.Province_State.isnull()][df.ConfirmedCases>10]\nprint(dftesta.shape)\nprint(dfa.shape)\n\nfrom matplotlib import pyplot\nfrom statsmodels.tsa.ar_model import AR\nfrom sklearn.metrics import mean_squared_error\n\nX = list(dfa.GrowthRate.values)\n\nX = [x for x in X if not np.i... | No | 4 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
248 | b"dfa = df[df.Country_Region == 'Italy'][df.Province_State.isnull()][df.ConfirmedCases>10]\nprint(dftesta.shape)\nprint(dfa.shape)\n\nfrom matplotlib import pyplot\nfrom statsmodels.tsa.ar_model import AR\nfrom sklearn.metrics import mean_squared_error\n\nX = list(dfa.GrowthRate.values)\n\nX = [x for x in X if not np.i... | No | 4 | 7 | Model_Train | train_model | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
249 | #dfsubmission.to_csv('submission.csv', index=False) | No | 4 | 7 | Model_Train | train_model | 8,667,455 | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
250 | import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
from sklearn.preprocessing import LabelEncoder
from skmultilearn.problem_transform import BinaryRelevance
from sklearn.naive_bayes import GaussianNB | No | 1 | 45 | Data_Extraction | load_from_csv | 8,689,318 | 1 | A | 0 | 0 | 0 | 0 | 0 | 7 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 4 | A |
251 | import pandas as pd | No | 5 | 22 | Environment | import_modules | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 0 | A |
252 | train = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-2/train.csv')
test = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-2/test.csv') | No | 5 | 45 | Data_Extraction | load_from_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
253 | test.info() | No | 5 | 40 | Debug | show_table_attributes | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
254 | train.sample(3) | No | 5 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
255 | train['Date'] = pd.to_datetime(train['Date'])
test['Date'] = pd.to_datetime(test['Date']) | No | 5 | 16 | Data_Transform | data_type_conversions | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
256 | train['Date'] = train['Date'].astype('int64')
test['Date'] = test['Date'].astype('int64') | No | 5 | 16 | Data_Transform | data_type_conversions | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
257 | from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
def FunLabelEncoder(df):
for c in df.columns:
if df.dtypes[c] == object:
le.fit(df[c].astype(str))
df[c] = le.transform(df[c].astype(str))
return df | No | 5 | 20 | Data_Transform | categorify | null | 1 | A | 1 | 3 | 3 | 0 | 10 | 8 | ok | 8 | 7 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Pipeline Checker", "fix": "Use Pipelines for all scikit-learn estimators.", "benefits": "Prevents data leakage and ensures correct model evaluation.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross V... | D | Cross Validation Checker=low, Data Leakage Checker=high, No random seed setting detected=low, Pipeline Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}, {"type": "No random seed setting detected", "severity": "low"}, {"type": "Pipeline Checker", "severity": "low"}] | ["Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 0 | D |
258 | train.iloc[:,:-2].sample(3) | No | 5 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
259 | X = train.iloc[:,:-2]
print(X.shape)
X.sample(3) | No | 3 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
260 | Y = train.iloc[:,-2:]
print(Y.shape)
Y.sample(3) | No | 3 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
261 | from sklearn.model_selection import train_test_split
trainX , valX, trainY, valY = train_test_split(X, Y, random_state=1) | No | 5 | 13 | Data_Transform | split | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}] | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | [] | 0 | B |
262 | y1Train = trainY.iloc[:,0]
print(y1Train.shape)
y1Train.sample(3) | No | 3 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
263 | y2Train = trainY.iloc[:,1]
y2Train.sample(3) | No | 5 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
264 | y1Val = valY.iloc[:,0]
y1Val.sample(3) | No | 5 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
265 | y2Val = valY.iloc[:,1]
y2Val.sample(3) | No | 4 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
266 | print(trainX.shape)
trainX.sample(3) | No | 4 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
267 | print(trainX.info()) | No | 5 | 40 | Debug | show_table_attributes | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
268 | trainX.iloc[:,1:].sample(3) | No | 5 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
269 | from sklearn.tree import DecisionTreeRegressor
lrModel1 = DecisionTreeRegressor(random_state = 27)
%time lrModel1.fit(trainX.iloc[:,1:], y1Train) | No | 3 | 4 | Model_Train | choose_model_class | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
270 | %time y1Pred = lrModel1.predict(valX.iloc[:,1:])
print(y1Pred[:,]) | No | 4 | 27 | Model_Train | predict_on_train | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
271 | from sklearn.metrics import mean_absolute_error
print("Accuracy in train set : ", lrModel1.score(trainX.iloc[:,1:], y1Train))
print("RMSE : ", mean_absolute_error(y1Val, y1Pred)**(0.5)) | No | 4 | 28 | Model_Train | compute_train_metric | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Unit Testing Checker", "fix": "Write unit tests for data processing and model components.", "benefits": "Ensures code reliability and prevents bugs.", "location": ""}] | A | no applicable ML-specific findings | [] | ["Unit Testing Checker"] | 0 | A |
272 | print(test.shape)
test.sample(3) | No | 3 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
273 | test.iloc[:,1:].sample(3) | No | 5 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
274 | %time finalPred1 = lrModel1.predict(test.iloc[:,1:])
print(finalPred1[:,]) | No | 5 | 48 | Model_Evaluation | predict_on_test | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
275 | %time finalPred2 = lrModel2.predict(test.iloc[:,1:])
print(finalPred2[:,]) | No | 5 | 48 | Model_Evaluation | predict_on_test | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
276 | outputFile = pd.DataFrame({"ForecastId": test.ForecastId,
"ConfirmedCases": (finalPred1+0.5).astype('int'),
"Fatalities": (finalPred2+0.5).astype('int')})' | No | 5 | 12 | Data_Transform | create_dataframe | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
277 | outputFile.sample(3) | No | 5 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
278 | outputFile.to_csv("submission.csv", index=False) | No | 5 | 25 | Data_Export | save_to_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
279 | import plotly.express as px
import plotly.graph_objs as go
from plotly.subplots import make_subplots
import plotly
plotly.offline.init_notebook_mode() # For not show up chart error
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from IPython.display import HTML
%matplotlib inline
from tqdm im... | No | 4 | 22 | Environment | import_modules | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
280 | # Fix error in train data
FirstDate = train.groupby('Country_Region').min()['Date'].unique()[0]
train['Last Confirm'] = train['ConfirmedCases'].shift(1)
while train[(train['Last Confirm'] > train['ConfirmedCases']) & (train['Date'] > FirstDate)].shape[0] > 0:
train['Last Confirm'] = train['ConfirmedCases'].shift(1)... | No | 5 | 8 | Data_Transform | feature_engineering | null | 2 | B | 2 | 1 | 1 | 0 | 24 | 9 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
281 | RMSLE(df_val[(df_val['ConfirmedCases'].isnull() == False)]['ConfirmedCases'].values,df_val[(df_val['ConfirmedCases'].isnull() == False)]['ConfirmedCases_hat'].values) | No | 5 | 49 | Model_Evaluation | compute_test_metric | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
282 | RMSLE(df_val[(df_val['Fatalities'].isnull() == False)]['Fatalities'].values,df_val[(df_val['Fatalities'].isnull() == False)]['Fatalities_hat'].values) | No | 5 | 49 | Model_Evaluation | compute_test_metric | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
283 | val_score = []
for country in df_val['Country_Region'].unique():
df_val_country = df_val[(df_val['Country_Region'] == country) & (df_val['Fatalities'].isnull() == False)]
val_score.append([country, RMSLE(df_val_country['ConfirmedCases'].values,df_val_country['ConfirmedCases_hat'].values),RMSLE(df_val_country['F... | No | 3 | 49 | Model_Evaluation | compute_test_metric | null | 1 | A | 0 | 1 | 1 | 0 | 0 | 7 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
284 | country = "Vietnam"
df_val = df_val_1
df_val[df_val['Country_Region'] == country].groupby(['Date','Country_Region']).sum().reset_index()' | No | 2 | 41 | Debug | show_table | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
285 | country = "Vietnam"
df_val = df_val_1
df_country = df_val[df_val['Country_Region'] == country].groupby(['Date','Country_Region']).sum().reset_index()
df_train = train[(train['Country_Region'].isin(df_country['Country_Region'].unique())) & (train['ConfirmedCases'] > 0)].groupby(['Date']).sum().reset_index()
idx = df_co... | No | 3 | 33 | Visualization | distribution | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
286 | df_total = df_val.groupby(['Date']).sum().reset_index()
df_train = train[(train['Country_Region'].isin(df_val['Country_Region'].unique())) & (train['ConfirmedCases'] > 0)].groupby(['Date']).sum().reset_index()
idx = df_total[((df_total['ConfirmedCases'].isnull() == False) & (df_total['ConfirmedCases'] > 0))].shape[0]
... | No | 4 | 33 | Visualization | distribution | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
287 | import requests
from bs4 import BeautifulSoup
req = requests.get('https://www.worldometers.info/coronavirus/')
soup = BeautifulSoup(req.text, "lxml")
df_country = soup.find('div',attrs={"id" : "nav-tabContent"}).find('table',attrs={"id" : "main_table_countries_today"}).find_all('tr')
arrCountry = []
for i in range(1,... | No | 5 | 53 | Other | something_strange | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
288 | fig = px.bar(df_worldinfor.sort_values('Total Cases', ascending=False)[:10][::-1],
x='Total Cases', y='Country',
title='Total Cases Worldwide', text='Total Cases', orientation='h')
fig.show()
fig = px.bar(df_worldinfor.sort_values('Cases', ascending=False)[:10][::-1],
x='Cases'... | No | 5 | 33 | Visualization | distribution | null | 1 | A | 2 | 0 | 0 | 0 | 12 | 12 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
289 | df_worldinfor[df_worldinfor['Country'] == 'Vietnam'] | No | 5 | 14 | Data_Transform | filter | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
290 | import matplotlib.pyplot as plt
import seaborn as sns
from keras.layers import Dense
from keras.layers import LSTM
from keras.layers import RepeatVector
from keras.layers import TimeDistributed
from keras.models import Sequential
from keras.wrappers.scikit_learn import KerasRegressor
from sklearn.model_selection impor... | No | 5 | 22 | Environment | import_modules | 8,705,213 | 1 | A | 0 | 0 | 0 | 0 | 0 | 11 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 5 | A |
291 | raw_train_data = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-2/train.csv')
test_data = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-2/test.csv') | No | 5 | 45 | Data_Extraction | load_from_csv | 8,705,213 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 3 | 2 | [{"detector": "general_ml", "framework": "General ML", "name": "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "fix": "Not specified", "benefits": "Not specified", "location": ""}, {"detector": "general_ml", "framework": "General ML", "name": "Har... | A | no applicable ML-specific findings | [] | ["Hardcoded file path", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness."] | 5 | A |
292 | # change dtypes
train_data = raw_train_data
train_data['Date'] = pd.to_datetime(train_data['Date'])
train_data['Province_State'] = train_data['Province_State'].fillna('None') | No | 3 | 16 | Data_Transform | data_type_conversions | 8,705,213 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Valida... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Column Selection Checker"] | 5 | B |
293 | # scale features independently
case_scaler = MinMaxScaler(feature_range=(0, 100))
fat_scaler = MinMaxScaler(feature_range=(0, 100))
train_data['ConfirmedCases_scaled'] = case_scaler.fit_transform(train_data['ConfirmedCases'].values.reshape(-1,1))
train_data['Fatalities_scaled'] = fat_scaler.fit_transform(train_data['Fa... | No | 5 | 18 | Data_Transform | normalization | 8,705,213 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 16 | 11 | [{"detector": "framework_specific", "framework": "Pandas", "name": "DataFrame Conversion Checker", "fix": "Use .to_numpy() instead of .values.", "benefits": "Ensures future compatibility and avoids unexpected behaviour.", "location": "Line 9"}, {"detector": "framework_specific", "framework": "Pandas", "name": "DataFram... | D | Cross Validation Checker=low, Cross-validation not detected=low, Data Leakage Checker=high, No random seed setting detected=low, Pipeline Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}, {"type": "No random seed setting detected", "severity": "low"}, {"type": "Pipeline Checker", "severity": "low"}] | ["Column Selection Checker", "DataFrame Conversion Checker", "Exception Handling Checker", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker", "Verbose Mode Checker"] | 5 | D |
294 | # plot global cases and fatalities temporally
global_cases = train_data.groupby(['Date'])[['ConfirmedCases','Fatalities']].sum()
fig,ax = plt.subplots(figsize=(8,5))
_=ax.plot(global_cases['ConfirmedCases'],label='Cases',c='k')
_=ax.plot(global_cases['Fatalities'],label='Deaths',c='r')
_=ax.xaxis.set_tick_params(rotat... | No | 4 | 33 | Visualization | distribution | 8,705,213 | 1 | A | 0 | 0 | 0 | 0 | 0 | 8 | ok | 4 | 4 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Valida... | B | Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}] | ["Column Selection Checker"] | 5 | B |
295 | fig,ax = plt.subplots(figsize=(8,5))
for i in highest_cases_countries.index:
_=ax.plot(regions[regions['Country_Region']==i]['Date'],
regions[regions['Country_Region']==i]['ConfirmedCases'],label=i)
_=ax.legend()
_=ax.xaxis.set_tick_params(rotation=15)
_=sns.despine()
_=ax.set(title='Re... | No | 5 | 33 | Visualization | distribution | 8,705,213 | 1 | A | 0 | 1 | 1 | 0 | 0 | 8 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}] | A | no applicable ML-specific findings | [] | ["Column Selection Checker"] | 5 | A |
296 | reshaped_data.shape | No | 5 | 58 | Debug | show_shape | 8,705,213 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 5 | A |
297 | model_data.shape | No | 5 | 58 | Debug | show_shape | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
298 | # LSTM input is 3D (samples, timesteps, feats), output is 2D(samples,feats)
# cross val data
restack = reshaped_data.values
x = restack[:,:-2].reshape(len(restack),n_in,2)
y = restack[:,-2:] | No | 4 | 13 | Data_Transform | split | 8,705,213 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}] | A | no applicable ML-specific findings | [] | ["Column Selection Checker"] | 5 | A |
299 | print(x.shape,y.shape) | No | 5 | 58 | Debug | show_shape | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
300 | def build_regressor(optimizer,lstm_nodes):
# define model
model = Sequential()
model.add(LSTM(lstm_nodes, activation='relu', input_shape=(n_in,2)))
model.add(Dense(2, activation='relu'))
model.compile(optimizer=optimizer, loss='mean_squared_logarithmic_error')
return model | No | 5 | 4 | Model_Train | choose_model_class | 8,705,213 | 1 | A | 0 | 1 | 0 | 0 | 0 | 6 | ok | 1 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Missing docstring for function: build_regressor. Consider adding documentation for parameters and return values.", "fix": "Not specified", "benefits": "Not specified", "location": "Line 6"}] | A | no applicable ML-specific findings | [] | ["Missing function docstring"] | 5 | A |
301 | # scikit wrapper function
regressor = KerasRegressor(build_fn = build_regressor,verbose=0)
# grid search parameters
parameters = {'lstm_nodes':[14,16,20],
'nb_epoch':[50],
'batch_size':[32],
'optimizer':['adam']}
gridsearch = GridSearchCV(estimator = regressor,
... | No | 3 | 5 | Hyperparam_Tuning | define_search_space | 8,705,213 | 1 | A | 0 | 0 | 0 | 0 | 0 | 11 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Unit Testing Checker", "fix": "Write unit tests for data processing and model components.", "benefits": "Ensures code reliability and prevents bugs.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Excepti... | A | no applicable ML-specific findings | [] | ["Exception Handling Checker", "Unit Testing Checker"] | 5 | A |
302 | # restack train and val
gridsearch = gridsearch.fit(x,y) | No | 5 | 6 | Hyperparam_Tuning | train_on_grid | 8,705,213 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 4 | 4 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 5 | B |
303 | gridsearch.cv_results_ | No | 4 | 1 | Hyperparam_Tuning | find_best_score | 8,705,213 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 5 | A |
304 | gridsearch.best_params_ | No | 3 | 2 | Hyperparam_Tuning | find_best_params | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.