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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1,037 | submission['Fatalities'].sum() | No | 5 | 40 | Debug | show_table_attributes | 8,620,454 | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 14 | null |
1,038 | len(submission) | 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 |
1,039 | submission.to_csv('submission.csv') | 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 |
1,040 | df_train.Province_State.fillna('NaN', inplace=True) | No | 5 | 17 | Data_Transform | correct_missing_values | 8,628,909 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,041 | df_plot = df_train.groupby(['Date','Country_Region','Province_State'], as_index=False)['ConfirmedCases','Fatalities'].sum() | No | 5 | 60 | Data_Transform | groupby | 8,628,909 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,042 | import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
import datetime
import numpy as np
import random
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.utils.data as tud
import torch.optim as optim
# set cuda
USE_CUDA = torch.cuda.is_available()
DEVICE = torch.device(... | No | 5 | 77 | Other | define_variables | 8,663,175 | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
1,043 | df = training.groupby(['Country_Region', 'Date'], as_index=False).sum()
df_test = testing.groupby(['Country_Region', 'Date'], as_index=False).sum() | No | 5 | 60 | Data_Transform | groupby | 8,658,083 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 3 | 3 | [{"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": "general_ml", "framework": "General ML", "name... | 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"}] | [] | 3 | B |
1,044 | df_test[df_test.Country_Region == 'Italy'] | No | 5 | 14 | Data_Transform | filter | 8,658,083 | 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 |
1,045 | df[df.Country_Region == 'Italy'] | No | 5 | 14 | Data_Transform | filter | 8,658,083 | 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 |
1,046 | len(df.Country_Region.unique()) | No | 5 | 54 | EDA | count_unique_values | 8,658,083 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,047 | len(df_test.Country_Region.unique()) | No | 5 | 54 | EDA | count_unique_values | 8,658,083 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,048 | train = pd.merge(training, data_, on=['Country_Region'], how= 'left')
test = pd.merge(testing, data_, on=['Country_Region'], how= 'left') | No | 5 | 32 | Data_Transform | merge | 8,658,083 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,049 | df = df_plot.query("Country_Region=='India'")
px.line(df, x='Date', y='ConfirmedCases', title='Daily Cases growth for India')' | No | 5 | 33 | Visualization | distribution | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,050 | train.isna().sum() | No | 5 | 39 | EDA | count_missing_values | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,051 | px.line(df, x='Date', y='Fatalities', title='Daily Deaths growth for India') | No | 5 | 75 | Visualization | time_series | 8,628,909 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,052 | data_[data_.Restrictions_date.notnull()][['Country_Region', 'Quarantine_date']] | No | 5 | 14 | Data_Transform | filter | 8,658,083 | 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 |
1,053 | train.loc[(train['Date'] == '2020-03-20') &(train.Country_Region == 'Argentina') ] | No | 5 | 14 | Data_Transform | filter | 8,658,083 | 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 |
1,054 | import pandas as pd
import numpy as np | No | 5 | 22 | Environment | import_modules | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 0 | A |
1,055 | ch_geojson = "../input/china-regions-map/china-provinces.json"
df_plot['day'] = df_plot.Date.dt.dayofyear
df_plot['Province_ch'] = ""' | No | 3 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,056 | PATH_WEEK='/kaggle/input/covid19-global-forecasting-week-2'
df_train = pd.read_csv(f'{PATH_WEEK}/train.csv')
df_test = pd.read_csv(f'{PATH_WEEK}/test.csv')
df_hospital_beds = pd.read_csv(r"/kaggle/input/hospital-beds/API_SH.MED.BEDS.ZS_DS2_en_csv_v2_887506.csv",
skiprows=4)
df_populati... | No | 1 | 45 | Data_Extraction | load_from_csv | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,057 | test['Quarantine'] = 0
test['Schools'] = 0
test['Restrictions'] = 0
test.loc[(test.Country_Region == 'Argentina'), 'Quarantine' ] = 1
test.loc[(test.Country_Region == 'Austria'), 'Quarantine' ] = 1
test.loc[(test.Country_Region == 'Belgium'), 'Quarantine' ] = 1
test.loc[(test.Country_Region == 'China'), 'Quarantine' ]... | No | 4 | 8 | Data_Transform | feature_engineering | 8,658,083 | 1 | A | 0 | 0 | 0 | 0 | 0 | 21 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "Pandas", "name": "InPlace Checker", "fix": "Assign operations to a new DataFrame variable.", "benefits": "Prevents data loss and improves code clarity.", "location": "Line 28"}, {"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker"... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "InPlace Checker"] | 3 | A |
1,058 | df = df_plot.query("Country_Region=='China'")
fig = px.choropleth_mapbox(df,
geojson=ch_geojson,
#scope="asia",
color="ConfirmedCases",
locations="Province_ch",
featureidkey="objects.CHN_adm1.geometries.properties.NL_NAME_1",
#featureid... | No | 5 | 33 | Visualization | distribution | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,059 | train['Quarantine'] = 0
train['Schools'] = 0
train['Restrictions'] = 0
train.loc[(train['Date'] >= '2020-03-20') &(train.Country_Region == 'Argentina'), 'Quarantine' ] = 1
train.loc[(train['Date'] >= '2020-03-16') &(train.Country_Region == 'Austria'), 'Quarantine' ] = 1
train.loc[(train['Date'] >= '2020-03-18') &(trai... | No | 5 | 8 | Data_Transform | feature_engineering | 8,658,083 | 1 | A | 0 | 0 | 0 | 0 | 0 | 21 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "Pandas", "name": "InPlace Checker", "fix": "Assign operations to a new DataFrame variable.", "benefits": "Prevents data loss and improves code clarity.", "location": "Line 28"}, {"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker"... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Column Selection Checker", "InPlace Checker"] | 3 | B |
1,060 | train[train.Quarantine == 1][['Country_Region', 'Date']].head(50) | No | 5 | 41 | Debug | show_table | 8,658,083 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | 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"] | 3 | B |
1,061 | df = df_plot.query("Country_Region=='China'")
px.line(df, x='Date', y='ConfirmedCases', color='Province_State', title='Daily Cases growth for China')' | No | 5 | 33 | Visualization | distribution | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,062 | country_names = {'Bahamas, The': 'Bahamas',
'Brunei Darussalam' : 'Brunei',
'DR Congo' : 'Congo (Kinshasa)',
"Cte d'Ivoire" : "Cote d'Ivoire",
'Congo' : 'Congo (Brazzaville)',
'Congo, Rep.': 'Congo (Brazzaville)',
'Congo, Dem. Rep.': 'Congo (Kinshasa)',
'Czech Republic (Czechia)' : 'Czechia',
'Czech ... | Yes | 1 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,063 | px.line(df, x='Date', y='Fatalities', color='Province_State', title='Daily Deaths growth for China') | No | 5 | 75 | Visualization | time_series | 8,628,909 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,064 | data_[data_.Quarantine_date.notnull()] | No | 5 | 14 | Data_Transform | filter | 8,658,083 | 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 |
1,065 | df_train['NumDate'] = df_train.Date.astype(int)/((10**9)*60*60*24)
first_date = df_train.NumDate.min()
df_train.NumDate -= first_date
df_train.head()
df_test['NumDate'] = df_test.Date.astype(int)/((10**9)*60*60*24)
df_test.NumDate -= first_date
outbreak_dates = df_train[['Country', 'NumDate']][df_train.ConfirmedCases... | Yes | 1 | 8 | Data_Transform | feature_engineering | 8,671,133 | 1 | A | 0 | 0 | 0 | 0 | 0 | 21 | ok | 5 | 4 | [{"detector": "framework_specific", "framework": "Pandas", "name": "InPlace Checker", "fix": "Assign operations to a new DataFrame variable.", "benefits": "Prevents data loss and improves code clarity.", "location": "Line 24"}, {"detector": "framework_specific", "framework": "Pandas", "name": "InPlace Checker", "fix": ... | 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"}] | ["InPlace Checker"] | 5 | B |
1,066 | def categoricalToInteger(df):
#convert NaN Province State values to a string
df.Province_State.fillna('NaN', inplace=True)
#Define Ordinal Encoder Model
oe = OrdinalEncoder()
df[['Province_State','Country_Region']] = oe.fit_transform(df.iloc[:,1:3])
return df | No | 5 | 20 | Data_Transform | categorify | 8,628,909 | 2 | B | 1 | 1 | 0 | 0 | 10 | 5 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,067 | df_train.WorldShare = df_train.WorldShare.str.rstrip('%').astype('float') / 100.0
df_test.WorldShare = df_test.WorldShare.str.rstrip('%').astype('float') / 100.0
df_train.UrbanPop = df_train.UrbanPop.str.rstrip('%').astype('float') / 100.0
df_test.UrbanPop = df_test.UrbanPop.str.rstrip('%').astype('float') / 100.0
df_t... | No | 5 | 16 | Data_Transform | data_type_conversions | 8,671,133 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | ok | 3 | 3 | [{"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": "general_ml", "framework": "General ML", "name... | 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"}] | [] | 5 | B |
1,068 | def create_features(df):
df['day'] = df['Date'].dt.day
df['month'] = df['Date'].dt.month
df['dayofweek'] = df['Date'].dt.dayofweek
df['dayofyear'] = df['Date'].dt.dayofyear
df['quarter'] = df['Date'].dt.quarter
df['weekofyear'] = df['Date'].dt.weekofyear
return df | No | 5 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | 1 | 0 | 0 | 0 | 8 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,069 | from scipy.optimize import curve_fit
import matplotlib.pyplot as plt
def log_growth(x, a,r,c):
return 1.0*c/(1+a * np.exp(-r * x))
def get_log_fit_params(data):
try:
popt, pcov = curve_fit(log_growth, data.NumDate, data.ConfirmedCases, method="lm")
return popt
except RuntimeError:
... | No | 5 | 53 | Other | something_strange | 8,671,133 | 1 | A | 1 | 2 | 3 | 0 | 5 | 17 | ok | 7 | 6 | [{"detector": "framework_specific", "framework": "NumPy", "name": "Array Creation Efficiency", "fix": "Specify dtype when creating arrays.", "benefits": "Improves memory efficiency and avoids unnecessary conversions.", "location": "Line 20"}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross... | 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"}] | ["Array Creation Efficiency", "Unit Testing Checker", "Verbose Mode Checker"] | 5 | B |
1,070 | df_opt[df_opt.a>0] | No | 5 | 14 | Data_Transform | filter | 8,671,133 | 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"] | 5 | A |
1,071 | df_train = pd.merge(df_train, df_opt, on="Country", how="left")
df_test = pd.merge(df_test, df_opt, on="Country", how="left") | No | 5 | 32 | Data_Transform | merge | 8,671,133 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 5 | A |
1,072 | df_train['LogPrediction'] = df_train.apply(lambda x : log_growth(x.NumDate, x.a, x.r, x.c), axis=1)
df_test['LogPrediction'] = df_test.apply(lambda x : log_growth(x.NumDate, x.a, x.r, x.c), axis=1) | No | 5 | 8 | Data_Transform | feature_engineering | 8,671,133 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | 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 |
1,073 | train['Quarantine'].any() ==1 | No | 5 | 53 | Other | something_strange | 8,658,083 | 1 | A | 0 | 0 | 0 | 1 | 0 | 1 | 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"] | 3 | B |
1,074 | train[train.Country_Region=='Italy'] | No | 5 | 14 | Data_Transform | filter | 8,658,083 | 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 |
1,075 | def cum_sum(df, date, country, state):
sub_df = df[(df['Country_Region']==country) & (df['Province_State']==state) & (df['Date']<=date)]
display(sub_df)
return sub_df['ConfirmedCases'].sum(), sub_df['Fatalities'].sum() | Yes | 3 | 14 | Data_Transform | filter | 8,628,909 | 1 | A | 0 | 1 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,076 | from sklearn.metrics import mean_squared_log_error
from sklearn.model_selection import KFold
from sklearn.preprocessing import PolynomialFeatures
import xgboost as xgb
df_train.fillna(0, inplace=True)
df_test.fillna(0, inplace=True)
features = ['NumDate', "Population", "YearlyChange",
"NetChang... | Yes | 1 | 11 | Data_Transform | concatenate | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
1,077 | df_out = pd.DataFrame(df_test.ForecastId)
X = pd.concat([df_test[features], pd.get_dummies(df_test.Country,prefix="C_"), pd.get_dummies(df_test.State,prefix="S_")],axis=1)
df_out['ConfirmedCases'] = [max(x,0) for x in fit1.predict(X)]
df_out['Fatalities'] = [max(x,0) for x in fit2.predict(X)]
df_out.tail()' | Yes | 1 | 11 | Data_Transform | concatenate | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,078 | train[train['Restrictions'] == 1] | No | 5 | 14 | Data_Transform | filter | 8,658,083 | 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 |
1,079 | train.columns | No | 5 | 71 | Debug | show_columns | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,080 | def train_dev_split(df):
date = df['Date'].max() - dt.timedelta(days=7)
return df[df['Date'] <= date], df[df['Date'] > date] | No | 5 | 13 | Data_Transform | split | 8,628,909 | 1 | A | 0 | 1 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,081 | train.hist(figsize=(11,10)) | No | 5 | 33 | Visualization | distribution | 8,658,083 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | 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"}] | [] | 3 | B |
1,082 | feat_importances = pd.Series(fit1.feature_importances_, index=X.columns)
feat_importances.sort_values(ascending=False).head(20) | No | 4 | 9 | Data_Transform | sort_values | 8,671,133 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 5 | A |
1,083 | df_train = categoricalToInteger(df_train)
df_train = create_features(df_train) | No | 5 | 8 | Data_Transform | feature_engineering | 8,628,909 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,084 | train.drop(['Tests','Test Pop', 'Density', 'Urban Pop', 'sex0', 'sex14',
'sex25', 'sex54', 'sex64', 'sex65plus', 'Sex Ratio', 'lung',
'Female Lung', 'Male Lung', 'Crime Index', 'Population 2020',
'Smoking 2016', 'Females 2018', 'Total Infected','Total Deaths',
'Total Reco... | No | 5 | 10 | Data_Transform | drop_column | 8,658,083 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "Pandas", "name": "InPlace Checker", "fix": "Assign operations to a new DataFrame variable.", "benefits": "Prevents data loss and improves code clarity.", "location": "Line 4"}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Chec... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["InPlace Checker"] | 3 | B |
1,085 | prediction_ww = pd.merge(df_test, df_out, on="ForecastId")[["Date", "ConfirmedCases", "Fatalities"]].groupby("Date").sum()
prediction_ww.set_axis(["PredictedCases", "PredictedFatalities"], axis=1, inplace=True)
prediction_ww.plot() | No | 4 | 11 | Data_Transform | concatenate | 8,671,133 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 7 | 5 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Merge Parameter Checker", "fix": "Specify how, on, and validate parameters in merge operations.", "benefits": "Ensures accurate data merging and prevents data loss.", "location": "Line 6"}, {"detector": "framework_specific", "framework": "Pandas", "nam... | B | No random seed setting detected=low | [{"type": "No random seed setting detected", "severity": "low"}] | ["Exception Handling Checker", "Merge Parameter Checker", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker"] | 5 | B |
1,086 | df_train, df_dev = train_dev_split(df_train) | No | 5 | 13 | Data_Transform | split | 8,628,909 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,087 | test.drop(['Tests','Test Pop', 'Density', 'Urban Pop', 'sex0', 'sex14',
'sex25', 'sex54', 'sex64', 'sex65plus', 'Sex Ratio', 'lung',
'Female Lung', 'Male Lung', 'Crime Index', 'Population 2020',
'Smoking 2016', 'Females 2018', 'Total Infected', 'Total Deaths',
'Total Recovere... | No | 5 | 10 | Data_Transform | drop_column | 8,658,083 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "Pandas", "name": "InPlace Checker", "fix": "Assign operations to a new DataFrame variable.", "benefits": "Prevents data loss and improves code clarity.", "location": "Line 4"}] | A | no applicable ML-specific findings | [] | ["InPlace Checker"] | 3 | A |
1,088 | train_ww = df_train[["Date", "ConfirmedCases", "Fatalities"]].groupby("Date").sum()
train_ww.plot() | No | 4 | 60 | Data_Transform | groupby | 8,671,133 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 3 | 3 | [{"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": "general_ml", "framework": "General ML", "name... | 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"}] | [] | 5 | B |
1,089 | pd.merge(train_ww, prediction_ww, how='outer', on="Date").plot()' | No | 5 | 32 | Data_Transform | merge | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,090 | print(train.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 |
1,091 | print(test.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 |
1,092 | test.isna().sum() | No | 5 | 39 | EDA | count_missing_values | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,093 | columns = ['day','month','dayofweek','dayofyear','quarter','weekofyear','Province_State', 'Country_Region','ConfirmedCases','Fatalities']
df_train = df_train[columns]
df_dev = df_dev[columns] | No | 5 | 10 | Data_Transform | drop_column | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,094 | test.Date = pd.to_datetime(test.Date) | No | 5 | 16 | Data_Transform | data_type_conversions | 8,658,083 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,095 | train = df_train.values
dev = df_dev.values
X_train, y_train = train[:,:-2], train[:,-2:]
X_dev, y_dev = dev[:,:-2], dev[:,-2:] | No | 4 | 21 | Data_Transform | prepare_x_and_y | 8,628,909 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,096 | def create_time_features(df):
"""
Creates time series features from datetime index
"""
df['date'] = df.index
df['dayofweek'] = df['Date'].dt.dayofweek
df['quarter'] = df['Date'].dt.quarter
df['month'] = df['Date'].dt.month
df['dayofyear'] = df['Date'].dt.dayofyear
df['dayofmonth'] = ... | No | 5 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,097 | import pandas as pd
#import plotly.express as px
#import matplotlib.pyplot as plt
#import plotly.graph_objects as go
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
import numpy as np
from sklearn.metrics import mean_squared_log_error
from sklearn.tree import Decis... | No | 5 | 22 | Environment | import_modules | 8,679,319 | 1 | A | 1 | 0 | 0 | 0 | 5 | 9 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 7 | A |
1,098 | train_df=pd.read_csv("../input/covid19-global-forecasting-week-2/train.csv")
test_df=pd.read_csv("../input/covid19-global-forecasting-week-2/test.csv") | No | 5 | 45 | Data_Extraction | load_from_csv | 8,679,319 | 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."] | 7 | A |
1,099 | train.Date = pd.to_datetime(train.Date) | No | 5 | 16 | Data_Transform | data_type_conversions | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,101 | create_time_features(train)
create_time_features(test) | No | 5 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,102 | def modelfit(alg, X_train, y_train,useTrainCV=True, cv_folds=5, early_stopping_rounds=50):
if useTrainCV:
xgb_param = alg.get_xgb_params()
xgtrain = xgb.DMatrix(X_train, label=y_train)
cvresult = xgb.cv(xgb_param, xgtrain, num_boost_round=alg.get_params()['n_estimators'], nfold=cv_folds... | Yes | 2 | 7 | Model_Train | train_model | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,103 | train.drop(["Id","Date", 'date'], axis=1, inplace=True)
test.drop(["Date", 'date'], axis=1, inplace=True)' | No | 5 | 10 | Data_Transform | drop_column | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,104 | print("Min train date: ",train_df["Date"].min())
print("Max train date: ",train_df["Date"].max())
print("Min test date: ",test_df["Date"].min())
print("Max test date: ",test_df["Date"].max()) | No | 5 | 40 | Debug | show_table_attributes | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,105 | train_df=train_df[train_df["Date"]<"2020-03-19"] | No | 5 | 14 | Data_Transform | filter | 8,679,319 | 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"] | 7 | A |
1,107 | test_df.isnull().sum() | No | 5 | 39 | EDA | count_missing_values | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,109 | pop_info = pd.read_csv("../input/population-by-country-2020/population_by_country_2020.csv") | No | 5 | 45 | Data_Extraction | load_from_csv | 8,679,319 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 1 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path detected: ../input/population-by-country-2020/population_by_country_2020.csv. Consider using configuration files or environment variables.", "fix": "Not specified", "benefits": "Not specified", "location": "Line 8"}] | A | no applicable ML-specific findings | [] | ["Hardcoded file path"] | 7 | A |
1,110 | b"pop_info.rename(columns={'Density (P/Km)': 'Density'}, inplace=True)" | No | 5 | 61 | Data_Transform | rename_columns | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,111 | pop_info.columns | No | 5 | 71 | Debug | show_columns | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,112 | country_lookup=pop_info[["Country (or dependency)","Population (2020)","Density"]] | No | 5 | 12 | Data_Transform | create_dataframe | 8,679,319 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 7 | A |
1,113 | pd.DataFrame.from_dict(country_lookup)
train_df_pop=pd.merge(train_df, country_lookup, how='left', left_on='Country_Region', right_on='Country (or dependency)') | No | 4 | 11 | Data_Transform | concatenate | 8,679,319 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 7 | A |
1,114 | train_df_pop.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 |
1,115 | train_df_pop.loc[train_df_pop["Country_Region"]=="US", ["Population (2020)"]]=331002651 #United Sates
train_df_pop.loc[train_df_pop["Country_Region"]=="US", ["Density"]]=36
train_df_pop.loc[train_df_pop["Country_Region"]=="Korea, South", ["Population (2020)"]]=51269185 #South Korea
train_df_pop.loc[train_df_pop["Countr... | No | 5 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,116 | model1 = XGBRegressor(n_estimators=1000)
model2 = XGBRegressor(n_estimators=1000) | No | 5 | 4 | Model_Train | choose_model_class | 8,628,909 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,117 | model1.fit(X_train, y_train[:,0],
eval_set=[(X_train, y_train[:,0]), (X_dev, y_dev[:,0])],
verbose=False) | No | 5 | 7 | Model_Train | train_model | 8,628,909 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,118 | model2.fit(X_train, y_train[:,1],
eval_set=[(X_train, y_train[:,1]), (X_dev, y_dev[:,1])],
verbose=False) | No | 5 | 7 | Model_Train | train_model | 8,628,909 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,119 | plot_importance(model1); | No | 3 | 79 | Visualization | model_coefficients | 8,628,909 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,120 | plot_importance(model2); | No | 3 | 79 | Visualization | model_coefficients | 8,628,909 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,121 | df_train = categoricalToInteger(df_test)
df_train = create_features(df_test) | No | 3 | 8 | Data_Transform | feature_engineering | 8,628,909 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,122 | columns = ['day','month','dayofweek','dayofyear','quarter','weekofyear','Province_State', 'Country_Region']
df_test = df_test[columns] | No | 5 | 10 | Data_Transform | drop_column | 8,628,909 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,123 | y_pred1 = model1.predict(df_test.values)
y_pred2 = model2.predict(df_test.values) | No | 5 | 48 | Model_Evaluation | predict_on_test | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,124 | df_submit = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-2/submission.csv') | No | 5 | 45 | Data_Extraction | load_from_csv | 8,628,909 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,125 | df_submit.ConfirmedCases = y_pred1
df_submit.Fatalities = y_pred2 | No | 5 | 55 | Data_Export | prepare_output | 8,628,909 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,127 | df_submit.to_csv(r'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 |
1,128 | # Installing the required libs
!pip install -q fastprogress fastai2 fastcore fast_tabnet --upgrade | No | 5 | 87 | Environment | install_modules | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,129 | from fastai2.basics import *
from fastai2.tabular.all import *
from fast_tabnet.core import * | No | 5 | 22 | Environment | import_modules | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,130 | import sys
sys.path.insert(0, "../input/covid19-global-forecasting-week-2/")
import warnings
warnings.filterwarnings(action='once')' | No | 3 | 23 | Environment | set_options | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,131 | df = pd.read_csv('/kaggle/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 |
1,132 | df_test = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-2/test.csv')
df_test.head() | Yes | 4 | 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 |
1,133 | df['key'] = df['Country_Region'] + '#' + df['Province_State'].fillna('')
df['province_flag'] = np.where(df['Province_State'].isnull(),0,1)
df['Province_State'] = df['Province_State'].fillna(df['Country_Region']) | Yes | 3 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,134 | df_test['key'] = df_test['Country_Region'] + '#' + df_test['Province_State'].fillna('')
df_test['province_flag'] = np.where(df_test['Province_State'].isnull(),0,1)
df_test['Province_State'] = df_test['Province_State'].fillna(df_test['Country_Region']) | Yes | 5 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,135 | df.head(600) | 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 |
1,136 | df_test.head(600) | 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 |
1,137 | #firstconfirmed = df[(df['ConfirmedCases']>0) & (df['Date']<'2020-03-19')].groupby(['Province_State','Country_Region'])['Date'].min().reset_index()
firstconfirmed = df[(df['ConfirmedCases']>0)].groupby(['Province_State','Country_Region'])['Date'].min().reset_index() | No | 5 | 60 | Data_Transform | groupby | null | 3 | C | 1 | 0 | 0 | 0 | 5 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,138 | firstconfirmed.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 |
1,139 | firstconfirmed.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 |
1,140 | firstfatality = df[(df['Fatalities']>0)].groupby(['Province_State','Country_Region'])['Date'].min().reset_index()
#firstfatality = df[(df['Fatalities']>0) & (df['Date']<'2020-03-19')].groupby(['Province_State','Country_Region'])['Date'].min().reset_index() | No | 4 | 60 | Data_Transform | groupby | null | 3 | C | 1 | 0 | 0 | 0 | 5 | 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.