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
829
regressor_models={ 'Linear Regression':LinearRegression(), 'Decision Tree Regressor':DecisionTreeRegressor(), 'Random Forest Regressor':RandomForestRegressor(), 'SVR':SVR(), }
No
3
23
Environment
set_options
13,503,938
1
A
0
0
0
0
0
6
ok
3
3
[{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Scaler Missing Checker", "fix": "Apply scaling before scaling-sensitive operations.", "benefits": "Improves model performance and accuracy.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Randomness Contr...
C
Randomness Control Checker=low, Scaler Missing Checker=medium
[{"type": "Randomness Control Checker", "severity": "low"}, {"type": "Scaler Missing Checker", "severity": "medium"}]
["Verbose Mode Checker"]
9
C
830
def get_rmse_score(model,x_train,x_test,y_train,y_test): model.fit(x_train,y_train) y_predicted=model.predict(x_test) r2_score=model.score(x_test,y_test) rmse=sqrt(mean_squared_error(y_test,y_predicted)) return rmse,r2_score
No
4
28
Model_Train
compute_train_metric
13,503,938
1
A
0
1
0
0
0
6
ok
9
8
[{"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, 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"}]
["Exception Handling Checker", "Missing function docstring", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker", "Verbose Mode Checker"]
9
B
831
x_train,x_test,y_train,y_test=train_test_split(X,Y,random_state=42)
No
5
13
Data_Transform
split
13,503,938
1
A
0
0
0
0
0
1
ok
1
1
[{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}]
B
Cross Validation Checker=low
[{"type": "Cross Validation Checker", "severity": "low"}]
[]
9
B
832
svr_model=SVR() svr_model.fit(x_train,y_train) Y_Test_predictions=svr_model.predict(X_Test)
No
3
27
Model_Train
predict_on_train
13,503,938
1
A
0
0
0
0
0
3
ok
9
8
[{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Scaler Missing Checker", "fix": "Apply scaling before scaling-sensitive operations.", "benefits": "Improves model performance and accuracy.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation...
C
Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low, Scaler Missing Checker=medium
[{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}, {"type": "Scaler Missing Checker", "severity": "medium"}]
["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"]
9
C
833
predictions=[] for index in range(len(Y_Test_predictions)): predictions.append([test_indexes[index],Y_Test_predictions[index]])
No
3
48
Model_Evaluation
predict_on_test
13,503,938
1
A
0
1
1
0
0
3
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": "Unit Testing...
A
no applicable ML-specific findings
[]
["Column Selection Checker", "Exception Handling Checker", "Unit Testing Checker"]
9
A
834
predictions_df=pd.DataFrame(predictions,columns=['Id','Prediction']) predictions_df.to_csv('SVM_Predictions.csv',index=False)
No
5
25
Data_Export
save_to_csv
13,503,938
1
A
0
0
0
0
0
2
ok
2
2
[{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Unit Testing Checker", "fix": "Write unit tests for data processing and model components.", "benefits": "Ensures code reliability and prevents bugs.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Excepti...
A
no applicable ML-specific findings
[]
["Exception Handling Checker", "Unit Testing Checker"]
9
A
835
# 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
22
Environment
import_modules
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 12"}]
A
no applicable ML-specific findings
[]
["Hardcoded file path"]
0
A
836
import pandas as pd import numpy as np import seaborn as sns import matplotlib.pyplot as plt import warnings warnings.filterwarnings("ignore")
No
5
23
Environment
set_options
null
1
A
0
0
0
0
0
6
ok
0
0
[]
A
no applicable ML-specific findings
[]
[]
0
A
837
train_path = '../input/restaurant-revenue-prediction/train.csv.zip' df_train = pd.read_csv(train_path) df_train.head()
No
3
41
Debug
show_table
14,177,670
1
A
0
0
0
0
0
3
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"]
11
B
838
test_path = '../input/restaurant-revenue-prediction/test.csv.zip' df_test = pd.read_csv(test_path, index_col='Id') df_test.head()
No
3
41
Debug
show_table
14,177,670
1
A
0
0
0
0
0
3
ok
1
1
[{"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path detected: ../input/restaurant-revenue-prediction/test.csv.zip. Consider using configuration files or environment variables.", "fix": "Not specified", "benefits": "Not specified", "location": "Line 12"}]
A
no applicable ML-specific findings
[]
["Hardcoded file path"]
11
A
839
from datetime import date, datetime def calculate_age(born): born = datetime.strptime(born, "%m/%d/%Y").date() today = date.today() return today.year - born.year - ((today.month, today.day) < (born.month, born.day)) df_train['Age'] = df_train['Open Date'].apply(calculate_age) df_test['Age'] = ...
No
3
41
Debug
show_table
null
1
A
0
null
0
0
0
null
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
840
# Find the sets of categorical variables and numberical variales for feature analyses numerical_features = df_train.select_dtypes([np.number]).columns.tolist() categorical_features = df_train.select_dtypes(exclude = [np.number,np.datetime64]).columns.tolist() print(categorical_features) print(numerical_features)
No
3
40
Debug
show_table_attributes
14,177,670
1
A
0
0
0
0
0
4
ok
3
3
[{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "general_ml", "framework": "General ML", "name...
B
Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low
[{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}]
[]
11
B
841
print(df_train['revenue'].describe()) sns.distplot(a=df_train['revenue'], kde=True).set(xlabel='revenue', ylabel='P(revenue)')
No
5
33
Visualization
distribution
null
1
A
0
0
0
0
0
2
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
842
df_train[df_train['revenue'] > 10000000 ]
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
843
# Drop outliers df_train = df_train[df_train['revenue'] < 10000000 ] df_train.reset_index(drop=True).head()
No
3
10
Data_Transform
drop_column
14,177,670
1
A
0
0
0
0
0
2
ok
4
4
[{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Valida...
B
Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low
[{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}]
["Column Selection Checker"]
11
B
844
fig, ax = plt.subplots(3, 1, figsize=(40, 30)) for variable, subplot in zip(categorical_features, ax.flatten()): df_2 = df_train[[variable,'revenue']].groupby(variable).revenue.sum().reset_index() df_2.columns = [variable,'total_revenue'] sns.barplot(x=variable, y='total_revenue', data=df_2 , ax=subplot) ...
No
5
33
Visualization
distribution
14,177,670
1
A
0
3
5
0
0
13
ok
3
3
[{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "general_ml", "framework": "General ML", "name...
B
Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low
[{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}]
[]
11
B
845
fig, ax = plt.subplots(13, 3, figsize=(30, 35)) for variable, subplot in zip(numerical_features, ax.flatten()): sns.regplot(x=df_train[variable], y=df_train['revenue'], ax=subplot) subplot.set_xlabel(variable,fontsize=20) subplot.set_ylabel('Revenue',fontsize=20) fig.tight_layout()
No
5
33
Visualization
distribution
null
1
A
0
1
1
0
0
6
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
846
plt.figure(figsize=(45,25)) mask = np.triu(np.ones_like(df_train.corr(), dtype=np.bool)) sns.heatmap(df_train.corr(),annot=True, mask=mask) sns.set(font_scale=1.4)
No
5
80
Visualization
heatmap
null
1
A
0
0
0
0
0
4
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
847
fig, ax = plt.subplots(3, 1, figsize=(40, 30)) for variable, subplot in zip(categorical_features, ax.flatten()): sns.swarmplot(x=variable, y='revenue', data=df_train, ax=subplot,size=10) subplot.set_xlabel(variable,fontsize=20) subplot.set_ylabel('Revenue',fontsize=20) for label in subplot.get_xticklabe...
No
5
33
Visualization
distribution
14,177,670
1
A
0
3
5
0
0
11
ok
0
0
[]
A
no applicable ML-specific findings
[]
[]
11
A
848
#Lets take a look at city group field print("--- Train set ---") print(df_train['City Group'].value_counts()) print("---- Test set ----") print(df_test['City Group'].value_counts())'
No
5
72
EDA
count_values
null
1
A
0
null
0
0
0
null
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
849
#Lets take a look at type field print("--- Train set ---") print(df_train['Type'].value_counts()) print("---- Test set ----") print(df_test['Type'].value_counts()) '
No
5
72
EDA
count_values
null
1
A
0
null
0
0
0
null
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
850
y = df_train['revenue'] df_train=df_train.drop('revenue', axis=1)
No
5
21
Data_Transform
prepare_x_and_y
14,177,670
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"]
11
B
851
print("Shapes: Train set ", df_train.shape ,", Test ",df_test.shape) df_full = pd.concat([df_train,df_test]) print("Full dataset shapes: ", df_full.shape)
No
4
58
Debug
show_shape
null
1
A
0
0
0
0
0
3
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
852
print('There are {} cities which restaurant location have been collected.'.format(len(df_full['City'].unique())))
No
3
58
Debug
show_shape
null
1
A
0
0
0
0
0
1
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
853
df_full = df_full.drop('City', axis=1) df_full.shape
No
4
10
Data_Transform
drop_column
14,177,670
1
A
0
0
0
0
0
2
ok
0
0
[]
A
no applicable ML-specific findings
[]
[]
11
A
854
p_name = ['P'+str(i) for i in range(1,38)]
No
3
58
Debug
show_shape
14,177,670
1
A
0
0
0
0
0
1
ok
0
0
[]
A
no applicable ML-specific findings
[]
[]
11
A
855
from sklearn.decomposition import PCA pca = PCA().fit(df_full[p_name]) plt.figure(figsize=(7,5)) plt.plot(np.cumsum(pca.explained_variance_ratio_)) plt.xlabel('number of Components') plt.ylabel('Explained variance') plt.yticks(np.arange(0.1,1.1,0.05)) plt.xticks(np.arange(0,41,2)) plt.grid(True)
No
3
23
Environment
set_options
null
1
A
1
0
0
0
5
9
ok
9
8
[{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Scaler Missing Checker", "fix": "Apply scaling before scaling-sensitive operations.", "benefits": "Improves model performance and accuracy.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Pipeline Checker...
D
Cross Validation Checker=low, Data Leakage Checker=high, Pipeline Checker=low, Randomness Control Checker=low, Scaler Missing Checker=medium
[{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}, {"type": "Pipeline Checker", "severity": "low"}, {"type": "Randomness Control Checker", "severity": "low"}, {"type": "Scaler Missing Checker", "severity": "medium"}]
["Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"]
0
D
856
pca_list = ['pca'+str(i) for i in range(1,30,1)] df_full[pca_list] = PCA(n_components=29).fit_transform(df_full[p_name]) df_full.drop(p_name,axis=1,inplace=True)
No
3
33
Visualization
distribution
14,177,670
1
A
0
0
0
0
0
3
ok
11
10
[{"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 14"}, {"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker"...
D
Cross Validation Checker=low, Data Leakage Checker=high, Pipeline Checker=low, Randomness Control Checker=low, Scaler Missing Checker=medium
[{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}, {"type": "Pipeline Checker", "severity": "low"}, {"type": "Randomness Control Checker", "severity": "low"}, {"type": "Scaler Missing Checker", "severity": "medium"}]
["Column Selection Checker", "Exception Handling Checker", "InPlace Checker", "Unit Testing Checker", "Verbose Mode Checker"]
11
D
857
df_full.info()
No
4
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
858
df=pd.get_dummies(df_full, dtype=float)
No
3
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
859
# Get number of train sets numTrain=df_train.shape[0] train = df[:numTrain] test = df[numTrain:]
No
3
13
Data_Transform
split
null
1
A
0
0
0
0
0
3
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
860
sns.distplot(a=y, kde=True).set(xlabel='revenue', ylabel='P(revenue)')
No
5
33
Visualization
distribution
14,177,670
1
A
0
0
0
0
0
1
ok
0
0
[]
A
no applicable ML-specific findings
[]
[]
11
A
861
print("Kurtosis: {}".format(y.kurt())) print("Skewness: {}".format(y.skew()))
No
5
40
Debug
show_table_attributes
14,177,670
1
A
0
0
0
0
0
2
ok
0
0
[]
A
no applicable ML-specific findings
[]
[]
11
A
862
from sklearn.model_selection import GridSearchCV from sklearn.linear_model import Lasso, Ridge, ElasticNet from sklearn.ensemble import AdaBoostRegressor from xgboost import XGBRegressor
No
4
21
Data_Transform
prepare_x_and_y
14,177,670
1
A
0
0
0
0
0
4
ok
0
0
[]
A
no applicable ML-specific findings
[]
[]
11
A
863
best_estimators=[]
No
5
77
Other
define_variables
14,177,670
1
A
0
0
0
0
0
1
ok
0
0
[]
A
no applicable ML-specific findings
[]
[]
11
A
864
## Parameters params = { "alpha" : [.01, .1, .5, .7, .9, .95, .99, 1, 5, 10, 20], "fit_intercept" : [True, False], "normalize" : [True,False], "solver" : ['svd', 'cholesky', 'lsqr', 'sparse_cg', 'sag', 'saga'], "tol" : [0.0001, 0.001, 0.01, 0.1], "random_state" : [42] } ## Ridge ridge = Ridge()...
No
4
23
Environment
set_options
null
1
A
0
null
0
0
0
null
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
865
params = { 'alpha' : [.01, .1, .5, .7, .9, .95, .99, 1, 5, 10, 20], 'fit_intercept' : [True, False], 'normalize' : [True,False], 'tol' : [0.0001, 0.001, 0.01, 0.1], "random_state" : [42] } ## Lasso lasso = Lasso() lasso_grid = GridSearchCV(lasso, params, scoring='r2', cv=5, n_jobs=-1) lasso_grid.fi...
No
3
5
Hyperparam_Tuning
define_search_space
null
1
A
0
null
0
0
0
null
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
866
# Parameters params = { "alpha" : [.01, .1, .5, .7, .9, .95, .99, 1, 5, 10, 20], "fit_intercept" : [True, False], "normalize" : [True,False], "tol" : [0.0001, 0.001, 0.01, 0.1], "random_state" : [42] } ## Elastic Net EL = ElasticNet() EL_grid = GridSearchCV(EL, params, scoring='r2', cv=5, n_jobs=-1...
No
3
5
Hyperparam_Tuning
define_search_space
null
1
A
0
null
0
0
0
null
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
867
# parameters params = { "learning_rate": [.1, .5, .7, .9, .95, .99, 1], "colsample_bytree": [.3, .4, .5, .6], "max_depth": [2, 4], "alpha": [1, 3, 5], "subsample": [.5], "n_estimators": [30, 70, 100, 200], "random_state" : [42] } ## XGBoost Regressor XGBR = XGBRegressor() XGBR_grid = GridS...
No
3
5
Hyperparam_Tuning
define_search_space
null
1
A
0
null
0
0
0
null
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
868
## parameters params = { "n_estimators": [10, 30, 50, 100], "learning_rate": [.01, 0.1, 0.5, 0.9, 0.95, 1], "random_state" : [42] } ## XGBoost Regressor AdaBoostR = AdaBoostRegressor() AdaBoostR_grid = GridSearchCV(AdaBoostR, params, scoring='r2', cv=5, n_jobs=-1) AdaBoostR_grid.fit(X_train, y_train) ##...
No
3
5
Hyperparam_Tuning
define_search_space
null
1
A
0
null
0
0
0
null
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
869
from sklearn.pipeline import Pipeline from sklearn.preprocessing import StandardScaler ## pipeline pipelines = [] for name,model in best_estimators: pipeline = Pipeline([("Scaler",StandardScaler()), (name,model) ]) pipelines.append(["Scaled_"+name,pipeline])
No
3
5
Hyperparam_Tuning
define_search_space
14,177,670
1
A
1
1
1
0
5
8
ok
0
0
[]
A
no applicable ML-specific findings
[]
[]
11
A
870
from sklearn.model_selection import KFold, cross_val_score ## Create a dataframe to store all the models' cross validation score evaluate = pd.DataFrame(columns=["model","cv","std"]) ## Encoded dataset for name,model in pipelines: kfold = KFold(n_splits=10,random_state=42) cv = cross_val_score(model, X_train...
No
2
22
Environment
import_modules
null
1
A
0
null
0
0
0
null
invalid_python
0
0
[]
null
invalid_python
[]
[]
0
null
871
from sklearn.ensemble import VotingRegressor
No
3
56
Visualization
plot_predictions
null
1
A
0
0
0
0
0
1
ok
0
0
[]
A
no applicable ML-specific findings
[]
[]
0
A
872
## Creating a list for all combinations models votings = [] ## All models votings.append(("Scaled_all_models",Pipeline([("Scaler",StandardScaler()), ("Votings",VotingRegressor([("XGBoostR",XGBR_grid.best_estimator_), ...
No
5
82
Hyperparam_Tuning
define_search_model
14,177,670
1
A
0
0
0
0
0
20
ok
0
0
[]
A
no applicable ML-specific findings
[]
[]
11
A
873
!pip install python-googlegeocoder
No
4
22
Environment
import_modules
8,604,602
1
A
0
null
0
0
0
null
invalid_python
0
0
[]
null
invalid_python
[]
[]
5
null
874
import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as sns from googlegeocoder import GoogleGeocoder from bokeh.plotting import figure, save import plotly.graph_objects as go import sklearn import warnings warnings.filterwarnings("ignore") plt.style.use('ggplot') pd.plotting.register_m...
No
5
23
Environment
set_options
null
1
A
0
null
0
0
0
null
invalid_python
0
0
[]
null
invalid_python
[]
[]
0
null
875
train_df=pd.read_csv('/kaggle/input/covid19-global-forecasting-week-2/train.csv') test_df=pd.read_csv('/kaggle/input/covid19-global-forecasting-week-2/test.csv') all_data=pd.concat([train_df,test_df],axis=0) all_data.reset_index(drop=True)
No
3
45
Data_Extraction
load_from_csv
8,604,602
1
A
0
0
0
0
0
4
ok
3
2
[{"detector": "general_ml", "framework": "General ML", "name": "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "fix": "Not specified", "benefits": "Not specified", "location": ""}, {"detector": "general_ml", "framework": "General ML", "name": "Har...
A
no applicable ML-specific findings
[]
["Hardcoded file path", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness."]
5
A
876
train_df.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
877
train_df['Country_Region'].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
878
print("fill blanks and add region for counting") train_df.drop('Province_State',axis=1,inplace=True)'
No
5
10
Data_Transform
drop_column
null
1
A
0
null
0
0
0
null
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
879
# Resetting Date column into Datetime object and making it an index of dataframe train_df['Date']=pd.to_datetime(train_df['Date']) train_df.set_index('Date',inplace=True)
No
4
16
Data_Transform
data_type_conversions
null
1
A
0
0
0
0
0
2
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
880
from sklearn.neighbors import KNeighborsRegressor params_knn = { 'n_neighbors' : [3, 5, 7, 9, 11], } knn_model = KNeighborsRegressor() knn_regressor = GridSearchCV(knn_model, params_knn, scoring='neg_root_mean_squared_error', cv=10, n_jobs=-1) knn_regressor.fit(X_train, y_train) print(f'Optimal neighbors: {knn_re...
No
4
6
Hyperparam_Tuning
train_on_grid
null
1
A
0
null
0
0
0
null
invalid_python
0
0
[]
null
invalid_python
[]
[]
0
null
881
knn_model = KNeighborsRegressor(n_neighbors=knn_regressor.best_params_["n_neighbors"]) knn_model.fit(X_train, y_train) y_train_pred = knn_model.predict(X_train) y_pred = knn_model.predict(X_test) print('Train r2 score: ', r2_score(y_train_pred, y_train)) print('Test r2 score: ', r2_score(y_test, y_pred)) train_rmse = n...
No
3
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
882
from sklearn.ensemble import RandomForestRegressor params_rf = { 'max_depth': [10, 30, 35, 50, 65, 75, 100], 'max_features': [.3, .4, .5, .6], 'min_samples_leaf': [3, 4, 5], 'min_samples_split': [8, 10, 12], 'n_estimators': [30, 50, 100, 200] } rf = RandomForestRegressor() rf_regressor = GridSearc...
No
5
2
Hyperparam_Tuning
find_best_params
null
1
A
0
null
0
0
0
null
invalid_python
0
0
[]
null
invalid_python
[]
[]
0
null
883
rf_model = RandomForestRegressor(max_depth=rf_regressor.best_params_["max_depth"], max_features=rf_regressor.best_params_["max_features"], min_samples_leaf=rf_regressor.best_params_["min_samples_leaf"], min_samples_spl...
No
3
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
884
# # City, City Group, Type from sklearn.preprocessing import LabelEncoder le = LabelEncoder() df_all["City"] = le.fit_transform(df_all["City"]) df_all["City Group"] = le.fit_transform(df_all["City Group"]) df_all["Type"] = le.fit_transform(df_all["Type"]) # df_all'
No
4
20
Data_Transform
categorify
null
1
A
0
0
0
0
0
5
ok
12
8
[{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Pipeline Checker", "fix": "Use Pipelines for all scikit-learn estimators.", "benefits": "Prevents data leakage and ensures correct model evaluation.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross V...
D
Cross Validation Checker=low, Data Leakage Checker=high, No random seed setting detected=low, Pipeline Checker=low
[{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}, {"type": "No random seed setting detected", "severity": "low"}, {"type": "Pipeline Checker", "severity": "low"}]
["Exception Handling Checker", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker", "Verbose Mode Checker"]
0
D
885
# df_train_fin = df_all.iloc[:df_train.shape[0]] # df_train df_test_fin = df_all.iloc[df_train.shape[0]:] # df_test'
No
5
13
Data_Transform
split
null
1
A
0
0
0
0
0
2
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
886
from sklearn.ensemble import RandomForestRegressor # IDOpenDate out_columns = ["Id", "Open Date"] columns = [] for i in df_train_fin.columns: if i not in out_columns: columns.append(i) x_train = df_train_fin[columns] # rfr = RandomForestRegressor( n_estimators=200, max_depth=5, max_feat...
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
887
pred = rfr.predict(df_test_fin[columns])
No
5
48
Model_Evaluation
predict_on_test
11,410,370
1
A
0
0
0
0
0
1
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": "Unit Testing...
A
no applicable ML-specific findings
[]
["Column Selection Checker", "Exception Handling Checker", "Unit Testing Checker"]
4
A
888
df_submission
No
5
41
Debug
show_table
null
1
A
0
0
0
1
0
1
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
889
df_submission['Prediction'] = pred df_submission.to_csv('/kaggle/working/RandamForest_submission01.csv', index=False)
No
4
25
Data_Export
save_to_csv
11,410,370
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": "general_ml", "framework": "General ML", "name": "Hardcoded file path d...
A
no applicable ML-specific findings
[]
["Column Selection Checker", "Hardcoded file path"]
4
A
890
# 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
5
88
Debug
list_files
null
1
A
1
2
3
0
5
8
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 16"}]
A
no applicable ML-specific findings
[]
["Hardcoded file path"]
0
A
891
train = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-2/train.csv') test = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-2/test.csv') submission = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-2/submission.csv')
No
5
45
Data_Extraction
load_from_csv
null
1
A
0
0
0
0
0
3
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
894
from plotly.offline import iplot from plotly import tools import plotly.graph_objects as go import plotly.express as px import plotly.offline as py import plotly.figure_factory as ff from plotly.subplots import make_subplots import plotly.io as pio pio.templates.default = "plotly_dark" py.init_notebook_mode(connected=T...
No
5
23
Environment
set_options
null
1
A
0
0
0
0
0
10
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
895
latest_grouped = train.groupby('Country_Region')['ConfirmedCases', 'Fatalities'].sum().reset_index()
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
896
fig = px.bar(latest_grouped.sort_values('ConfirmedCases', ascending=False)[:20][::-1], x='ConfirmedCases', y='Country_Region', title='Confirmed Cases Worldwide', text='ConfirmedCases', height=1000, orientation='h') fig.show()
No
5
33
Visualization
distribution
null
1
A
0
0
0
0
0
4
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
897
europe = list(['Austria','Belgium','Bulgaria','Croatia','Cyprus','Czechia','Denmark','Estonia','Finland','France','Germany','Greece','Hungary','Ireland', 'Italy', 'Latvia','Luxembourg','Lithuania','Malta','Norway','Netherlands','Poland','Portugal','Romania','Slovakia','Slovenia', 'Spain', ...
No
5
14
Data_Transform
filter
null
1
A
1
0
0
0
5
5
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
898
temp = train[train['Country_Region'].isin(europe)] temp = temp.groupby(['Date', 'Country_Region'])['ConfirmedCases'].sum().reset_index() temp['Date'] = pd.to_datetime(temp['Date']).dt.strftime('%m/%d/%Y') temp['size'] = temp['ConfirmedCases'].pow(0.3) * 3.5 fig = px.scatter_geo(temp, locations="Country_Region", locati...
No
5
33
Visualization
distribution
null
1
A
0
null
0
0
0
null
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
899
fig = px.bar(europe_grouped_latest.sort_values('ConfirmedCases', ascending=False)[:10][::-1], x='ConfirmedCases', y='Country_Region', color_discrete_sequence=['#84DCC6'], title='Confirmed Cases in Europe', text='ConfirmedCases', orientation='h') fig.show()
No
5
33
Visualization
distribution
null
1
A
0
0
0
0
0
4
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
900
usa = train[train['Country_Region'] == "US"] usa_latest = usa[usa['Date'] == max(usa['Date'])] usa_latest = usa_latest.groupby('Province_State')['ConfirmedCases', 'Fatalities'].max().reset_index() fig = px.bar(usa_latest.sort_values('ConfirmedCases', ascending=False)[:10][::-1], x='ConfirmedCases', y='Pro...
No
5
33
Visualization
distribution
null
1
A
0
null
0
0
0
null
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
901
ch = train[train['Country_Region'] == "China"] ch = ch[ch['Date'] == max(ch['Date'])] ch = ch.groupby('Province_State')['ConfirmedCases', 'Fatalities'].max().reset_index() fig = px.bar(ch.sort_values('ConfirmedCases', ascending=False)[:10][::-1], x='ConfirmedCases', y='Province_State', color_discrete_sequ...
No
5
33
Visualization
distribution
null
1
A
0
null
0
0
0
null
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
902
province_encoded = {state:index for index, state in enumerate(train['Province_State'].unique())}
No
5
77
Other
define_variables
null
1
A
0
0
0
0
0
1
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
903
train['province_encoded'] = train['Province_State'].apply(lambda x: province_encoded[x]) train.head()
No
4
20
Data_Transform
categorify
null
1
A
0
0
0
0
0
2
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
904
country_encoded = dict(enumerate(train['Country_Region'].unique())) country_encoded = dict(map(reversed, country_encoded.items()))
No
5
20
Data_Transform
categorify
null
1
A
0
0
0
0
0
2
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
905
train['country_encoded'] = train['Country_Region'].apply(lambda x: country_encoded[x]) train.head()
No
4
20
Data_Transform
categorify
null
1
A
0
0
0
0
0
2
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
906
from datetime import datetime import time
No
5
22
Environment
import_modules
null
1
A
0
0
0
0
0
2
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
909
train['Mon'] = train['Date'].apply(lambda x: int(x.split('-')[1])) train['Day'] = train['Date'].apply(lambda x: int(x.split('-')[2]))
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
910
train['serial'] = train['Mon'] * 30 + train['Day'] train.head()
No
4
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
911
train['serial'] = train['serial'] - train['serial'].min()
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
912
gdp2020 = pd.read_csv('/kaggle/input/gdp2020/GDP2020.csv') population2020 = pd.read_csv('/kaggle/input/population2020/population2020.csv')
No
5
45
Data_Extraction
load_from_csv
null
1
A
0
0
0
0
0
2
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
913
gdp2020 = gdp2020.rename(columns={"rank":"rank_gdp"}) gdp2020_numeric_list = [list(gdp2020)[0]] + list(gdp2020)[2:-1] gdp2020.head()
No
4
61
Data_Transform
rename_columns
null
2
B
1
0
0
0
5
3
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
914
set(train['Country_Region']) - set(population2020['name'])
No
5
57
Debug
show_unique_values
null
1
A
0
0
0
1
0
1
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
915
set(train['Country_Region']) - set(gdp2020['country'])
No
5
57
Debug
show_unique_values
null
1
A
0
0
0
1
0
1
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
916
population2020 = population2020.rename(columns={"rank":"rank_pop"}) population2020_numeric_list = [list(population2020)[0]] + list(gdp2020)[2:] population2020.head()
No
4
61
Data_Transform
rename_columns
null
2
B
1
0
0
0
5
3
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
917
train = pd.merge(train, population2020, how='left', left_on = 'Country_Region', right_on = 'name') train = pd.merge(train, gdp2020, how='left', left_on = 'Country_Region', right_on = 'country')
No
5
32
Data_Transform
merge
null
1
A
0
0
0
0
0
2
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
918
train = train.fillna(-1)
No
5
17
Data_Transform
correct_missing_values
null
1
A
0
0
0
0
0
1
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
919
# numeric_features_X = ['Lat','Long', 'province_encoded' ,'country_encoded','Mon','Day'] numeric_features_X = ['province_encoded' ,'country_encoded','Mon','Day'] + population2020_numeric_list + gdp2020_numeric_list numeric_features_Y = ['ConfirmedCases', 'Fatalities'] train_numeric_X = train[numeric_features_X] train_n...
No
5
21
Data_Transform
prepare_x_and_y
null
1
A
1
0
0
0
5
4
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
920
test['province_encoded'] = test['Province_State'].apply(lambda x: province_encoded[x] if x in province_encoded else max(province_encoded.values())+1)
No
5
8
Data_Transform
feature_engineering
null
1
A
0
1
1
0
0
1
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
921
test['country_encoded'] = test['Country_Region'].apply(lambda x: country_encoded[x] if x in country_encoded else max(country_encoded.values())+1)
No
5
8
Data_Transform
feature_engineering
null
1
A
0
1
1
0
0
1
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
922
test['Mon'] = test['Date'].apply(lambda x: int(x.split('-')[1])) test['Day'] = test['Date'].apply(lambda x: int(x.split('-')[2]))
No
3
16
Data_Transform
data_type_conversions
null
1
A
0
0
0
0
0
2
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
923
test['serial'] = test['Mon'] * 30 + test['Day'] test['serial'] = test['serial'] - test['serial'].min()
No
4
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
924
test = pd.merge(test, population2020, how='left', left_on = 'Country_Region', right_on = 'name') test = pd.merge(test, gdp2020, how='left', left_on = 'Country_Region', right_on = 'country')
No
5
32
Data_Transform
merge
null
1
A
0
0
0
0
0
2
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
925
test_numeric_X = test[numeric_features_X] test_numeric_X.isnull().sum()
No
4
21
Data_Transform
prepare_x_and_y
null
1
A
0
0
0
0
0
2
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
926
test_numeric_X = test_numeric_X.fillna(-1)
No
5
17
Data_Transform
correct_missing_values
null
1
A
0
0
0
0
0
1
no_ml_import
0
0
[]
null
no_ml_import
[]
[]
0
null
927
from sklearn.pipeline import Pipeline from sklearn.preprocessing import StandardScaler from sklearn.linear_model import LinearRegression
No
5
22
Environment
import_modules
null
1
A
0
0
0
0
0
3
ok
0
0
[]
A
no applicable ML-specific findings
[]
[]
0
A
928
# Random Forest Model Feature Importance rf_feature_importance = pd.Series(index = X_train.columns, data = np.abs(rf_model.feature_importances_)) n_features = (rf_feature_importance>0).sum() print(f'{n_features} features with reduction of {(1-n_features/len(rf_feature_importance))*100:2.2f}%') rf_feature_importance.sor...
No
2
79
Visualization
model_coefficients
12,343,159
1
A
0
0
0
0
0
4
ok
2
1
[{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 9"}, {"detector": "framework_specific", "framework": "General", "name": "Import Checker", ...
A
no applicable ML-specific findings
[]
["Import Checker"]
15
A
929
import lightgbm as lgbm params_lgbm = { 'learning_rate': [.01, .1, .5, .7, .9, .95, .99, 1], 'boosting': ['gbdt'], 'metric': ['l1'], 'feature_fraction': [.3, .4, .5, 1], 'num_leaves': [20], 'min_data': [10], 'max_depth': [10], 'n_estimators': [10, 30, 50, 100] } lgb = lgbm.LGBMRegresso...
No
5
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
930
lgb_model = lgbm.LGBMRegressor(learning_rate=lgb_regressor.best_params_["learning_rate"], boosting='gbdt', metric='l1', feature_fraction=lgb_regressor.best_params_["feature_fraction"], num_leaves=20, min_data=10, max_depth=10, ...
No
3
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
931
# LightGBM Feature Importance lgb_feature_importance = pd.Series(index = X_train.columns, data = np.abs(lgb_model.feature_importances_)) n_features = (lgb_feature_importance>0).sum() print(f'{n_features} features with reduction of {(1-n_features/len(lgb_feature_importance))*100:2.2f}%') lgb_feature_importance.sort_valu...
No
5
79
Visualization
model_coefficients
12,343,159
1
A
0
0
0
0
0
4
ok
2
1
[{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 9"}, {"detector": "framework_specific", "framework": "General", "name": "Import Checker", ...
A
no applicable ML-specific findings
[]
["Import Checker"]
15
A
932
params_xgb = { 'learning_rate': [.1, .5, .7, .9, .95, .99, 1], 'colsample_bytree': [.3, .4, .5, .6], 'max_depth': [4], 'alpha': [3], 'subsample': [.5], 'n_estimators': [30, 70, 100, 200] } xgb_model = XGBRegressor() xgb_regressor = GridSearchCV(xgb_model, params_xgb, scoring='neg_root_mean_squa...
No
5
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