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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2,889 | len(data.train_ds.cont_names) | 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 |
2,890 | learn.lr_find()
learn.recorder.plot() | No | 5 | 35 | Visualization | learning_history | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,891 | learn.fit_one_cycle(5, 1e-3, wd=0.2) | No | 5 | 7 | Model_Train | train_model | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,892 | learn.save('1') | No | 5 | 50 | Model_Train | save_model | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,893 | learn.recorder.plot_losses(skip_start=10000) | No | 5 | 35 | Visualization | learning_history | 10,295,596 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,894 | learn.load('1'); | No | 5 | 30 | Model_Train | load_pretrained | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,895 | learn.fit_one_cycle(5, 3e-4) | No | 5 | 7 | Model_Train | train_model | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,896 | import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import os | 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 |
2,897 | # Loading data directly from CatBoost
from catboost.datasets import amazon
train, test = amazon() | No | 3 | 21 | Data_Transform | prepare_x_and_y | 3,389,306 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 5 | A |
2,898 | print("Train shape: {}, Test shape: {}".format(train.shape, test.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 |
2,899 | train.head(5) | No | 5 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,900 | test.head(5) | No | 5 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,901 | train.apply(lambda x: len(x.unique())) | No | 5 | 54 | EDA | count_unique_values | 3,389,306 | 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"}] | [] | 5 | B |
2,902 | import itertools
target = "ACTION"
col4train = [x for x in train.columns if x!=target]
col1 = 'ROLE_CODE'
col2 = 'ROLE_TITLE'
pair = len(train.groupby([col1,col2]).size())
single = len(train.groupby([col1]).size())
print(col1, col2, pair, single)' | No | 3 | 71 | Debug | show_columns | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,903 | col4train = [x for x in col4train if x!='ROLE_TITLE'] | No | 5 | 77 | Other | define_variables | 3,389,306 | 1 | A | 0 | 1 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 5 | A |
2,904 | #linear - OHE
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import OneHotEncoder
ohe = OneHotEncoder(sparse=True, dtype=np.float32, handle_unknown='ignore') | Yes | 4 | 20 | Data_Transform | categorify | 3,389,306 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 5 | A |
2,905 | X = ohe.fit_transform(train[col4train])
y = train["ACTION"].values | No | 4 | 21 | Data_Transform | prepare_x_and_y | 3,389,306 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 6 | 6 | [{"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... | D | Cross Validation Checker=low, Data Leakage Checker=high | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}] | ["Column Selection Checker", "Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 5 | D |
2,906 | from sklearn.model_selection import cross_validate
model = LogisticRegression(
penalty='l2',
C=1.0,
fit_intercept=True,
random_state=432,
solver = 'liblinear',
max_iter = 1000,
)
stats = cross_validate(model, X,... | No | 3 | 4 | Model_Train | choose_model_class | 3,389,306 | 1 | A | 0 | 0 | 0 | 0 | 0 | 13 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Scaler Missing Checker", "fix": "Apply scaling before scaling-sensitive operations.", "benefits": "Improves model performance and accuracy.", "location": ""}] | C | Scaler Missing Checker=medium | [{"type": "Scaler Missing Checker", "severity": "medium"}] | [] | 5 | C |
2,907 | X = ohe.fit_transform(train[col4train])
y = train["ACTION"].values
X_te = ohe.transform(test[col4train])
model.fit(X,y)
predictions = model.predict_proba(X_te)[:,1]
submit = pd.DataFrame()
submit["Id"] = test["id"]
submit["ACTION"] = predictions
submit.to_csv("submission.csv", index = False) | Yes | 3 | 7 | Model_Train | train_model | 3,389,306 | 1 | A | 0 | 0 | 0 | 0 | 0 | 9 | ok | 14 | 10 | [{"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... | D | Cross Validation Checker=low, Cross-validation not detected=low, Data Leakage Checker=high, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}, {"type": "No random seed setting detected", "severity": "low"}] | ["Column Selection Checker", "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", "Verbose Mode Checker"] | 5 | D |
2,908 | # Loading data directly from CatBoost
from catboost.datasets import amazon
train, test = amazon()
target = "ACTION"
col4train = [x for x in train.columns if x not in [target, "ROLE_TITLE"]]
y = train[target].values | No | 3 | 13 | Data_Transform | split | 3,414,311 | 1 | A | 0 | 1 | 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"] | 6 | A |
2,909 | from sklearn.model_selection import StratifiedKFold
from sklearn.metrics import roc_auc_score
from sklearn.ensemble import ExtraTreesClassifier
#our small helper function, returns ExtraTrees instance
def get_model():
params = {
"n_estimators":300,
"n_jobs": 3,
"random_state":5436,
}
... | No | 3 | 59 | Model_Train | init_hyperparams | 3,414,311 | 1 | A | 1 | 1 | 0 | 0 | 5 | 10 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 6 | A |
2,910 | from sklearn.base import BaseEstimator, TransformerMixin
class TargetEncoding(BaseEstimator, TransformerMixin):
def __init__(self, columns_names ):
self.columns_names = columns_names
self.learned_values = {}
self.dataset_mean = np.nan
def fit(self, X, y, **fit_params):
X_ = ... | No | 5 | 20 | Data_Transform | categorify | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
2,911 | skf = StratifiedKFold(n_splits=5, random_state = 5451, shuffle = True)
te = TargetEncoding(columns_names=col4train)
X_tr = te.fit_transform(train, y).values
scores = []
tr_scores = []
for train_index, test_index in skf.split(train, y):
train_df, valid_df = X_tr[train_index], X_tr[test_index]
train_y, valid_y =... | Yes | 2 | 7 | Model_Train | train_model | 3,414,311 | 1 | A | 0 | 1 | 1 | 0 | 0 | 17 | ok | 11 | 6 | [{"detector": "framework_specific", "framework": "NumPy", "name": "Missing Axis Specification", "fix": "Specify axis in array operations.", "benefits": "Improves performance and avoids unexpected behaviour.", "location": "Line 27"}, {"detector": "framework_specific", "framework": "NumPy", "name": "Missing Axis Specific... | C | Missing Axis Specification=medium | [{"type": "Missing Axis Specification", "severity": "medium"}] | ["Column Selection Checker", "Exception Handling Checker", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker", "Verbose Mode Checker"] | 6 | C |
2,912 | scores = []
tr_scores = []
for train_index, test_index in skf.split(train, y):
train_df = train.loc[train_index,col4train].reset_index(drop = True)
valid_df = train.loc[test_index,col4train].reset_index(drop = True)
train_y, valid_y = y[train_index], y[test_index]
te = TargetEncoding(columns_names=... | Yes | 2 | 7 | Model_Train | train_model | 3,414,311 | 1 | A | 0 | 1 | 1 | 0 | 0 | 18 | ok | 16 | 10 | [{"detector": "framework_specific", "framework": "NumPy", "name": "Missing Axis Specification", "fix": "Specify axis in array operations.", "benefits": "Improves performance and avoids unexpected behaviour.", "location": "Line 28"}, {"detector": "framework_specific", "framework": "NumPy", "name": "Missing Axis Specific... | D | Cross Validation Checker=low, Cross-validation not detected=low, Data Leakage Checker=high, Missing Axis Specification=medium, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}, {"type": "Missing Axis Specification", "severity": "medium"}, {"type": "No random seed setting detected", "severity": "low"}] | ["Column Selection Checker", "Exception Handling Checker", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker", "Verbose Mode Checker"] | 6 | D |
2,913 | class TargetEncodingSmoothing(BaseEstimator, TransformerMixin):
def __init__(self, columns_names,k, f ):
self.columns_names = columns_names
self.learned_values = {}
self.dataset_mean = np.nan
self.k = k #
self.f = f #
def smoothing_func(self, N): #
return 1 / (1 +... | No | 3 | 20 | Data_Transform | categorify | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,914 | %matplotlib inline
x = np.linspace(0,100,100)
plot = pd.DataFrame()
te = TargetEncodingSmoothing([], 1,1)
plot["k=1|f=1"] = te.smoothing_func(x)
te = TargetEncodingSmoothing([], 33,5)
plot["k=33|f=5"] = te.smoothing_func(x)
te = TargetEncodingSmoothing([], 66,15)
plot["k=66|f=15"] = te.smoothing_func(x)
plot.plot(figsi... | No | 5 | 81 | Visualization | relationship | 3,414,311 | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 6 | null |
2,915 | scores = []
tr_scores = []
for train_index, test_index in skf.split(train, y):
train_df = train.loc[train_index,col4train].reset_index(drop = True)
valid_df = train.loc[test_index,col4train].reset_index(drop = True)
train_y, valid_y = y[train_index], y[test_index]
te = TargetEncodingSmoothing(
c... | Yes | 1 | 7 | Model_Train | train_model | 3,414,311 | 1 | A | 0 | 1 | 1 | 0 | 0 | 21 | ok | 16 | 10 | [{"detector": "framework_specific", "framework": "NumPy", "name": "Missing Axis Specification", "fix": "Specify axis in array operations.", "benefits": "Improves performance and avoids unexpected behaviour.", "location": "Line 30"}, {"detector": "framework_specific", "framework": "NumPy", "name": "Missing Axis Specific... | D | Cross Validation Checker=low, Cross-validation not detected=low, Data Leakage Checker=high, Missing Axis Specification=medium, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}, {"type": "Missing Axis Specification", "severity": "medium"}, {"type": "No random seed setting detected", "severity": "low"}] | ["Column Selection Checker", "Exception Handling Checker", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker", "Verbose Mode Checker"] | 6 | D |
2,916 | def get_CV_target_encoding(data, y, encoder, cv = 5):
skfTE = StratifiedKFold(n_splits=cv, random_state = 545167, shuffle = True)
result = []
for train_indexTE, test_indexTE in skfTE.split(data, y):
encoder.fit(data.iloc[train_indexTE,:].reset_index(drop = True), y[train_indexTE])
tmp = enc... | Yes | 2 | 20 | Data_Transform | categorify | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,917 | scores = []
tr_scores = []
for train_index, test_index in skf.split(train, y):
train_df = train.loc[train_index,col4train].reset_index(drop = True)
valid_df = train.loc[test_index,col4train].reset_index(drop = True)
train_y, valid_y = y[train_index], y[test_index]
te = TargetEncodingSmoothing(
c... | Yes | 1 | 7 | Model_Train | train_model | 3,414,311 | 1 | A | 0 | 1 | 1 | 0 | 0 | 22 | ok | 16 | 10 | [{"detector": "framework_specific", "framework": "NumPy", "name": "Missing Axis Specification", "fix": "Specify axis in array operations.", "benefits": "Improves performance and avoids unexpected behaviour.", "location": "Line 33"}, {"detector": "framework_specific", "framework": "NumPy", "name": "Missing Axis Specific... | D | Cross Validation Checker=low, Cross-validation not detected=low, Data Leakage Checker=high, Missing Axis Specification=medium, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}, {"type": "Missing Axis Specification", "severity": "medium"}, {"type": "No random seed setting detected", "severity": "low"}] | ["Column Selection Checker", "Exception Handling Checker", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker", "Verbose Mode Checker"] | 6 | D |
2,918 | class TargetEncodingExpandingMean(BaseEstimator, TransformerMixin):
def __init__(self, columns_names):
self.columns_names = columns_names
self.learned_values = {}
self.dataset_mean = np.nan
def fit(self, X, y, **fit_params):
X_ = X.copy()
self.learned_values = {}
... | No | 4 | 20 | Data_Transform | categorify | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,919 | scores = []
tr_scores = []
for train_index, test_index in skf.split(train, y):
train_df = train.loc[train_index,col4train].reset_index(drop = True)
valid_df = train.loc[test_index,col4train].reset_index(drop = True)
train_y, valid_y = y[train_index], y[test_index]
te = TargetEncodingExpandingMean(column... | Yes | 2 | 7 | Model_Train | train_model | 3,414,311 | 1 | A | 0 | 1 | 1 | 0 | 0 | 18 | ok | 16 | 10 | [{"detector": "framework_specific", "framework": "NumPy", "name": "Missing Axis Specification", "fix": "Specify axis in array operations.", "benefits": "Improves performance and avoids unexpected behaviour.", "location": "Line 28"}, {"detector": "framework_specific", "framework": "NumPy", "name": "Missing Axis Specific... | D | Cross Validation Checker=low, Cross-validation not detected=low, Data Leakage Checker=high, Missing Axis Specification=medium, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}, {"type": "Missing Axis Specification", "severity": "medium"}, {"type": "No random seed setting detected", "severity": "low"}] | ["Column Selection Checker", "Exception Handling Checker", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker", "Verbose Mode Checker"] | 6 | D |
2,920 | train[col4train] = train[col4train].values.astype(str)
test[col4train] = test[col4train].values.astype(str)
from itertools import combinations
new_col4train = col4train
for c1,c2 in combinations(col4train, 2):
name = "{}_{}".format(c1,c2)
new_col4train.append(name)
train[name] = train[c1] + "_" + train[c2]... | No | 3 | 78 | Data_Transform | string_transform | 3,414,311 | 1 | A | 0 | 1 | 1 | 0 | 0 | 9 | 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"] | 6 | B |
2,921 | print(train[new_col4train].shape, test[new_col4train].shape)
train[new_col4train].head(5) | No | 4 | 58 | Debug | show_shape | 3,414,311 | 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"] | 6 | B |
2,922 | train[new_col4train].apply(lambda x: len(x.unique())) | No | 5 | 54 | EDA | count_unique_values | 3,414,311 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Valida... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Column Selection Checker"] | 6 | B |
2,923 | scores = []
tr_scores = []
for train_index, test_index in skf.split(train, y):
train_df = train.loc[train_index,new_col4train].reset_index(drop = True)
valid_df = train.loc[test_index,new_col4train].reset_index(drop = True)
train_y, valid_y = y[train_index], y[test_index]
te = TargetEncodingExpandingMea... | Yes | 1 | 7 | Model_Train | train_model | 3,414,311 | 1 | A | 0 | 1 | 1 | 0 | 0 | 27 | ok | 19 | 10 | [{"detector": "framework_specific", "framework": "NumPy", "name": "Missing Axis Specification", "fix": "Specify axis in array operations.", "benefits": "Improves performance and avoids unexpected behaviour.", "location": "Line 40"}, {"detector": "framework_specific", "framework": "NumPy", "name": "Missing Axis Specific... | D | Cross Validation Checker=low, Cross-validation not detected=low, Data Leakage Checker=high, Missing Axis Specification=medium, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}, {"type": "Missing Axis Specification", "severity": "medium"}, {"type": "No random seed setting detected", "severity": "low"}] | ["Column Selection Checker", "Exception Handling Checker", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker", "Verbose Mode Checker"] | 6 | D |
2,924 | te = TargetEncodingExpandingMean(columns_names=new_col4train)
X_tr = te.fit_transform(train[new_col4train], y)
X_val = te.transform(test[new_col4train])
te2 = TargetEncodingSmoothing(
columns_names= new_col4train,
k = 3, f = 1.5,
)
X_tr2 = get_CV_target_encoding(train[new_col4train], y, te2, cv = 5)
te2.fit(... | Yes | 1 | 7 | Model_Train | train_model | 3,414,311 | 1 | A | 0 | 0 | 0 | 0 | 0 | 19 | ok | 17 | 10 | [{"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... | D | Cross Validation Checker=low, Cross-validation not detected=low, Data Leakage Checker=high, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}, {"type": "No random seed setting detected", "severity": "low"}] | ["Column Selection Checker", "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", "Verbose Mode Checker"] | 6 | D |
2,925 | import numpy as np
import pandas as pd
import os
print(os.listdir("../input"))
| No | 5 | 88 | Debug | list_files | 4,374,092 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 1 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path detected: ../input. Consider using configuration files or environment variables.", "fix": "Not specified", "benefits": "Not specified", "location": "Line 11"}] | A | no applicable ML-specific findings | [] | ["Hardcoded file path"] | 6 | A |
2,926 | train = pd.read_csv('../input/train.csv')
test = pd.read_csv('../input/test.csv') | No | 5 | 45 | Data_Extraction | load_from_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,927 | id=test.iloc[:,0].values
test.drop('id',axis=1) | No | 5 | 10 | Data_Transform | drop_column | 4,374,092 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 6 | A |
2,928 | id | No | 5 | 53 | Other | something_strange | null | 1 | A | 0 | 0 | 0 | 1 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,929 | X = train.iloc[:, 1:11].values
y = train.iloc[:, 0].values | No | 5 | 21 | Data_Transform | prepare_x_and_y | 4,374,092 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 6 | A |
2,930 | from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0) | No | 5 | 13 | Data_Transform | split | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}] | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | [] | 0 | B |
2,931 | from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test) | No | 5 | 18 | Data_Transform | normalization | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 9 | 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 |
2,932 | # Fitting Random Forest Classification to the Training set
from sklearn.ensemble import RandomForestClassifier
classifier = RandomForestClassifier(n_estimators = 99, criterion = 'entropy', random_state = 0)
classifier.fit(X_train, y_train) | Yes | 3 | 7 | Model_Train | train_model | 4,374,092 | 2 | B | 1 | 0 | 0 | 0 | 5 | 3 | ok | 6 | 5 | [{"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"}] | ["Dependent Threshold Checker", "Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 6 | B |
2,933 | y_pred = classifier.predict(X_test) | No | 5 | 48 | Model_Evaluation | predict_on_test | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,934 | from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred) | No | 5 | 49 | Model_Evaluation | compute_test_metric | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 0 | A |
2,935 | cm | No | 5 | 53 | Other | something_strange | null | 1 | A | 0 | 0 | 0 | 1 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,936 | #for calculating accuracy
(131+6090)/(131+6090+92+241) | No | 5 | 53 | Other | something_strange | 4,374,092 | 1 | A | 0 | 0 | 0 | 1 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 6 | A |
2,937 | test.drop(['id'], axis=1, inplace = True) | No | 5 | 10 | Data_Transform | drop_column | 4,374,092 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "Pandas", "name": "InPlace Checker", "fix": "Assign operations to a new DataFrame variable.", "benefits": "Prevents data loss and improves code clarity.", "location": "Line 7"}] | A | no applicable ML-specific findings | [] | ["InPlace Checker"] | 6 | A |
2,938 | test | 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 |
2,939 | test_pred = classifier.predict(test) | No | 5 | 48 | Model_Evaluation | predict_on_test | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,940 | test_pred | 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 |
2,941 | submission = pd.DataFrame({'Id':id,'Action':test_pred}) | No | 5 | 12 | Data_Transform | create_dataframe | 4,374,092 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 6 | A |
2,942 | final_submission=submission.iloc[0:58921,:].values | No | 5 | 14 | Data_Transform | filter | 4,374,092 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 6 | A |
2,943 | final_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 |
2,944 | final_submission = pd.DataFrame({'Id':final_submission[:,0],'Action':final_submission[:,-1]}) | No | 5 | 12 | Data_Transform | create_dataframe | 4,374,092 | 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"] | 6 | A |
2,945 | filename = 'Amazon Employee Access .csv'
final_submission.to_csv(filename,index=False)
print('Saved file: ' + filename) | No | 4 | 25 | Data_Export | save_to_csv | 4,374,092 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 6 | A |
2,946 | import seaborn as sns
import numpy as np # linear algebra
import pandas as pd
from sklearn.metrics import confusion_matrix
from sklearn.metrics import f1_score
from sklearn.metrics import accuracy_score
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_tes... | No | 5 | 22 | Environment | import_modules | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 21 | ok | 1 | 1 | [{"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": ""}] | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker"] | 0 | A |
2,947 | train_file_path = '/kaggle/input/covid19-global-forecasting-week-2/train.csv'
test_file_path = '/kaggle/input/covid19-global-forecasting-week-2/test.csv'
train_dataset = pd.read_csv(train_file_path)
test_dataset = pd.read_csv(test_file_path)
| No | 5 | 45 | Data_Extraction | load_from_csv | 8,689,318 | 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."] | 4 | A |
2,948 | print("Understanding of Train Dataset:\
\
\
")
print('Train Dataset has following states:\
')
province_state = train_dataset['Province_State'].unique()
print(province_state)
print('\
\
\
Train Dataset has following Country Region:\
')
country_region = train_dataset['Country_Region'].unique()
print(country_region)
... | No | 3 | 16 | Data_Transform | data_type_conversions | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,949 | print("Understanding of Test Dataset:\
\
\
")
print('Test Dataset has following states:\
')
province_state = test_dataset['Province_State'].unique()
print(province_state)
print('\
\
\
Test Dataset has following Country Region:\
')
country_region = test_dataset['Country_Region'].unique()
print(country_region)
print... | No | 4 | 57 | Debug | show_unique_values | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,950 | print("Train Dataset Graphical Representation of Counrtry Region w.r.t. Confirmed Cases")
show_cumulatively = train_dataset.groupby(by='Country_Region')[['ConfirmedCases','Fatalities']].max().reset_index()
plt.figure(figsize=(20,10))
#sns.set()
sns.barplot(x='ConfirmedCases',y='Country_Region',data=show_cumulatively[sh... | No | 4 | 81 | Visualization | relationship | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,951 |
print("Train Dataset Graphical Representation of Counrtry Region w.r.t. Fatalities")
plt.figure(figsize=(20,10))
sns.barplot(x='Fatalities',y='Country_Region',data=show_cumulatively[show_cumulatively['Fatalities'] != 0].sort_values(by='Fatalities',ascending=False).head(50))' | No | 4 | 81 | Visualization | relationship | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,952 | print('Those Country Regions of Train Dataset whose Confirmed Cases have Fatalities')
non_fatalities_train_df = train_dataset[train_dataset['Fatalities'] != 0]
non_fatalities_train_df[['Country_Region','Date','ConfirmedCases','Fatalities']] | No | 4 | 71 | Debug | show_columns | 8,689,318 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 4 | A |
2,953 | print('Those Country Regions whose Confirmed Cases have not Fatalities')
non_fatalities_train_df = train_dataset[train_dataset['Fatalities'] == 0]
non_fatalities_train_df[['Country_Region','Date','ConfirmedCases','Fatalities']] | No | 3 | 71 | Debug | show_columns | 8,689,318 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 4 | A |
2,954 | b"print('The value count of Country Regions of Non-Null Province States in Train Dataset')\nprint(train_dataset[~train_dataset['Province_State'].isnull()]['Country_Region'].value_counts())\n\n\nprint('\\n\\n\\nThe value count of Country Regions of Null Province States in Train Dataset')\nprint(train_dataset[train_datas... | No | 5 | 39 | EDA | count_missing_values | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,955 | b"print('The value count of Country Regions of Non-Null Province States in Test Dataset')\nprint(test_dataset[~test_dataset['Province_State'].isnull()]['Country_Region'].value_counts())\n\n\nprint('\\n\\n\\nThe value count of Country Regions of Null Province States in Test Dataset')\nprint(test_dataset[test_dataset['Pr... | No | 5 | 39 | EDA | count_missing_values | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,956 | print("Train dataset before pre-processing:\
")
print(train_dataset.head())
train_dataset = train_dataset.fillna('Enpyty_value')
print("\
\
\
Train dataset after pre-processing:\
")
print(train_dataset.head())' | No | 4 | 17 | Data_Transform | correct_missing_values | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,957 | print("Test dataset before pre-processing:\
")
print(test_dataset.head())
test_dataset = test_dataset.fillna('Enpyty_value')
print("\
\
\
Test dataset after pre-processing:\
")
print(test_dataset.head())' | No | 4 | 17 | Data_Transform | correct_missing_values | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,958 | labelEncoder = LabelEncoder()
train_dataset['Date'] = pd.to_datetime(train_dataset['Date']).dt.strftime("%m%d").astype(int)
train_dataset['Date'] -= 122
test_dataset['Date'] = pd.to_datetime(test_dataset['Date']).dt.strftime("%m%d").astype(int)
test_dataset['Date'] -= 122
train_dataset.Province_State = labelEncode... | 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 |
2,959 | #We don't need to convert it into vector because it is alreayd in vector form. See following
print(train_dataset.head())
print(test_dataset.head())
| No | 4 | 84 | Other | not_enough_vertices | 8,689,318 | 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"}] | [] | 4 | B |
2,960 | X = train_dataset[['Province_State','Country_Region','Date']]
y = train_dataset[['ConfirmedCases','Fatalities']]
classifier = BinaryRelevance(GaussianNB())
# train
classifier.fit(X, y[['Fatalities']])
# predict
predictions_fatalities = classifier.predict(test_dataset[['Province_State','Country_Region','Date']])
# t... | No | 3 | 7 | Model_Train | train_model | 8,689,318 | 1 | A | 0 | 0 | 0 | 0 | 0 | 7 | ok | 11 | 7 | [{"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, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "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", "Verbose Mode Checker"] | 4 | B |
2,961 | output_confirmed_cases_df = pd.DataFrame(data=predictions_confirmed_cases.toarray())
output_fatalities_df = pd.DataFrame(data=predictions_fatalities.toarray())
output_confirmed_cases_df = output_confirmed_cases_df.rename(columns={0: "ConfirmedCases"})
output_fatalities_df = output_fatalities_df.rename(columns={0: "Fat... | No | 5 | 55 | Data_Export | prepare_output | 8,689,318 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 5 | 4 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Unit Testing Checker", "fix": "Write unit tests for data processing and model components.", "benefits": "Ensures code reliability and prevents bugs.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Excepti... | B | No random seed setting detected=low | [{"type": "No random seed setting detected", "severity": "low"}] | ["Exception Handling Checker", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker"] | 4 | B |
2,962 | test_dataset.ForecastId | No | 4 | 84 | Other | not_enough_vertices | 8,689,318 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 4 | A |
2,964 | result.to_csv('submission.csv', index=False)
| No | 5 | 25 | Data_Export | save_to_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,965 | filepath= '/kaggle/input/amazon-employee-access-challenge/train.csv'
traindata= pd.read_csv(filepath)
filepath2= '/kaggle/input/amazon-employee-access-challenge/test.csv'
testdata= pd.read_csv(filepath2)
testdatacopy=testdata
traindata.head() | No | 4 | 45 | Data_Extraction | load_from_csv | 10,307,360 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | 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"}] | ["Dependent Threshold Checker", "Hardcoded file path", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness."] | 15 | B |
2,966 | ##Thus we see that there are no null values
sns.heatmap(traindata.isnull(),yticklabels=False,cbar=False,cmap='viridis') | No | 5 | 80 | Visualization | heatmap | 10,307,360 | 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": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Dependent Threshold Checker"] | 15 | B |
2,967 | #Now we plot the number of people who were granted access
sns.set_style('whitegrid')
sns.countplot(x='ACTION',data=traindata,palette='RdBu_r') | No | 5 | 33 | Visualization | distribution | 10,307,360 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 1 | 1 | [{"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": ""}] | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker"] | 15 | A |
2,968 | y=traindata['ACTION']
x=traindata.drop('ACTION',axis=1)
#Splitting training and testing data
x_train, x_test, y_train, y_test = train_test_split(x, y, train_size=0.70,test_size=0.30, random_state=0) | No | 4 | 21 | Data_Transform | prepare_x_and_y | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,969 | #Logistic Regression
LogisticRegressor = LogisticRegression(max_iter=10000)
LogisticRegressor.fit(x_train, y_train)
y_predicted = LogisticRegressor.predict(x_test)
mse = mean_squared_error(y_test, y_predicted)
r = r2_score(y_test, y_predicted)
mae = mean_absolute_error(y_test,y_predicted)
print("Mean Squared Error:",ms... | 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 |
2,970 | # Random Forest
rf = RandomForestClassifier()
rf.fit(x_train,y_train);
y_predicted_r = rf.predict(x_test)
mse = mean_squared_error(y_test, y_predicted_r)
r = r2_score(y_test, y_predicted_r)
mae = mean_absolute_error(y_test,y_predicted_r)
print("Mean Squared Error:",mse)
print("R score:",r)
print("Mean Absolute Error:",... | 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 |
2,971 | # Decision Tree - CART
regressor = DecisionTreeRegressor(random_state = 0)
regressor.fit(x_train, y_train)
y_predicted_d = regressor.predict(x_test)
mse = mean_squared_error(y_test, y_predicted_d)
r = r2_score(y_test, y_predicted_d)
mae = mean_absolute_error(y_test,y_predicted_d)
print("Mean Squared Error:",mse)
print(... | 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 |
2,972 | #XGBClassifier
xgboost = XGBClassifier(n_estimators=1000)
xgboost.fit(x_train,y_train)
xg_pred = xgboost.predict(x_test)
msee21 = mean_squared_error(y_test, xg_pred)
ra21 = r2_score(y_test, xg_pred)
maee21 = mean_absolute_error(y_test,xg_pred)
print("Mean Squared Error:",msee21)
print("R score:",ra21)
print("Mean Absol... | No | 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 |
2,973 | #SVM
svclassifier = SVC(kernel='linear')
svclassifier.fit(x_train, y_train)
y_pred2 = svclassifier.predict(x_test)
mseew = mean_squared_error(y_test, y_pred2)
ra = r2_score(y_test, y_pred2)
maeew = mean_absolute_error(y_test,y_pred2)
print("Mean Squared Error:",mseew)
print("R score:",ra)
print("Mean Absolute Error:"... | 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 |
2,974 | #Naive Bayes
gnb = GaussianNB()
y_preed = gnb.fit(x_train, y_train).predict(x_test)
ms = mean_squared_error(y_test, y_preed)
rae = r2_score(y_test, y_preed)
mew = mean_absolute_error(y_test,y_preed)
print("Mean Squared Error:",ms)
print("R score:",rae)
print("Mean Absolute Error:",mew)
print('f1 score:')
print(f1_sc... | 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 |
2,975 | #KNN
math.sqrt(len(y_test))
#Therefore n neighbors=99
| No | 5 | 53 | Other | something_strange | 10,307,360 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 1 | 1 | [{"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": ""}] | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker"] | 15 | A |
2,976 | #KNN
classify= KNeighborsClassifier (n_neighbors=99, p =2, metric= 'euclidean')
classify.fit(x_train,y_train)
ypred1=classify.predict(x_test)
msee = mean_squared_error(y_test, ypred1)
r = r2_score(y_test, y_predicted_d)
maee = mean_absolute_error(y_test,ypred1)
print("Mean Squared Error:",msee)
print("R score:",r)
pri... | No | 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 |
2,977 | testdata=testdata.drop('id',axis=1) | No | 5 | 10 | Data_Transform | drop_column | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,978 | # Random Forest
rf = RandomForestClassifier()
rf.fit(x,y)
Prediction = rf.predict(testdata)
| Yes | 3 | 7 | Model_Train | train_model | 10,307,360 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 11 | 9 | [{"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, Randomness Control Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}, {"type": "Randomness Control Checker", "severity": "low"}] | ["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", "Verbose Mode Checker"] | 15 | B |
2,979 | predictionlist=Prediction.tolist()
Passengerid=testdatacopy['id'].tolist()
output=pd.DataFrame(list(zip(Passengerid, predictionlist)),
columns=['id','Action'])
output.head()
output.to_csv('my_submission(AmazonEmployeeAccess).csv', index=False) | No | 3 | 25 | Data_Export | save_to_csv | 10,307,360 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | 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": "Dependent Th... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Dependent Threshold Checker"] | 15 | A |
2,980 | plt.figure(figsize=(25,12))
mask = np.zeros_like(df.corr())
mask[np.triu_indices_from(mask)] = True
sns.heatmap(df.corr(), cmap='coolwarm', vmax=1.0, vmin=-1.0 , mask = mask, linewidths=2.5)
plt.show() | No | 5 | 80 | Visualization | heatmap | 2,095,107 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "NumPy", "name": "Array Creation Efficiency", "fix": "Specify dtype when creating arrays.", "benefits": "Improves memory efficiency and avoids unnecessary conversions.", "location": "Line 8"}, {"detector": "framework_specific", "framework": "Pandas", "name": "Column Sele... | A | no applicable ML-specific findings | [] | ["Array Creation Efficiency", "Column Selection Checker"] | 6 | A |
2,981 | df_train = df[df['part']== 'train'] | No | 5 | 14 | Data_Transform | filter | 2,095,107 | 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"] | 6 | A |
2,982 | cols_train = ['Store', 'DayOfWeek', 'Date', 'Sales', 'Promo','PromoOpen',
# 'shift_sales','shift_t7_sales', 'shift_t30_sales','shift_customer','shift_t7_customer', 'shift_t30_customer',
'StateHoliday', 'SchoolHoliday', 'StoreType', 'Assortment',
'CompetitionDistance', 'Promo2', 'Mont... | No | 5 | 77 | Other | define_variables | 2,095,107 | 1 | A | 0 | 0 | 0 | 0 | 0 | 11 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 6 | A |
2,983 | params = {"objective": "reg:linear", # for linear regression
"booster" : "gbtree", # use tree based models
"eta": 0.02, # learning rate
"max_depth": 11, # maximum depth of a tree
"subsample": 0.9, # Subsample ratio of the training instances
"colsample_bytree"... | No | 4 | 23 | Environment | set_options | null | 1 | A | 0 | 1 | 0 | 0 | 0 | 16 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,984 | tmp= pd.pivot_table(data, ['Date'], "Store", aggfunc="count").reset_index().sort_values('Date', ascending=False).head(300)
top_stores = tmp["Store"].values' | 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 |
2,985 | # from sklearn.manifold import TSNE
# from sklearn.preprocessing import StandardScaler
def process(x, cols=None, all_stores=False):
x.sort_values("Date",inplace=True)
# scaler = StandardScaler()
if cols is None:
cols = x.columns
x = x.fillna(x.median())
# for i in x.c... | Yes | 4 | 1 | Hyperparam_Tuning | find_best_score | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
2,986 | fig, ax = plt.subplots(5, 2, figsize=(25, 15))
X = df_train[df_train['Store'].isin(top_stores)] .copy()
X_train_col, X_train_arr, Y_train, X_test, X_test_arr = process(X, cols_train, True)
dtrain = xgb.DMatrix(X_train_arr, Y_train)
estimator = xgb.train(params, dtrain, num_boost_round, feval=rmspe_xg,)
Y_pred = estim... | Yes | 3 | 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 |
2,987 | import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import seaborn as sns
%matplotlib inline
np.random.seed(2)
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix
import itertools
from keras.utils.np_utils import to_cate... | No | 5 | 23 | Environment | set_options | 3,344,044 | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
2,988 | ### load data
train = pd.read_csv('../input/training/training.csv')
test = pd.read_csv('../input/test/test.csv')
sample = pd.read_csv('../input/SampleSubmission.csv')
look_id = pd.read_csv('../input/IdLookupTable.csv') | No | 5 | 45 | Data_Extraction | load_from_csv | 3,344,044 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
2,989 | train.tail().T | No | 5 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.