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,347 | # Forbered aflevering
dftest.drop(['Dayofyear',
'Expo','FatalityPct2', 'Factor',
'ConfirmedCases_base', 'ConfirmedCases_init',
'NewCases_base', 'Fatalities_init', 'FatalityBasis',
'ConfirmedCases_shift',
'NewCases', 'NewCases_cum', 'NewFatalities','NewFatalities_cum'],axis=1,inplace=... | No | 4 | 10 | Data_Transform | drop_column | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 9 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,348 | mask = dftest["ConfirmedCases"].isnull()
print(mask.sum())
errors = dftest.loc[mask]
print(errors)
mask = dftest["Fatalities"].isnull()
print(mask.sum())
errors = dftest.loc[mask]
print(errors)
dftest.drop(['Province_State','Country_Region','Date'],axis=1,inplace=True)
print("dftest columns =",dftest.columns)
' | Yes | 4 | 39 | EDA | count_missing_values | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,349 | #print(dftest[dftest['Country_Region']=='Burma'])
dftest.ForecastId = dftest.ForecastId.astype('int')
dftest['ConfirmedCases'] = dftest['ConfirmedCases'].round().astype(int)
dftest['Fatalities'] = dftest['Fatalities'].round().astype(int)
dftest.to_csv('submission.csv', index=False)
| Yes | 4 | 25 | Data_Export | save_to_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,350 | import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn import preprocessing
import time
from datetime import datetime
from scipy import integrate, optimize
import warnings
warnings.filterwarnings('ignore')
# ML libraries
import lightgbm as lgb
import xgboost as xgb
... | No | 5 | 23 | Environment | set_options | 8,711,165 | 1 | A | 0 | 0 | 0 | 0 | 0 | 17 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 7 | A |
1,351 | submission_example = pd.read_csv("../input/covid19-global-forecasting-week-2/submission.csv")
test = pd.read_csv("../input/covid19-global-forecasting-week-2/test.csv")
train = pd.read_csv("../input/covid19-global-forecasting-week-2/train.csv")
display(train.head(5))
display(train.describe())
print("Number of Country_Re... | 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,352 | # Merge train and test, exclude overlap
dates_overlap = ['2020-03-19','2020-03-20','2020-03-21','2020-03-22','2020-03-23', '2020-03-24', '2020-03-25',
'2020-03-26', '2020-03-27', '2020-03-28', '2020-03-29', '2020-03-30', '2020-03-31']
train2 = train.loc[~train['Date'].isin(dates_overlap)]
all_data = p... | 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 |
1,353 | missings_count = {col:all_data[col].isnull().sum() for col in all_data.columns}
missings = pd.DataFrame.from_dict(missings_count, orient='index')
print(missings.nlargest(30, 0)) | No | 5 | 39 | EDA | count_missing_values | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,354 | def calculate_trend(df, lag_list, column):
for lag in lag_list:
trend_column_lag = "Trend_" + column + "_" + str(lag)
df[trend_column_lag] = (df[column]-df[column].shift(lag, fill_value=-999))/df[column].shift(lag, fill_value=0)
return df
def calculate_lag(df, lag_list, column):
for lag in... | 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,355 | all_data[all_data['Country_Region']=='Spain'].iloc[40:50][['Id', 'Province_State', 'Country_Region', 'Date',
'ConfirmedCases', 'Fatalities', 'ForecastId', 'Day_num', 'ConfirmedCases_1',
'ConfirmedCases_2', 'ConfirmedCases_3', 'Fatalities_1', 'Fatalities_2',
'Fatalities_3']] | No | 5 | 14 | Data_Transform | filter | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,356 | # Load countries data file
world_population = pd.read_csv("/kaggle/input/population-by-country-2020/population_by_country_2020.csv")
# Select desired columns and rename some of them
world_population = world_population[['Country (or dependency)', 'Population (2020)', 'Density (P/Km)', 'Land Area (Km)', 'Med. Age', 'Urb... | Yes | 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,357 | # Filter selected features
data = all_data.copy()
features = ['Id', 'ForecastId', 'Country_Region', 'Province_State', 'ConfirmedCases', 'Fatalities',
'Day_num']
data = data[features]
# Apply log transformation to all ConfirmedCases and Fatalities columns, except for trends
data[['ConfirmedCases', 'Fatalities']... | 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,358 | # Select train (real) data from March 1 to March 22nd
dates_list = ['2020-03-01', '2020-03-02', '2020-03-03', '2020-03-04', '2020-03-05', '2020-03-06', '2020-03-07', '2020-03-08', '2020-03-09',
'2020-03-10', '2020-03-11','2020-03-12','2020-03-13','2020-03-14','2020-03-15','2020-03-16','2020-03-17','20... | No | 4 | 14 | Data_Transform | filter | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,359 | all_data.loc[all_data['Country_Region']==country_dict['Spain']][40:65] | 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 |
1,360 | def plot_rreg_basic_country(data, country_name, dates_list, day_start, shift):
data_country = data[data['Country_Region']==country_dict[country_name]]
data_country = data_country.loc[data_country['Day_num']>=day_start]
X_train, Y_train_1, Y_train_2, X_test = split_data(data_country)
model, pred = r... | Yes | 3 | 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,361 | # Filter Spain, run the Linear Regression workflow
country_name = "Spain"
march_day = 15
day_start = 39+march_day
dates_list2 = dates_list[march_day:]
plot_rreg_basic_country(data, country_name, dates_list2, day_start, march_day) | No | 4 | 56 | Visualization | plot_predictions | 8,711,165 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | 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": "Magic number detected... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Magic number"] | 7 | A |
1,362 | # Filter Italy, run the Linear Regression workflow
country_name = "Italy"
march_day = 0
day_start = 39+march_day
dates_list2 = dates_list[march_day:]
plot_rreg_basic_country(data, country_name, dates_list2, day_start, march_day) | No | 5 | 33 | Visualization | distribution | 8,711,165 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | 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,363 | # Filter Italy, run the Linear Regression workflow
country_name = "Italy"
march_day = 15
day_start = 39+march_day
dates_list2 = dates_list[march_day:]
plot_rreg_basic_country(data, country_name, dates_list2, day_start, march_day) | No | 2 | 56 | Visualization | plot_predictions | 8,711,165 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | 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": "Magic number detected... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Magic number"] | 7 | A |
1,364 | # Filter Germany, run the Linear Regression workflow
country_name = "Germany"
march_day = 0
day_start = 39+march_day
dates_list2 = dates_list[march_day:]
plot_rreg_basic_country(data, country_name, dates_list2, day_start, march_day) | No | 5 | 56 | Visualization | plot_predictions | 8,711,165 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | 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,365 | # Filter Germany, run the Linear Regression workflow
country_name = "Germany"
march_day = 15
day_start = 39+march_day
dates_list2 = dates_list[march_day:]
plot_rreg_basic_country(data, country_name, dates_list2, day_start, march_day) | No | 5 | 33 | Visualization | distribution | 8,711,165 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | 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": "Magic number detected... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Magic number"] | 7 | A |
1,366 | # Filter Albania, run the Linear Regression workflow
country_name = "Albania"
march_day = 0
day_start = 39+march_day
dates_list2 = dates_list[march_day:]
plot_rreg_basic_country(data, country_name, dates_list2, day_start, march_day) | No | 5 | 33 | Visualization | distribution | 8,711,165 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | 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,367 | # Filter Albania, run the Linear Regression workflow
country_name = "Albania"
march_day = 15
day_start = 39+march_day
dates_list2 = dates_list[march_day:]
plot_rreg_basic_country(data, country_name, dates_list2, day_start, march_day) | No | 5 | 56 | Visualization | plot_predictions | 8,711,165 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | 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": "Magic number detected... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Magic number"] | 7 | A |
1,368 | # Filter Andorra, run the Linear Regression workflow
country_name = "Andorra"
shift = 0
day_start = 39+shift
dates_list2 = dates_list[shift:]
plot_rreg_basic_country(data, country_name, dates_list2, day_start, shift) | No | 5 | 33 | Visualization | distribution | 8,711,165 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | 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,369 | # Filter Andorra, run the Linear Regression workflow
country_name = "Andorra"
shift = 7
day_start = 39+shift
dates_list2 = dates_list[shift:]
plot_rreg_basic_country(data, country_name, dates_list2, day_start, shift) | No | 5 | 33 | Visualization | distribution | 8,711,165 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | 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": "Magic number detected... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Magic number"] | 7 | A |
1,370 | ts = time.time()
def ridge_reg_basic_all_countries(data, day_start):
data2 = data.loc[data.Day_num >= day_start]
# Set the dataframe where we will update the predictions
data_pred = data[data.ForecastId != -1][['Country_Region', 'Province_State', 'Day_num', 'ForecastId']]
data_pred = data_pred.lo... | Yes | 3 | 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 |
1,371 | import numpy as np
import pandas as pd
import os
sub = pd.read_csv("../input/submissions/submission.csv")
sub.to_csv("submission.csv", index=False) | No | 3 | 45 | Data_Extraction | load_from_csv | 9,326,374 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 1 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path detected: ../input/submissions/submission.csv. Consider using configuration files or environment variables.", "fix": "Not specified", "benefits": "Not specified", "location": "Line 7"}] | A | no applicable ML-specific findings | [] | ["Hardcoded file path"] | 2 | A |
1,372 | import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
Predictions = pd.read_csv('../input/covid-predictions/COVID_predictions.csv')
Predictions.to_csv('submission.csv',index=False) | No | 4 | 25 | Data_Export | save_to_csv | 9,349,764 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 1 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path detected: ../input/covid-predictions/COVID_predictions.csv. Consider using configuration files or environment variables.", "fix": "Not specified", "benefits": "Not specified", "location": "Line 4"}] | A | no applicable ML-specific findings | [] | ["Hardcoded file path"] | 2 | A |
1,373 | # This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.... | No | 4 | 88 | Debug | list_files | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
1,374 | # Data Handling
import pandas as pd
import numpy as np
import math
import scipy.stats as sps
#from scipy import stats, integrate
from time import time
# sklearn and models
from sklearn import preprocessing, ensemble, metrics, feature_selection, model_selection, pipeline
import xgboost as xgb
#plotting and display
fr... | No | 5 | 22 | Environment | import_modules | 171,635 | 1 | A | 1 | 0 | 0 | 0 | 5 | 9 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,375 | # create date parser
dateparse = lambda x: pd.datetime.strptime(x, '%Y-%m-%d')
# create data type converters
dtype_map_weather = dict(Station = 'str')
dtype_map_test_train = dict(Block = 'str', Street = 'str')
# read data into PANDAS DataFrames with date parsing
test = pd.read_csv('../input/test.csv', parse_dates=['D... | No | 4 | 45 | Data_Extraction | load_from_csv | 171,635 | 1 | A | 2 | 0 | 0 | 0 | 10 | 7 | ok | 5 | 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."] | 3 | A |
1,376 | print('Train')
display(train.info())
print('Test')
display(test.info()) | No | 5 | 40 | Debug | show_table_attributes | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | 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,377 | print('Weather')
display(weather.info()) | No | 5 | 40 | Debug | show_table_attributes | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,378 | # weather
weather_exclude = ['Dewpoint', 'WetBulb', 'CodeSum', 'Depth', 'Water1', 'SnowFall', 'StnPressure',
'SeaLevel', 'ResultSpeed', 'ResultDir', 'AvgSpeed','DewPoint']
weather_cols = [col for col in weather.columns if col not in weather_exclude]
weather = weather[weather_cols]
# train
train_exclu... | No | 4 | 10 | Data_Transform | drop_column | 171,635 | 1 | A | 0 | 3 | 0 | 0 | 0 | 10 | 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,379 | weather.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,380 | print('Weather')
display(weather.head())
print('Train')
display(train.head()) | No | 5 | 41 | Debug | show_table | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | 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,381 | # what species have been detected (note that according to the CDC each
# of these species can carry WNV)
set(train.Species) | No | 5 | 57 | Debug | show_unique_values | 171,635 | 1 | A | 0 | 0 | 0 | 1 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,382 | # does this correspond to the test set
set(test.Species)
# it looks like there is another category | No | 5 | 57 | Debug | show_unique_values | 171,635 | 1 | A | 0 | 0 | 0 | 1 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,383 | train.groupby('Species').sum().WnvPresent | No | 5 | 60 | Data_Transform | groupby | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | 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, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}] | [] | 3 | B |
1,384 | miss_weather = ['M', '-']
trace_weather = ['T'] | No | 4 | 10 | Data_Transform | drop_column | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,385 | cols_not_date = [col for col in weather.columns if col != 'Date'] | No | 5 | 14 | Data_Transform | filter | 171,635 | 1 | A | 0 | 1 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,386 | weather[cols_not_date].apply(pd.value_counts, axis=1)[miss_weather + trace_weather].fillna(0).sum() | No | 5 | 17 | Data_Transform | correct_missing_values | 171,635 | 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,387 | # Both stations
check.loc[['M', '-', 'T']]/(len(weather)) * 100 | No | 4 | 41 | Debug | show_table | 171,635 | 1 | A | 0 | 0 | 0 | 1 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,388 | # Station 1
check_stat1.loc[['M', '-', 'T']]/(len(weather)) * 100 | No | 4 | 41 | Debug | show_table | 171,635 | 1 | A | 0 | 0 | 0 | 1 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,389 | # Station 2()
check_stat2.loc[['M', '-', 'T']]/(len(weather)) * 100 | No | 4 | 41 | Debug | show_table | 171,635 | 1 | A | 0 | 0 | 0 | 1 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,390 | weather = weather.replace('M', np.NaN)
weather = weather.replace('-', np.NaN)
weather = weather.replace('T', 0.005) # very small amounts of rain can impact mosquito hatches
weather.Tmax = weather.Tmax.fillna(method = 'ffill')
weather.Tmin = weather.Tmin.fillna(method = 'ffill')
weather.Depart = weather.Depart.fillna(me... | No | 4 | 17 | Data_Transform | correct_missing_values | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 9 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,391 | # convert datatpypes
to_numeric = ['Tmax','Tmin','Tavg', 'Depart', 'Heat', 'Cool', 'PrecipTotal']
for col in to_numeric:
weather[col]= pd.to_numeric(weather[col]) | No | 5 | 16 | Data_Transform | data_type_conversions | 171,635 | 1 | A | 0 | 1 | 1 | 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"] | 3 | A |
1,392 | weather.Sunrise = weather.Sunrise.fillna(method = 'ffill')
weather.Sunset = weather.Sunset.fillna(method = 'ffill') | No | 5 | 17 | Data_Transform | correct_missing_values | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,393 | # sunset has entries where instead of incrementing to the next hour after xx59 it incremented to xx60
# This causes an exception, let's take a look
counter = 0
tracker = []
for index, val in enumerate(weather.Sunset):
try:
pd.to_datetime(val, format = '%H%M').time()
except:
counter += 1
... | No | 4 | 16 | Data_Transform | data_type_conversions | 171,635 | 1 | A | 1 | 1 | 3 | 0 | 5 | 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 |
1,394 | # time conversion lambda function
time_func = lambda x: pd.Timestamp(pd.to_datetime(x, format = '%H%M')) | No | 5 | 16 | Data_Transform | data_type_conversions | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,395 | weather.Sunrise = weather.Sunrise.apply(time_func) | No | 5 | 8 | Data_Transform | feature_engineering | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,396 | weather.Sunset = weather.Sunset.apply(time_func) | No | 5 | 8 | Data_Transform | feature_engineering | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,397 | # what is the range of values for sunrise and sunset (in hours)
minutes= (weather.Sunset - weather.Sunrise).astype('timedelta64[m]') | No | 5 | 16 | Data_Transform | data_type_conversions | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,398 | #create a DayLength column with minute level precsion
weather['DayLength_MPrec'] = (weather.Sunset - weather.Sunrise).astype('timedelta64[m]')/60 | No | 5 | 16 | Data_Transform | data_type_conversions | 171,635 | 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,399 | #create a DayLength column with rounded to the nearest hour
weather['DayLength_NearH'] = np.round(((weather.Sunset - weather.Sunrise).astype('timedelta64[m]')/60).values) | No | 5 | 8 | Data_Transform | feature_engineering | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 2 | 2 | [{"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 5"}, {"detector": "framework_specific", "framework": "Pandas", "name": "Column S... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "DataFrame Conversion Checker"] | 3 | A |
1,400 | # length of night with minute level precision
weather['NightLength_MPrec']= 24.0 - weather.DayLength_MPrec | No | 5 | 8 | Data_Transform | feature_engineering | 171,635 | 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,401 | # lenght of night rounded to nearest hour
weather['NightLength_NearH']= 24.0 - weather.DayLength_NearH | No | 5 | 8 | Data_Transform | feature_engineering | 171,635 | 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,402 | # function to calculate sunset and sunrise times in hours
hours_RiseSet_func = lambda x: x.minute/60.0 + float(x.hour) | No | 5 | 84 | Other | not_enough_vertices | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,403 | # sunrise in hours
weather['Sunrise_hours'] = weather.Sunrise.apply(hours_RiseSet_func) | No | 5 | 8 | Data_Transform | feature_engineering | 171,635 | 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,404 | # sunset in hours
weather['Sunset_hours'] = weather.Sunset.apply(hours_RiseSet_func) | No | 5 | 8 | Data_Transform | feature_engineering | 171,635 | 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,405 | station_blend = pd.DataFrame((station_1.values + station_2.values)/2, columns= blended_cols) | No | 5 | 12 | Data_Transform | create_dataframe | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,406 | extract_2 = weather[weather.Station == '2'].reset_index(drop = True)
extract_2.head() | No | 4 | 14 | Data_Transform | filter | 171,635 | 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 |
1,407 | extract_1 = weather[weather.Station == '1'].reset_index(drop = True)
extract_1.head() | No | 5 | 14 | Data_Transform | filter | 171,635 | 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 |
1,408 | joined_1 = extract_1.join(station_blend)
joined_2 = extract_2.join(station_blend) | No | 5 | 32 | Data_Transform | merge | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,409 | weather_blend = pd.concat([joined_1, joined_2]) | No | 5 | 11 | Data_Transform | concatenate | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,410 | weather_blend.info() | No | 5 | 40 | Debug | show_table_attributes | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,411 | month_func = lambda x: x.month
day_func= lambda x: x.day
day_of_year_func = lambda x: x.dayofyear
week_of_year_func = lambda x: x.week
# train
train['month'] = train.Date.apply(month_func)
train['day'] = train.Date.apply(day_func)
train['day_of_year'] = train.Date.apply(day_of_year_func)
train['week'] = train.Date.app... | No | 4 | 8 | Data_Transform | feature_engineering | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 12 | ok | 3 | 3 | [{"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, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}] | ["Column Selection Checker"] | 3 | B |
1,412 | # remove sunrise and sunset since we have extracted critical information into other fields
weather_blend = weather_blend.drop(['Sunrise', 'Sunset'], axis= 1) | No | 5 | 10 | Data_Transform | drop_column | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,413 | train = train.merge(weather_blend, on='Date')
test = test.merge(weather_blend, on='Date') | No | 5 | 32 | Data_Transform | merge | 171,635 | 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"}] | [] | 3 | B |
1,414 | weather_blend.ix[:,:12].describe() | No | 4 | 40 | Debug | show_table_attributes | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,415 | weather_blend.ix[:,12:].describe() | No | 4 | 40 | Debug | show_table_attributes | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,416 | # split the data into two dataframes by station
train_station_1= train[train.Station == '1']
train_station_2= train[train.Station == '2']
test_station_1= test[test.Station == '1']
test_station_2= test[test.Station == '2'] | No | 5 | 14 | Data_Transform | filter | 171,635 | 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"] | 3 | A |
1,417 | # set up a merge for stations 1 and 2
# keep unique cols from station 2
keep_cols = ['Date', u'Tmax', u'Tmin', u'Tavg',u'PrecipTotal']
train_station_2 = train_station_2[keep_cols]
test_station_2 = test_station_2[keep_cols]
# rename cols with prefix
prefix_s2 = 'stat_2_'
rename_cols_s2 = [prefix_s2 + col for col in tra... | No | 3 | 61 | Data_Transform | rename_columns | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 7 | 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,418 | # drop cols from station 1 that won't be used in model
drop_cols = ['Heat', 'Cool', 'Depart', 'NightLength_MPrec', 'NightLength_NearH',
'blended_Depart', 'blended_Heat', 'blended_Cool']
train_station_1 = train_station_1.drop(drop_cols, axis= 1)
test_station_1 = test_station_1.drop(drop_cols, axis= 1) | No | 5 | 10 | Data_Transform | drop_column | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | 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,419 | # raname uniqe station 1 columns
prefix_s1 = 'stat_1_'
rename_cols_s1 = [prefix_s1 + col for col in keep_cols]
cols_to_rename= [col for col in train_station_1.columns if col in keep_cols]
# setup name mapping
s1_name_map = dict(zip(cols_to_rename, rename_cols_s1))
train_station_1 = train_station_1.rename(columns= s1_... | No | 4 | 61 | Data_Transform | rename_columns | 171,635 | 1 | A | 0 | 1 | 0 | 0 | 0 | 6 | 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,420 | # concat (outer join)
train_station_1 = train_station_1.reset_index(drop= True)
train_station_2 = train_station_2.reset_index(drop = True)
train_merge = pd.concat([train_station_1, train_station_2], axis= 1)
test_station_1 = test_station_1.reset_index(drop= True)
test_station_2 = test_station_2.reset_index(drop = Tr... | No | 4 | 11 | Data_Transform | concatenate | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | 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, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}] | [] | 3 | B |
1,421 | # remove dates
train_merge = train_merge.drop(['stat_1_Date', 'stat_2_Date'], axis = 1)
test_merge = test_merge.drop(['stat_1_Date', 'stat_2_Date' ], axis = 1) | No | 5 | 10 | Data_Transform | drop_column | 171,635 | 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"}] | [] | 3 | B |
1,422 | # add lat and long integer columns
train_merge['Lat_int'] = train_merge.Latitude.astype(int)
train_merge['Long_int'] = train_merge.Longitude.astype(int)
test_merge['Lat_int'] = test_merge.Latitude.astype(int)
test_merge['Long_int'] = test_merge.Longitude.astype(int) | No | 5 | 16 | Data_Transform | data_type_conversions | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 3 | 3 | [{"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, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}] | ["Column Selection Checker"] | 3 | B |
1,423 | #train_merge= train_merge.drop(['Street', 'Trap', 'Station'], axis= 1)
#test_merge= test_merge.drop(['Street', 'Trap', 'Station'], axis= 1)
train_merge= train_merge.drop('Station', axis= 1)
test_merge= test_merge.drop('Station', axis= 1) | No | 5 | 10 | Data_Transform | drop_column | 171,635 | 2 | B | 1 | 0 | 0 | 0 | 5 | 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"}] | [] | 3 | B |
1,424 | len(train_merge.columns) | No | 5 | 40 | Debug | show_table_attributes | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,425 | len(test_merge.columns) | No | 5 | 40 | Debug | show_table_attributes | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,426 | test_merge= test_merge.drop(unique_test_cols, axis= 1) | No | 5 | 10 | Data_Transform | drop_column | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,427 | clf = ensemble.RandomForestClassifier(n_estimators=1000, min_samples_split= 2, random_state= 42)
clf.fit(train_merge, labels) | No | 5 | 7 | Model_Train | train_model | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 5 | 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"] | 3 | B |
1,428 | # create predictions and submission file
predictions_randfor = clf.predict_proba(test_merge)[:,1] | No | 5 | 48 | Model_Evaluation | predict_on_test | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 3 | 3 | [{"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", "Exception Handling Checker", "Unit Testing Checker"] | 3 | A |
1,429 | # fit model no training data
xgbc = xgb.XGBClassifier(seed= 42)
xgbc.fit(train_merge, labels)
# feature importance
#print(xgb.feature_importances_)
# plot feature importance
fig, ax = pyplot.subplots(figsize=(10, 15))
xgb.plot_importance(xgbc, ax=ax)
#pyplot.show() | No | 4 | 7 | Model_Train | train_model | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | 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"] | 3 | B |
1,430 | xgbc.get_fscore() | No | 5 | 79 | Visualization | model_coefficients | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | 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"] | 3 | A |
1,431 | # feature importance
xgbc.get_fscore()
#print(xgbc.feature_importances_) | No | 5 | 84 | Other | not_enough_vertices | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | 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"] | 3 | A |
1,432 | def calc_roc_auc(y, predict_probs):
"""
Function accepts labels (matrix y) and predicted probabilities
Function calculates fpr (false positive rate), tpr (true postivies rate), thresholds and auc (area under
the roc curve)
Function returns auc
"""
fpr, tpr, thresholds = metrics.roc_curv... | No | 5 | 84 | Other | not_enough_vertices | 171,635 | 1 | A | 1 | 1 | 0 | 0 | 5 | 4 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,433 | train_split, val_split, label_train_split, label_val_split = model_selection.train_test_split(train_merge,
labels, test_size = 0.33, random_state = 42, stratify= labels) | No | 5 | 13 | Data_Transform | split | 171,635 | 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"}] | [] | 3 | B |
1,434 | train_merge.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,435 | # initialize and fit model
xgb_clf= xgb.XGBClassifier(seed= 42)
xgb_clf.fit(sfm_train, labels) | No | 4 | 7 | Model_Train | train_model | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | 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"] | 3 | B |
1,436 | sfm_test = sfm.transform(test_merge)
predictions_xgb = xgb_clf.predict_proba(sfm_test)[:,1] | No | 4 | 48 | Model_Evaluation | predict_on_test | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 6 | 5 | [{"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":... | B | No random seed setting detected=low | [{"type": "No random seed setting detected", "severity": "low"}] | ["Dependent Threshold Checker", "Exception Handling Checker", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker"] | 3 | B |
1,437 | X_train= train_split
X_test= val_split
y_train= label_train_split
y_test= label_val_split
model= xgb.XGBClassifier(seed= 42)
eval_set = [(X_train, y_train), (X_test, y_test)]
model.fit(X_train, y_train, eval_metric="auc", eval_set=eval_set, verbose=True) | Yes | 3 | 7 | Model_Train | train_model | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 7 | 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": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Exception Handling Checker", "Unit Testing Checker"] | 3 | B |
1,438 | results = model.evals_result()
print(results) | No | 5 | 28 | Model_Train | compute_train_metric | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
1,439 | model.fit(X_train, y_train, eval_metric=["auc", "logloss", "error"], eval_set=eval_set)
# retrieve performance metrics
results = model.evals_result()
epochs = len(results['validation_0']['auc'])
x_axis = range(0, epochs)
# plot auc
fig, ax = pyplot.subplots()
ax.plot(x_axis, results['validation_0']['auc'], label='Trai... | No | 4 | 35 | Visualization | learning_history | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,440 | eval_set = [(X_test, y_test)]
model.fit(X_train, y_train, eval_metric=["auc"], eval_set=eval_set, early_stopping_rounds=10)
results = model.evals_result()
print(results) | Yes | 3 | 7 | Model_Train | train_model | 171,635 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | 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"] | 3 | B |
1,441 | # Utility function to report best scores
def report(results, n_top=3):
for i in range(1, n_top + 1):
candidates = np.flatnonzero(results['rank_test_score'] == i)
for candidate in candidates:
print("Model with rank: {0}".format(i))
print("Mean validation score: {0:.3f} (std: {... | No | 4 | 1 | Hyperparam_Tuning | find_best_score | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
1,442 | #n_estimators_dist= np.random.randint(1, 500)# number of trees, could use a discrete list or np.random.exponential(scale=0.1, size= 100)
#colsample_bytree_dist= np.random.uniform(0.2,0.6) # should be 0.3 - 0.5
#max_depth_dist = np.random.randint(2, 12) # typical values 3 - 10
#learning_rate_dist= np.random.uniform(0.01... | No | 5 | 5 | Hyperparam_Tuning | define_search_space | 171,635 | 3 | C | 2 | 0 | 0 | 0 | 10 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | C |
1,443 | #cv = model_selection.StratifiedShuffleSplit(n_splits = 10, random_state = 42)
param_dist = dict(learning_rate= learning_rate_dist, n_estimators= n_estimators_dist)
# run randomized search
n_iter_search = 20
random_search = model_selection.RandomizedSearchCV(model, param_distributions=param_dist,
... | 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,444 | sample_sub['WnvPresent'] = predictions_xgb
sample_sub.to_csv('sub_xgb.csv', index=False)
#sample_sub['WnvPresent'] = predictions_randfor
#sample_sub.to_csv('sub_randfor.csv', index=False) | No | 4 | 25 | Data_Export | save_to_csv | 171,635 | 2 | B | 1 | 0 | 0 | 0 | 5 | 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 | B |
1,445 | # This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load in
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O... | No | 4 | 88 | Debug | list_files | 2,843,645 | 1 | A | 0 | 0 | 0 | 0 | 0 | 7 | 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": "general_ml", "framework": "Genera... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Hardcoded file path"] | 3 | A |
1,446 | test_stage_1 = pd.read_csv("../input/test_stage_1.tsv", sep="\\t")' | No | 5 | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.