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,242 |
from sklearn.ensemble import RandomForestRegressor
model = RandomForestRegressor(n_estimators=150)
model.fit(X, Y)
test_predicted = pd.DataFrame()
test_predicted['Id'] = test_data.Id
test_predicted['Prediction'] = model.predict(test_data.drop('Id', axis=1))
test_predicted.to_csv('submission-random-forest.csv', inde... | No | 3 | 7 | Model_Train | train_model | 10,424,951 | 1 | A | 2 | 0 | 0 | 0 | 10 | 8 | ok | 13 | 9 | [{"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, Randomness Control Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}, {"type": "Randomness Control Checker", "severity": "low"}] | ["Column Selection 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"] | 8 | B |
1,243 |
model = Ridge(alpha=330)
model.fit(X, Y)
test_predicted = pd.DataFrame()
test_predicted['Id'] = test_data.Id
test_predicted['Prediction'] = model.predict(test_data.drop('Id', axis=1))
test_predicted.to_csv('submission-ridge-330.csv', index=False)
test_predicted.describe()
| No | 3 | 7 | Model_Train | train_model | 10,424,951 | 1 | A | 0 | 0 | 0 | 0 | 0 | 7 | ok | 11 | 8 | [{"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", "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"] | 8 | B |
1,244 |
model = Lasso(alpha=200000)
model.fit(X, Y)
test_predicted = pd.DataFrame()
test_predicted['Id'] = test_data.Id
test_predicted['Prediction'] = model.predict(test_data.drop('Id', axis=1))
test_predicted.to_csv('submission-lasso-high-alpha.csv', index=False)
test_predicted.describe()
| No | 4 | 7 | Model_Train | train_model | 10,424,951 | 1 | A | 0 | 0 | 0 | 0 | 0 | 7 | ok | 11 | 8 | [{"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", "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"] | 8 | B |
1,245 | data['Days_Open'].unique()
| No | 5 | 57 | Debug | show_unique_values | 10,424,951 | 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"] | 8 | A |
1,246 |
data['Time_Open'] = round(data['Days_Open'] / 700, 0)
data = data.drop('Days_Open', axis=1)
test_data['Time_Open'] = round(test_data['Days_Open'] / 700, 0)
test_data = test_data.drop('Days_Open', axis=1)
| No | 4 | 8 | Data_Transform | feature_engineering | 10,424,951 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | 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"] | 8 | A |
1,247 |
X = data.drop(['Id', 'revenue'], axis=1)
Y = data.revenue
| No | 5 | 21 | Data_Transform | prepare_x_and_y | 10,424,951 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 8 | A |
1,248 | model = Ridge(alpha=330)
model.fit(X, Y)
test_predicted = pd.DataFrame()
test_predicted['Id'] = test_data.Id
test_predicted['Prediction'] = model.predict(test_data.drop('Id', axis=1))
test_predicted.to_csv('submission.csv', index=False)
test_predicted | No | 4 | 4 | Model_Train | choose_model_class | 10,424,951 | 1 | A | 0 | 0 | 0 | 1 | 0 | 7 | ok | 10 | 8 | [{"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", "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"] | 8 | B |
1,249 |
model = Lasso(alpha=200000)
model.fit(X, Y)
test_predicted = pd.DataFrame()
test_predicted['Id'] = test_data.Id
test_predicted['Prediction'] = model.predict(test_data.drop('Id', axis=1))
test_predicted.to_csv('submission-lasso-.csv', index=False)
test_predicted.describe()
| No | 4 | 7 | Model_Train | train_model | 10,424,951 | 1 | A | 0 | 0 | 0 | 0 | 0 | 7 | ok | 11 | 8 | [{"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", "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"] | 8 | B |
1,250 | # %%
import numpy as np
import itertools
import plotly.express as px
import pandas as pd
from plotly.subplots import make_subplots
from multiprocessing import Pool
class CoronaSim:
def __init__(self, grid_size, initial_virus, recover_time, speedreaction, incubation, virulence, contactsize=1, num_cores=4):
... | No | 5 | 53 | Other | something_strange | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
1,251 | # Start running simulations
result = test.simspread(t_end=10, savefile='test.npz') | No | 5 | 53 | Other | something_strange | 8,693,806 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 2 | A |
1,252 | # Simulation setup
scenario1 = CoronaSim(grid_size=100, initial_virus=5, contactsize=2, num_cores=6,
recover_time=30, speedreaction=0.01, incubation=7, virulence=25) | No | 5 | 53 | Other | something_strange | 8,693,806 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 2 | A |
1,253 | # %%
import plotly.graph_objects as go
import numpy as np
import pandas as pd
num_infected = []
Day = []
batch_list = []
for batch in range(1, 4):
savefile = f'../input/simulation-scripts/outfile_s{batch}.npz'
container = np.load(savefile)
sim_result = [container[key] for key in container]
for t in ran... | Yes | 2 | 33 | Visualization | distribution | 8,693,806 | 1 | A | 8 | 2 | 3 | 0 | 40 | 60 | 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": "general_ml", "framework": "General ML", "name": "Hardcoded file path d... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Hardcoded file path"] | 2 | A |
1,254 | # %%
import plotly.graph_objects as go
import numpy as np
import pandas as pd
num_infected = []
Day = []
batch_list = []
for batch in range(1, 4):
savefile = f'../input/simulation-scripts/outfile_s{batch}.npz'
container = np.load(savefile)
sim_result = [container[key] for key in container]
acc_list = [... | Yes | 5 | 53 | Other | something_strange | 8,693,806 | 1 | A | 9 | 2 | 3 | 0 | 45 | 62 | 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": "general_ml", "framework": "General ML", "name": "Hardcoded file path d... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Hardcoded file path"] | 2 | A |
1,255 | import plotly.express as px
import pandas as pd
import plotly.graph_objects as go
import numpy as np
datafile = '../input/covid19-global-forecasting-week-2/train.csv'
data = pd.read_csv(datafile)
data['PSCR'] = data.Province_State.map(str)+ '' + data.Country_Region.map(str)
region = pd.unique(data['PSCR']).tolist()
f... | Yes | 2 | 45 | Data_Extraction | load_from_csv | 8,693,806 | 1 | A | 9 | 2 | 4 | 0 | 45 | 61 | 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": "general_ml", "framework": "General ML", "name": "Hardcoded file path d... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Hardcoded file path"] | 2 | A |
1,256 | import plotly.express as px
import pandas as pd
import numpy as np
datafile = '../input/covid19-global-forecasting-week-2/train.csv'
data = pd.read_csv(datafile)
# %%
all_region_data = data[pd.isna(data['Province_State'])]
region = ['Japan', 'Israel']
# region = pd.unique(all_region_data['Country_Region']).tolist()
f... | Yes | 5 | 53 | Other | something_strange | 8,693,806 | 1 | A | 12 | 4 | 7 | 0 | 60 | 77 | ok | 3 | 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": "general_ml", "framework": "General ML", "name": "Hardcoded file path d... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Hardcoded file path"] | 2 | A |
1,257 | # %%
import numpy as np
import plotly.express as px
import plotly.graph_objects as go
import pandas as pd
class plotresult:
def __init__(self, savefile):
container = np.load(savefile)
self.sim_result = [container[key] for key in container]
def infectiongrowth(self):
num_infected = []
... | Yes | 3 | 22 | Environment | import_modules | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
1,258 | # get place list
places = np.sort(df_traintest['place_id'].unique())
print(len(places)) | No | 3 | 57 | Debug | show_unique_values | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,259 | # calc cases, fatalities per day
df_traintest2 = copy.deepcopy(df_traintest)
df_traintest2['cases/day'] = 0
df_traintest2['fatal/day'] = 0
tmp_list = np.zeros(len(df_traintest2))
for place in places:
tmp = df_traintest2['ConfirmedCases'][df_traintest2['place_id']==place].values
tmp[1:] -= tmp[:-1]
df_traint... | No | 2 | 12 | Data_Transform | create_dataframe | null | 1 | A | 0 | 1 | 1 | 0 | 0 | 13 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,260 | pipeline = Pipeline([('scaler', StandardScaler()), ('lr', LinearRegression())])
pipeline.fit(train_numeric_X, train_numeric_Y)
predicted = pipeline.predict(test_numeric_X) | Yes | 3 | 7 | Model_Train | train_model | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,261 | from sklearn.svm import SVR | 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 |
1,262 | pipeline = Pipeline([('scaler', StandardScaler()), ('estimator', SVR())])
pipeline.fit(train_numeric_X, train_numeric_Y.values[:,0])
pipeline2 = Pipeline([('scaler', StandardScaler()), ('estimator', SVR())])
pipeline2.fit(train_numeric_X, train_numeric_Y.values[:,1])
discovered, fatal = pipeline.predict(test_numeric_X)... | No | 3 | 7 | Model_Train | train_model | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,263 | predicted_x1 = pipeline.predict(train_numeric_X)
fig = go.Figure()
fig.add_trace(go.Histogram(
x=train_numeric_Y['ConfirmedCases'],
histnorm='percent',
name='actual discovered', # name used in legend and hover labels
xbins=dict( # bins used for histogram
start=-4.0,
end=3.0,
siz... | No | 5 | 56 | Visualization | plot_predictions | null | 1 | A | 2 | 0 | 0 | 0 | 10 | 32 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,264 | predicted_x2 = pipeline2.predict(train_numeric_X)
fig = go.Figure()
fig.add_trace(go.Histogram(
x=train_numeric_Y['Fatalities'],
histnorm='percent',
name='actual died', # name used in legend and hover labels
xbins=dict( # bins used for histogram
start=-4.0,
end=3.0,
size=0.5
... | No | 5 | 56 | Visualization | plot_predictions | null | 1 | A | 2 | 0 | 0 | 0 | 10 | 32 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,265 | from sklearn.model_selection import KFold
kf = KFold(n_splits=10)
outcomes = []
fold = 0
for train_index, test_index in kf.split(train_numeric_X):
fold += 1
X_train, X_test = train_numeric_X.values[train_index], train_numeric_X.values[test_index]
y_train, y_test = train_numeric_Y['ConfirmedCases'].valu... | No | 3 | 7 | Model_Train | train_model | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
1,266 | from sklearn.neighbors import KNeighborsClassifier | 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 |
1,267 | pipeline = Pipeline([('scaler', StandardScaler()), ('estimator', KNeighborsClassifier(n_jobs=4))])
pipeline.fit(train_numeric_X, train_numeric_Y)
predicted_x = pipeline.predict(train_numeric_X) | No | 4 | 7 | Model_Train | train_model | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,268 | fig = go.Figure()
fig.add_trace(go.Scatter(
x=train_numeric_Y['ConfirmedCases'],
y=train_numeric_Y['Fatalities'],
marker=dict(color="crimson", size=12),
mode="markers",
name="actual",
))
fig.add_trace(go.Scatter(
x=predicted_x[:,0],
y=predicted_x[:,1],
marker=dict(color="lightseagreen",... | No | 5 | 56 | Visualization | plot_predictions | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,269 | from sklearn.ensemble import RandomForestClassifier | 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 |
1,270 | RF_model = RandomForestClassifier(n_estimators=50, n_jobs=4, max_depth=5)
RF_model.fit(train_numeric_X, train_numeric_Y)
predicted = RF_model.predict(test_numeric_X) | No | 3 | 7 | Model_Train | train_model | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,271 | predicted_x = RF_model.predict(train_numeric_X) | No | 5 | 27 | Model_Train | predict_on_train | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,272 | fig = go.Figure()
fig.add_trace(go.Histogram(
x=train_numeric_Y['ConfirmedCases'],
histnorm='percent',
name='actual discovered', # name used in legend and hover labels
xbins=dict( # bins used for histogram
start=-4.0,
end=3.0,
size=0.5
),
opacity=0.75
))
fig.add_trace(go.... | No | 5 | 84 | Other | not_enough_vertices | null | 1 | A | 2 | 0 | 0 | 0 | 10 | 31 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,273 | from sklearn.metrics import make_scorer, accuracy_score
accuracy_score(train_numeric_Y['ConfirmedCases'], predicted_x[:,0]), accuracy_score(train_numeric_Y['Fatalities'], predicted_x[:,1]) | No | 4 | 49 | Model_Evaluation | compute_test_metric | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Threshold Checker", "fix": "Use threshold-independent metrics alongside threshold-dependent ones.", "benefits": "Provides a comprehensive evaluation of model performance.", "location": ""}, {"detector": "framework_specific", "framework":... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Unit Testing Checker"] | 0 | A |
1,274 | from sklearn.model_selection import KFold
kf = KFold(n_splits=10)
outcomes = []
fold = 0
for train_index, test_index in kf.split(train_numeric_X):
fold += 1
X_train, X_test = train_numeric_X.values[train_index], train_numeric_X.values[test_index]
y_train, y_test = train_numeric_Y['ConfirmedCases'].val... | No | 3 | 7 | Model_Train | train_model | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
1,275 | from sklearn.ensemble import AdaBoostClassifier | 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 |
1,276 | adaboost_model_for_ConfirmedCases = AdaBoostClassifier(n_estimators=5)
adaboost_model_for_ConfirmedCases.fit(train_numeric_X, train_numeric_Y[numeric_features_Y[0]])
adaboost_model_for_Fatalities = AdaBoostClassifier(n_estimators=5)
adaboost_model_for_Fatalities.fit(train_numeric_X, train_numeric_Y[numeric_features_Y[1... | No | 4 | 7 | Model_Train | train_model | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,277 | predicted_x1 = adaboost_model_for_ConfirmedCases.predict(train_numeric_X)
predicted_x2 = adaboost_model_for_Fatalities.predict(train_numeric_X)
fig = go.Figure()
fig.add_trace(go.Scatter(
x=train_numeric_Y['ConfirmedCases'],
y=train_numeric_Y['Fatalities'],
marker=dict(color="crimson", size=12),
mode="... | No | 4 | 56 | Visualization | plot_predictions | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,283 | train_y_pred = RF_model.predict(train_numeric_X) | No | 5 | 27 | Model_Train | predict_on_train | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,284 | plt.figure(figsize=(12,8))
plt.hist([train_numeric_Y['ConfirmedCases'],train_y_pred[:,0]],bins=100, range=(1,100), label=['ConfirmedCases_actual','ConfirmedCases_pred'],alpha=0.75)
plt.title('ConfirmedCases Comparison',fontsize=20)
plt.xlabel('sample',fontsize=20)
plt.ylabel('match',fontsize=20)
plt.legend()
plt.show() | No | 5 | 33 | Visualization | distribution | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 7 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,285 | plt.figure(figsize=(12,8))
plt.hist([train_numeric_Y['Fatalities'],train_y_pred[:,1]],bins=100, range=(1,100), label=['Fatalities_actual','Fatalities_pred'],alpha=0.75)
plt.title('Fatalities Comparison',fontsize=20)
plt.xlabel('sample',fontsize=20)
plt.ylabel('match',fontsize=20)
plt.legend()
plt.show() | No | 5 | 56 | Visualization | plot_predictions | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 7 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,286 | error = np.sqrt((train_y_pred - train_numeric_Y)**2)
error = error.cumsum() | No | 5 | 28 | Model_Train | compute_train_metric | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,287 | fig,ax = plt.subplots()
plt.xlabel('sample')
plt.ylabel('error')
plt.subplot(2, 1, 1)
plt.plot(range(len(error)), error['ConfirmedCases'], "x-",label="ConfirmedCases",color='orange')
plt.legend()
plt.subplot(2, 1, 2)
plt.plot(range(len(error)), error['Fatalities'], "+-", label="Fatalities")
plt.legend()
plt.show()' | No | 5 | 56 | Visualization | plot_predictions | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,288 | from sklearn.metrics import mean_squared_error
rmse = mean_squared_error(train_numeric_Y, train_y_pred , squared=False)
rmse | No | 4 | 49 | Model_Evaluation | compute_test_metric | null | 1 | A | 0 | 0 | 0 | 1 | 0 | 3 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 0 | A |
1,289 | plt.bar(range(len(numeric_features_X)), RF_model.feature_importances_, tick_label=numeric_features_X)
plt.xlabel('feature')
plt.ylabel('weight')
plt.xticks(rotation=90)
plt.show() | No | 5 | 33 | Visualization | distribution | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,290 | import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import os
for dirname, _, filenames in os.walk('/kaggle/input'):
for filename in filenames:
print(os.path.join(dirname, filename))
| No | 5 | 88 | Debug | list_files | null | 1 | A | 0 | 2 | 3 | 0 | 0 | 6 | ok | 1 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path detected: /kaggle/input. Consider using configuration files or environment variables.", "fix": "Not specified", "benefits": "Not specified", "location": "Line 5"}] | A | no applicable ML-specific findings | [] | ["Hardcoded file path"] | 0 | A |
1,291 | DT=1
optimize_model=False
Make_submission=True
n_estimators=200 #400 #500 #1500
max_depth=2 #4 #12 #8 | No | 5 | 59 | Model_Train | init_hyperparams | 8,701,862 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 1 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Magic number detected: 200", "fix": "Not specified", "benefits": "Not specified", "location": "Line 8"}] | A | no applicable ML-specific findings | [] | ["Magic number"] | 4 | A |
1,292 | train=pd.read_csv("/kaggle/input/covid19-global-forecasting-week-2/train.csv")
train.head() | No | 4 | 45 | Data_Extraction | load_from_csv | 8,701,862 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 2 | 2 | [{"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 | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Hardcoded file path"] | 4 | B |
1,293 | train[train['Province_State'].notna()].groupby(['Country_Region'], sort=False)['Province_State'].nunique() | No | 5 | 54 | EDA | count_unique_values | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,294 | def add_location(df_old):
df=df_old.copy()
df['Date']=pd.to_datetime(df['Date'])
df['Country_Region']=df['Country_Region'].fillna('')
df['Province_State']=df['Province_State'].fillna('')
df['location']=df['Province_State'].astype('str')+" "+df['Country_Region'].astype('str')
return df' | No | 3 | 17 | Data_Transform | correct_missing_values | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,295 | train=add_location(train) | 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 |
1,296 | Confirm_pivot=pd.pivot_table(train_df,index='Date',columns='Country_Region',
values='ConfirmedCases',aggfunc=np.sum) | No | 5 | 53 | Other | something_strange | 8,604,602 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 5 | A |
1,297 | plt.figure(figsize=(16,8))
colors=['r','b','g','y','orange','purple','m','hotpink','violet','darkgreen','navy','brown']
for i,country in enumerate(list_countries):
Confirm=Confirm_pivot[Confirm_pivot[country]>0][country].diff().fillna(0)
Confirm=Confirm[Confirm>0]
Confirm.plot(color=colors[i],label=country,... | No | 5 | 33 | Visualization | distribution | 8,604,602 | 1 | A | 0 | 1 | 1 | 0 | 0 | 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"] | 5 | A |
1,298 | plt.figure(figsize=(20,16))
colors=['r','b','g','y','orange','purple','m','hotpink','violet','darkgreen','navy','brown']
for i,country in enumerate(list_countries):
Confirm=Confirm_pivot[Confirm_pivot[country]>0][country].diff().fillna(0)
Confirm=Confirm[Confirm>0]
plt.subplot(4,3,i+1)
Confirm.plot... | No | 5 | 33 | Visualization | distribution | null | 1 | A | 0 | 1 | 1 | 0 | 0 | 11 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,299 | train.set_index('location',inplace=True)
train['day_of_year']=train['Date'].dt.dayofyear
train['day_of_week']=train['Date'].dt.dayofweek
first_day=train[(train['ConfirmedCases']>0)].groupby(['location'], sort=False)['day_of_year'].min()
first_day.rename('first_day',inplace=True) | No | 4 | 60 | Data_Transform | groupby | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,300 | def add_days_passed(df_old,first_day):
df=df_old.copy()
df=pd.concat([df,first_day],axis=1,join='inner')
df['days_passed']=df['day_of_year']-df['first_day']
df.drop(columns=['first_day'],inplace=True)
df['location']=df.index
df.set_index('Id',inplace=True)
df['Id']=df.index
return df
| No | 4 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | 1 | 0 | 0 | 0 | 9 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,301 | train=add_days_passed(train,first_day)
train.head() | 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,302 | country_stat=pd.read_csv('../input/countryinfo/covid19countryinfo.csv')
country_stat = country_stat[country_stat['region'].isnull()]
def add_country_stat(old_df,country_stat):
df=old_df.copy()
df=df.merge(country_stat[['country','pop','medianage','sex65plus','lung','smokers','density']],left_on=['Country_Regi... | Yes | 3 | 45 | Data_Extraction | load_from_csv | null | 1 | A | 3 | 1 | 0 | 0 | 15 | 15 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,303 | country_stat.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,304 | border_info=pd.read_csv("https://raw.githubusercontent.com/geodatasource/country-borders/master/GEODATASOURCE-COUNTRY-BORDERS.CSV")
border_info.drop(columns=["country_code","country_border_code"],inplace=True)
border_info.replace({'United States of America':'US',
'United Kingdom of Great Britain and... | Yes | 2 | 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,305 | from itertools import product as it_product
def expand_grid(data_dict):
rows = it_product(*data_dict.values())
return pd.DataFrame.from_records(rows, columns=data_dict.keys()) | No | 4 | 12 | Data_Transform | create_dataframe | null | 1 | A | 0 | 1 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,306 | skel=expand_grid({'Index':border_info.index,'Date':train['Date'].unique()})
skel.info() | No | 4 | 12 | Data_Transform | create_dataframe | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,307 | country_info=train.groupby(['Date','Country_Region'])['ConfirmedCases'].sum() | No | 5 | 60 | Data_Transform | groupby | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,308 | skel=expand_grid({'Index':border_info.index,'Date':train['Date'].unique()})
skel=skel.merge(border_info, how='inner', left_on=['Index'],right_index=True)
skel=skel.merge(country_info, how='inner',
left_on=['Date','country_border_name'],right_on=['Date','Country_Region']) | No | 4 | 32 | Data_Transform | merge | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,309 | from datetime import timedelta
skel['Date']=skel['Date']+timedelta(days=DT)
border_cases=skel.groupby(['country_name','Date'])['ConfirmedCases'].sum()
len(skel['country_name'].unique()) | No | 3 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,310 | train=train.merge(border_cases, how='left', left_on=['Country_Region','Date'],right_on=['country_name','Date'])
train['ConfirmedCases_y']=train['ConfirmedCases_y'].fillna(0)
train.rename(columns={'ConfirmedCases_y':'ConfirmedCases_neighbors','ConfirmedCases_x':'ConfirmedCases'},inplace=True) | No | 4 | 32 | Data_Transform | merge | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,311 | big_train = pd.concat([train,pd.get_dummies(train['location'], prefix='loc')],axis=1)
big_train['ConfirmedCases_neighbors']=np.log1p(big_train['ConfirmedCases_neighbors'])
big_train.reset_index(inplace=True)
big_train.drop(columns=["Id"],inplace=True)' | No | 3 | 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,312 | big_train.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,313 | def df_add_deltas(df_old):
df=df_old.copy()
df=df.sort_values(by=['location', 'Date'])
df['d_ConfirmedCases'] = df.groupby(['location'])['ConfirmedCases'].diff()
df['d_Fatalities'] = df.groupby(['location'])['Fatalities'].diff()
df.loc[df['d_Fatalities']<0,'d_Fatalities']=0
df.loc[df['d_Confirme... | No | 5 | 8 | Data_Transform | feature_engineering | 8,701,862 | 1 | A | 0 | 1 | 0 | 0 | 0 | 14 | 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 20"}, {"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker"... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "InPlace Checker", "Missing function docstring"] | 4 | A |
1,314 | big_train,first_day_stat=df_add_deltas(big_train) | 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 |
1,315 | big_train.reset_index(inplace=True,drop=True) | No | 5 | 84 | Other | not_enough_vertices | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,316 | X=big_train.drop(columns=['Province_State','Country_Region','Date','ConfirmedCases','Fatalities','location',
'd_ConfirmedCases','d_Fatalities'])
y=big_train['d_ConfirmedCases']
y_2=big_train['d_Fatalities'] | No | 4 | 10 | Data_Transform | drop_column | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,317 | max_day=X['day_of_year'].max()
mask_train=X['day_of_year']<max_day-DT+1
mask_test=X['day_of_year']>=max_day-DT+1 | No | 4 | 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,318 | X_train=X[mask_train]
X_test=X[mask_test]
y_train=y[mask_train]
y_test=y[mask_test]
y_train_2=y_2[mask_train]
y_test_2=y_2[mask_test] | No | 5 | 21 | Data_Transform | prepare_x_and_y | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,319 | X_test['day_of_year'].nunique() | No | 5 | 54 | EDA | count_unique_values | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,320 | X_train.drop(columns=['day_of_year'],inplace=True) #including day of year makes things worse RMLSE goes up from 0.49 to 0.7
X_test.drop(columns=['day_of_year'],inplace=True) #including day of year makes things worse RMLSE goes up from 0.49 to 0.7
X_train.drop(columns=['day_of_week'],inplace=True) #including day of... | No | 5 | 10 | Data_Transform | drop_column | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,321 | X.drop(columns=['index'],inplace=True)
X_train.drop(columns=['index'],inplace=True)
X_test.drop(columns=['index'],inplace=True) | 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,322 | # Best: -0.252369 using {'max_depth': 6, 'n_estimators': 1500}
# Best: -1.051575 using {'max_depth': 6, 'n_estimators': 500} - predict shifts log
# Best: -278.598983 using {'max_depth': 10, 'n_estimators': 500} - predict values
# Best: -1.111758 using {'max_depth': 6, 'n_estimators': 500} - predict shifts log, knowi... | No | 3 | 6 | Hyperparam_Tuning | train_on_grid | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
1,323 | # Best: -0.211438 using {'max_depth': 5, 'n_estimators': 2500}
# Best: -0.974302 using {'max_depth': 5, 'n_estimators': 400} - predict shifts log
# Best: -274.964946 using {'max_depth': 12, 'n_estimators': 500}
# Best: -1.064197 using {'max_depth': 5, 'n_estimators': 400}
if optimize_model:
model = xgb.XGBRegr... | Yes | 3 | 6 | Hyperparam_Tuning | train_on_grid | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,324 | #Best: -0.211107 using {'max_depth': 5, 'n_estimators': 3000}
#Best: -0.940498 using {'max_depth': 4, 'n_estimators': 400}
#Best: -274.964946 using {'max_depth': 12, 'n_estimators': 500}
#Best: -0.861262 using {'max_depth': 2, 'n_estimators': 200}
if optimize_model:
model = xgb.XGBRegressor(random_state=42)
... | Yes | 3 | 6 | Hyperparam_Tuning | train_on_grid | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,325 | reg.fit(X_train,np.log1p(y_train)) | No | 5 | 7 | Model_Train | train_model | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,326 | y_pred = reg.predict(X_test) | No | 5 | 48 | Model_Evaluation | predict_on_test | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,327 | from sklearn.metrics import mean_squared_error
np.sqrt(mean_squared_error(y_pred,np.log1p(y_test))) | No | 5 | 49 | Model_Evaluation | compute_test_metric | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 0 | A |
1,328 | X_train_2=X_train.copy()
X_train_2['d_confirmed']=y_train #0.4412899060661785 <- without , with - 0.4463
X_test_2=X_test.copy()
X_test_2['d_confirmed']=y_pred | No | 4 | 49 | Model_Evaluation | compute_test_metric | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,329 | reg_2.fit(X_train_2,np.log1p(y_train_2)) | No | 5 | 7 | Model_Train | train_model | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,330 | y_pred_2 = reg_2.predict(X_test_2) | No | 5 | 48 | Model_Evaluation | predict_on_test | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,331 | np.sqrt(mean_squared_error(y_pred_2,np.log1p(y_test_2))) | 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 |
1,332 | test=pd.read_csv("/kaggle/input/covid19-global-forecasting-week-2/test.csv")
test.rename(columns={'ForecastId':'Id'},inplace=True)
test=add_location(test)
test.set_index('location',inplace=True)
test['day_of_year']=test['Date'].dt.dayofyear
test['day_of_week']=test['Date'].dt.dayofweek
test=add_days_passed(test,first... | Yes | 2 | 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,333 | big_train=big_train.drop(columns=["index"])
| No | 5 | 10 | Data_Transform | drop_column | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,334 | known=big_train['Date'].unique()
print(known) | No | 5 | 57 | Debug | show_unique_values | 8,701,862 | 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"] | 4 | B |
1,335 | if Make_submission==True:
results=[]
for d in days_to_predict:
print("Predicting {}".format(d))
if d in known:
print("Data Known")
X=big_train.drop(columns=['Province_State','Country_Region','ConfirmedCases','Fatalities','location','Date',
... | Yes | 2 | 21 | Data_Transform | prepare_x_and_y | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,336 | if Make_submission==True:
submission=pd.read_csv("../input/covid19-global-forecasting-week-2/submission.csv")
submission.drop(columns=['ConfirmedCases','Fatalities'],inplace=True)
submission=submission.merge(pd.concat(results),left_on=['ForecastId'],right_index=True).clip(lower=0)
submission.to_csv('sub... | Yes | 3 | 25 | Data_Export | save_to_csv | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,337 | # KAGGLE competition >> Prediction of confirmed cases
# This script trains the model on the latest dataset and predicts the next value
# Author: Neilay Khasnabish
# Import libraries
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeRegres... | Yes | 1 | 7 | Model_Train | train_model | null | 1 | A | 36 | 11 | 12 | 0 | 123 | 101 | ok | 16 | 7 | [{"detector": "framework_specific", "framework": "NumPy", "name": "Missing Axis Specification", "fix": "Specify axis in array operations.", "benefits": "Improves performance and avoids unexpected behaviour.", "location": "Line 57"}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Verbose Mode Ch... | C | Missing Axis Specification=medium | [{"type": "Missing Axis Specification", "severity": "medium"}] | ["Exception Handling Checker", "Hardcoded file path", "Magic number", "Missing function docstring", "Unit Testing Checker", "Verbose Mode Checker"] | 0 | C |
1,338 | # KAGGLE competition >> Fatality rate
# This script trains the model on the latest dataset and predicts the next value
# Author: Neilay Khasnabish
# Import libraries
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeRegressor
from sklearn... | Yes | 1 | 7 | Model_Train | train_model | null | 1 | A | 36 | 11 | 12 | 0 | 123 | 99 | ok | 16 | 7 | [{"detector": "framework_specific", "framework": "NumPy", "name": "Missing Axis Specification", "fix": "Specify axis in array operations.", "benefits": "Improves performance and avoids unexpected behaviour.", "location": "Line 56"}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Verbose Mode Ch... | C | Missing Axis Specification=medium | [{"type": "Missing Axis Specification", "severity": "medium"}] | ["Exception Handling Checker", "Hardcoded file path", "Magic number", "Missing function docstring", "Unit Testing Checker", "Verbose Mode Checker"] | 0 | C |
1,339 | # Creating the submission
predictions_dF['Fatalities'] = fatality_dF['Fatalities']
predictions_dF[['ForecastId', 'ConfirmedCases', 'Fatalities']].to_csv('submission.csv', index=False)
print(predictions_dF[['ForecastId', 'ConfirmedCases', 'Fatalities']].head(10))
print(predictions_dF[['ForecastId', 'ConfirmedCases', 'Fa... | No | 4 | 25 | Data_Export | save_to_csv | 8,702,904 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 6 | 4 | [{"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... | B | No random seed setting detected=low | [{"type": "No random seed setting detected", "severity": "low"}] | ["Exception Handling Checker", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker"] | 6 | B |
1,340 | b"# import necessary modules\nimport numpy as np \nimport pandas as pd \nimport matplotlib.pyplot as plt\nimport os\nimport warnings\nfrom datetime import datetime\nfrom scipy import stats\nfrom scipy.stats import norm, skew, probplot \n\nwarnings.filterwarnings('ignore')\ndaybasecount = 4 #antal dage ... | No | 4 | 77 | Other | define_variables | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,341 | #print(os.listdir("../kaggle-Covid19/covid19-global-forecasting-week-2"))
dftrain = pd.read_csv('../input/covid19-global-forecasting-week-3/train.csv', parse_dates=['Date']).sort_values(by=['Country_Region', 'Date'])
dftest = pd.read_csv('../input/covid19-global-forecasting-week-3/test.csv', parse_dates=['Date']).so... | No | 4 | 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,342 | dftrain['Dayofyear'] = dftrain['Date'].dt.dayofyear
dftest['Dayofyear'] = dftest['Date'].dt.dayofyear
dftest['Expo'] = dftest['Dayofyear']-baseday
print(dftrain.tail(5))
dftest = dftest.merge(dftrain[['Country_Region','Province_State','Date','ConfirmedCases','Fatalities']]
, on=['Country_Region','... | No | 4 | 32 | Data_Transform | merge | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,343 | #dftrain = dftrain.loc[dftrain['Country_Region'] == 'Denmark']
dftrain['Province_State'].fillna(dftrain['Country_Region'], inplace=True)
dftest ['Province_State_orig'] = dftest ['Province_State']
dftest ['Province_State'].fillna(dftest['Country_Region'], inplace=True)
dftrain.sort_values(by =['Country_Region', 'Provi... | Yes | 2 | 60 | Data_Transform | groupby | null | 1 | A | 1 | 0 | 0 | 0 | 5 | 25 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,344 | b"#find gennemsnit af forrige 4(=daybasecount) dage\ngrouped=dftrain.groupby(['Country_Region','Province_State']).tail(daybasecount*2)\ngrouped=grouped.groupby(['Country_Region','Province_State']).head(daybasecount)\ngrouped.drop(['FatalityBasis'],axis=1,inplace=True)\n\nto_sum = ['NewCases','NewFatalities']\ngrouped1 ... | Yes | 2 | 14 | Data_Transform | filter | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,345 | dftest.drop('_merge',axis=1,inplace= True)
dftest = dftest.merge(grouped[['Country_Region','FatalityPct2','Factor']], on=['Country_Region'], how='left')
dftest = dftest.merge(grouped_gem[['Province_State','Country_Region','ConfirmedCases_base','ConfirmedCases_init','NewCases_base','Fatalities_init','FatalityBasis']], o... | No | 4 | 32 | Data_Transform | merge | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,346 | dftest['ConfirmedCases_shift'] = dftest.groupby(['Country_Region', 'Province_State'])[['ConfirmedCases']].transform(lambda x: x.shift(1))
mask = dftest['ConfirmedCases'].isnull()
# find new cases
dftest.loc[mask,'NewCases'] = dftest.loc[mask,'NewCases_base']*(dftest.loc[mask,'Factor']**dftest.loc[mask,'Expo'])
#dfte... | Yes | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.