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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
7,381 | from sklearn.model_selection import train_test_split | No | 5 | 22 | Environment | import_modules | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 0 | A |
7,382 | X = pd.concat([train[col_interval],train[col_ordinal],pd.get_dummies(train[col_binary])], axis=1)
y = pd.DataFrame(train.target)
X.fillna(-1, inplace=True)
y.fillna(-1, inplace=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) | Yes | 3 | 21 | Data_Transform | prepare_x_and_y | 1,881,540 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 5 | 4 | [{"detector": "framework_specific", "framework": "Pandas", "name": "InPlace Checker", "fix": "Assign operations to a new DataFrame variable.", "benefits": "Prevents data loss and improves code clarity.", "location": "Line 12"}, {"detector": "framework_specific", "framework": "Pandas", "name": "InPlace Checker", "fix": ... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Column Selection Checker", "Dependent Threshold Checker", "InPlace Checker"] | 9 | B |
7,383 | y.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 |
7,384 | X.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 |
7,385 | X.head() | No | 5 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
7,386 | plt.figure(figsize=(18,16))
plt.title('Pearson correlation of continuous features', y=1.05, size=15)
sns.heatmap(X.corr(),linewidths=0.1,vmax=1.0, square=True, cmap=colormap, linecolor='white', annot=False, fmt = '.1f') | No | 5 | 80 | Visualization | heatmap | 1,881,540 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | 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"] | 9 | A |
7,387 | from sklearn.ensemble import RandomForestClassifier<br>rf = RandomForestClassifier(n_estimators=150, max_depth=8, min_samples_leaf=30, max_features=0.2, n_jobs=-1, random_state=0)<br>rf.fit(X_train, y_train[\'target\'])<br>features = X_train.columns.values<br>print("----- Training Done -----") | No | 5 | 7 | Model_Train | train_model | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
7,388 | from sklearn.metrics import accuracy_score, roc_auc_score | No | 5 | 22 | Environment | import_modules | null | 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"] | 0 | A |
7,389 | acc = accuracy_score(y_train, rf.predict(X_train))
auc = roc_auc_score(y_train, rf.predict(X_train))
print("Accuracy: %.4f" % acc)
print("AUC: %.4f" % auc) | No | 5 | 28 | Model_Train | compute_train_metric | 1,881,540 | 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"] | 9 | B |
7,390 | acc = accuracy_score(y_test, rf.predict(X_test))
auc = roc_auc_score(y_test, rf.predict(X_test))
print("Accuracy: %.4f" % acc)
print("AUC: %.4f" % auc) | No | 5 | 49 | Model_Evaluation | compute_test_metric | 1,881,540 | 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"] | 9 | B |
7,391 | def get_feature_importance_df(feature_importances, <br> column_names, <br> top_n=25):<br> """Get feature importance data frame.<br> <br> Parameters<br> ----------<br> feature_importances : numpy ndarray<br> Feature importances computed by an e... | No | 5 | 86 | Model_Interpretation | features_selection | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
7,392 | feature_importance = get_feature_importance_df(rf.feature_importances_, features)
feature_importance | No | 5 | 86 | Model_Interpretation | features_selection | 1,881,540 | 1 | A | 0 | 0 | 0 | 1 | 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"] | 9 | A |
7,393 | fig,ax = plt.subplots()<br>fig.set_size_inches(20,10)<br>sns.barplot(data=feature_importance[:10],x="feature",y="importance",ax=ax,color=default_color,)<br>ax.set(xlabel=\'Variable name\', ylabel=\'Importance\',title="Variable importances") | No | 5 | 79 | Visualization | model_coefficients | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
7,394 | from xgboost import XGBClassifier
from lightgbm import LGBMClassifier
from catboost import CatBoostClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier | No | 5 | 22 | Environment | import_modules | 1,881,540 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | 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"] | 9 | A |
7,395 | #RandomForest params
rf_params = {}
rf_params['n_estimators'] = 200
rf_params['max_depth'] = 6
rf_params['min_samples_split'] = 70
rf_params['min_samples_leaf'] = 30 | No | 5 | 59 | Model_Train | init_hyperparams | 1,881,540 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 6 | 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": "Dependent Th... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Dependent Threshold Checker", "Magic number"] | 9 | A |
7,396 | rf_model = RandomForestClassifier(**rf_params, random_state=29,n_jobs = -1) | No | 5 | 4 | Model_Train | choose_model_class | 1,881,540 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Verbose Mode Checker", "fix": "Enable verbose mode for long training processes.", "benefits": "Provides better insights into model training progress.", "location": "Line 10"}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": ... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Verbose Mode Checker"] | 9 | A |
7,397 | # XGBoost params
xgb_params = {}
xgb_params['learning_rate'] = 0.02
xgb_params['n_estimators'] = 1000
xgb_params['max_depth'] = 4
xgb_params['subsample'] = 0.9
xgb_params['colsample_bytree'] = 0.9 | No | 5 | 59 | Model_Train | init_hyperparams | 1,881,540 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | ok | 7 | 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": "Dependent Th... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Dependent Threshold Checker", "Magic number"] | 9 | A |
7,398 | XGB_model = XGBClassifier(**rf_params, random_state=29,n_jobs=-1) | No | 5 | 4 | Model_Train | choose_model_class | 1,881,540 | 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"] | 9 | A |
7,399 | def create_extra_features(train_ext):
train_ext['null_sum'] = train_ext[train_ext==-1].count(axis=1)
#train_ext['bin_sum'] = train_ext[col_binary].sum(axis=1)
train_ext['ord_sum'] = train_ext[col_ordinal].sum(axis=1)
train_ext['interval_median'] = train_ext[col_interval].sum(axis=1)
train_ext['ne... | No | 5 | 8 | Data_Transform | feature_engineering | 1,881,540 | 1 | A | 1 | 1 | 0 | 0 | 5 | 7 | 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... | 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", "Dependent Threshold Checker", "Missing function docstring"] | 9 | B |
7,400 | ids_targets = meta_data[meta_data['role'] != 'input'].index | No | 5 | 77 | Other | define_variables | 1,881,540 | 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": "Dependent Th... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Dependent Threshold Checker"] | 9 | A |
7,401 | train_ext.head() | No | 5 | 41 | Debug | show_table | 1,881,540 | 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"] | 9 | B |
7,402 | test_ext.head() | No | 5 | 41 | Debug | show_table | 1,881,540 | 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"] | 9 | A |
7,403 | train_ext.fillna(-1, inplace = True)
X_ext = pd.concat([train_ext[col_interval],train_ext[col_ordinal], pd.get_dummies(train_ext[col_binary])], axis=1)
X_ext.head() | Yes | 3 | 17 | Data_Transform | correct_missing_values | 1,881,540 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 4 | 4 | [{"detector": "framework_specific", "framework": "Pandas", "name": "InPlace Checker", "fix": "Assign operations to a new DataFrame variable.", "benefits": "Prevents data loss and improves code clarity.", "location": "Line 10"}, {"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker"... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Column Selection Checker", "Dependent Threshold Checker", "InPlace Checker"] | 9 | B |
7,404 | X_ext = X_ext.drop(columns = ['facebook_profile_False','gender_f'], axis=1) | No | 5 | 10 | Data_Transform | drop_column | 1,881,540 | 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"] | 9 | A |
7,405 | test_ext = pd.concat([test_ext[col_interval],test_ext[col_ordinal], pd.get_dummies(test_ext[col_binary])], axis=1)
test_ext.fillna(-1, inplace = True)
#X_ext = X_ext.drop(columns = ids_targets, axis =1)
y_ext = pd.DataFrame(train_ext.target) #train_lc.target_default.ravel(order='K') #pd.DataFrame(train_ext.target)
y_ex... | Yes | 3 | 21 | Data_Transform | prepare_x_and_y | 1,881,540 | 1 | A | 1 | 0 | 0 | 0 | 5 | 6 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "Pandas", "name": "InPlace Checker", "fix": "Assign operations to a new DataFrame variable.", "benefits": "Prevents data loss and improves code clarity.", "location": "Line 11"}, {"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker"... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Dependent Threshold Checker", "InPlace Checker"] | 9 | A |
7,406 | cols = list(X_ext)
test_ext = test_ext[cols] | No | 5 | 77 | Other | define_variables | 1,881,540 | 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": "Dependent Th... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Dependent Threshold Checker"] | 9 | A |
7,407 | X_ext.head() | No | 5 | 41 | Debug | show_table | 1,881,540 | 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"] | 9 | A |
7,408 | from sklearn.utils.multiclass import type_of_target
type_of_target(y_ext) | No | 4 | 70 | Debug | show_data_types | 1,881,540 | 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"] | 9 | A |
7,409 | X_ext.shape | No | 5 | 58 | Debug | show_shape | 1,881,540 | 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"] | 9 | A |
7,410 | test_ext.shape | No | 5 | 58 | Debug | show_shape | 1,881,540 | 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"] | 9 | A |
7,411 | X_train, X_test, y_train, y_test = train_test_split(X_ext, y_ext, test_size=0.2, random_state=42) | No | 5 | 13 | Data_Transform | split | 1,881,540 | 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"] | 9 | B |
7,412 | from sklearn.model_selection import GridSearchCV | No | 5 | 22 | Environment | import_modules | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 0 | A |
7,413 | tuned_parameters = [{'max_depth': [4,5,6,7,8,9,10],
'max_features': [4,5,6,7,8,9,10],
'n_estimators':[10,25,50,75]}]
clf = GridSearchCV(RandomForestClassifier(random_state=29), tuned_parameters, cv=3, scoring='roc_auc')
clf.fit(X_train, y_train) | No | 5 | 6 | Hyperparam_Tuning | train_on_grid | 1,881,540 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 7 | 4 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Verbose Mode Checker", "fix": "Enable verbose mode for long training processes.", "benefits": "Provides better insights into model training progress.", "location": "Line 14"}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": ... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 9 | A |
7,414 | from hyperopt.pyll.base import scope
from hyperopt.pyll.stochastic import sample
from hyperopt import STATUS_OK, Trials, fmin, hp, tpe | No | 5 | 22 | Environment | import_modules | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
7,415 | import random
import itertools
N_HYPEROPT_PROBES = 10
EARLY_STOPPING = 80
HOLDOUT_SEED = 123456
HOLDOUT_SIZE = 0.10
HYPEROPT_ALGO = tpe.suggest # tpe.suggest OR hyperopt.rand.suggest
DATASET = 'clean' # 'raw' | 'clean' | 'extended'
SEED0 = random.randint(1,1000000000)
NB_CV_FOLDS = 5 | No | 5 | 59 | Model_Train | init_hyperparams | 1,881,540 | 1 | A | 0 | 0 | 0 | 0 | 0 | 10 | ok | 6 | 2 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Threshold Checker", "fix": "Use threshold-independent metrics alongside threshold-dependent ones.", "benefits": "Provides a comprehensive evaluation of model performance.", "location": ""}, {"detector": "general_ml", "framework": "Genera... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Magic number"] | 9 | A |
7,416 | obj_call_count = 0
cur_best_score = 0 | No | 5 | 77 | Other | define_variables | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
7,417 | space_RF ={<br> \'n_estimators\' : hp.choice(\'n_estimators\', np.arange(10, 200, dtype=int)), <br> \'max_depth\' : hp.choice("max_depth", np.arange(3, 15, dtype=int)),<br> \'min_samples_split\' : hp.choice("min_samples_split", np.arange(20, 100, d... | No | 5 | 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 |
7,418 | space_XGB ={<br> \'max_depth\' : hp.choice("max_depth", np.arange(5, 15,dtype=int)), <br> \'learning_rate\' : hp.loguniform(\'learning_rate\', -4.9, -3.0),<br> \'n_estimators\' : hp.choice(\'n_estimators\', np.arange(10, 100,dtype=int)),<br> \'objective\' : \'binary:logistic\',<br> \... | No | 5 | 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 |
7,419 | train_stack = train_backup.copy()
test_stack = test_backup.copy() | No | 5 | 12 | Data_Transform | create_dataframe | 1,881,540 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Dependent Threshold Checker"] | 9 | B |
7,420 | train_stack.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 |
7,421 | test_stack.shape | No | 5 | 58 | Debug | show_shape | 1,881,540 | 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"] | 9 | A |
7,422 | meta_data = get_meta(train_stack)
col_ordinal = meta_data[(meta_data.level == 'ordinal') & (meta_data.keep)& (meta_data.role != 'target')].index
col_nominal = meta_data[(meta_data.level == 'nominal') & (meta_data.keep)& (meta_data.role != 'target')].index
col_interval = meta_data[(meta_data.level == 'interval') & (... | No | 5 | 14 | Data_Transform | filter | 1,881,540 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Th... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Dependent Threshold Checker"] | 9 | A |
7,423 | train_stack = train_stack.replace(-1, np.NaN)
d_median = train_stack.median(axis=0)
d_mean = train_stack.mean(axis=0)
train_stack = train_stack.fillna(-1) | No | 5 | 17 | Data_Transform | correct_missing_values | 1,881,540 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 4 | 4 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low, 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"}] | ["Dependent Threshold Checker"] | 9 | B |
7,424 | from sklearn import preprocessing | No | 5 | 22 | Environment | import_modules | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 0 | A |
7,425 |
train_stack = create_extra_features(train_stack)
test_stack = create_extra_features(test_stack)
train_stack['bin_sum'] = train_stack[col_binary].sum(axis=1)
test_stack['bin_sum'] = test_stack[col_binary].sum(axis=1) | No | 5 | 8 | Data_Transform | feature_engineering | 1,881,540 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Valida... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Column Selection Checker", "Dependent Threshold Checker"] | 9 | B |
7,426 | col = [c for c in train_stack.columns if c not in ['id','target']]
col = [c for c in col if not c.startswith('ps_calc_')] ## Droping ps_cal_ vars | No | 5 | 77 | Other | define_variables | 1,881,540 | 1 | A | 0 | 2 | 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"] | 9 | A |
7,427 | target_stack.shape | No | 5 | 58 | Debug | show_shape | 1,881,540 | 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"] | 9 | A |
7,428 | score = classifier.evaluate(test_x, test_y, verbose=0)
print('valid loss:', score[0])
print('valid accuracy:', score[1]) | No | 5 | 49 | Model_Evaluation | compute_test_metric | 1,915,708 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}] | A | no applicable ML-specific findings | [] | ["Column Selection Checker"] | 2 | A |
7,429 | import pandas as pd
aa = pd.read_csv('submission_file.csv')
aa
| Yes | 4 | 45 | Data_Extraction | load_from_csv | 1,915,708 | 1 | A | 0 | 0 | 0 | 1 | 0 | 3 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 2 | A |
7,430 | import numpy as np
import pandas as pd
from fastai.conv_learner import *
import os
# Input data files are available in the "../input/" directory.
# Any results you write to the current directory are saved as output.
PATH = "data/dogscats/" | No | 5 | 77 | Other | define_variables | 1,942,011 | 1 | A | 1 | 0 | 0 | 0 | 5 | 5 | ok | 1 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path detected: data/dogscats/. 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"] | 2 | A |
7,431 | # Image size, batch size and pretrained model architecture
sz=224
bs=20
arch=resnet50 | No | 5 | 77 | Other | define_variables | 1,942,011 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 2 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Magic number detected: 224", "fix": "Not specified", "benefits": "Not specified", "location": "Line 4"}, {"detector": "general_ml", "framework": "General ML", "name": "Magic number detected: 20", "fix": "Not specified", "benefits": "Not specified", "locati... | A | no applicable ML-specific findings | [] | ["Magic number"] | 2 | A |
7,432 | X_stack = pd.concat([train_stack[col_interval],train_stack[col_ordinal], pd.get_dummies(train_stack[col_binary])], axis=1)
test_stack_val = pd.concat([test_stack[col_interval],test_stack[col_ordinal], pd.get_dummies(test_stack[col_binary])], axis=1)
y_stack = target_stack | Yes | 4 | 21 | Data_Transform | prepare_x_and_y | 1,881,540 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | 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"] | 9 | A |
7,433 | X_stack.shape | No | 5 | 58 | Debug | show_shape | 1,881,540 | 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"] | 9 | A |
7,434 | test_stack_val.shape | No | 5 | 58 | Debug | show_shape | 1,881,540 | 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"] | 9 | A |
7,435 | X_stack = X_stack.drop(columns=['gender_-1','facebook_profile_-1'], axis = 1)
| No | 5 | 10 | Data_Transform | drop_column | 1,881,540 | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 9 | null |
7,436 | #RandomForest params<br>rf_params = {}<br>rf_params[\'n_estimators\'] = 80<br>rf_params[\'max_depth\'] = 12<br>rf_params[\'min_samples_split\'] = 50<br>rf_params[\'min_samples_leaf\'] = 23<br>#rf_params[\'class_weight\'] = "balanced_subsample"# "balanced" # "balanced_subsample"<br>#rf_params[\'criterion\'] = 1<br>#{\'c... | No | 5 | 59 | Model_Train | init_hyperparams | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
7,437 | # XGBoost params
xgb_params = {}
xgb_params['learning_rate'] =0.03660642032718193
xgb_params['n_estimators'] = 70
xgb_params['max_depth'] = 7
xgb_params['reg_alpha'] = 0.1
xgb_params['reg_lambda'] = 0.1
xgb_params['colsample_bytree'] = 0.6162725690461764
xgb_params['min_child_weight'] = 0.751826989118936
#{'colsample... | No | 5 | 59 | Model_Train | init_hyperparams | 1,881,540 | 1 | A | 1 | 0 | 0 | 0 | 5 | 8 | ok | 9 | 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": "Dependent Th... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Dependent Threshold Checker", "Magic number"] | 9 | A |
7,438 | rf_model = RandomForestClassifier(**rf_params, random_state=584867) | No | 5 | 4 | Model_Train | choose_model_class | 1,881,540 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Verbose Mode Checker", "fix": "Enable verbose mode for long training processes.", "benefits": "Provides better insights into model training progress.", "location": "Line 10"}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": ... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Verbose Mode Checker"] | 9 | A |
7,439 | xgb_model = XGBClassifier(**xgb_params, random_state=2943) | No | 5 | 4 | Model_Train | choose_model_class | 1,881,540 | 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"] | 9 | A |
7,440 | log_model = LogisticRegression(random_state=29) | No | 5 | 4 | Model_Train | choose_model_class | 1,881,540 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 2 | 2 | [{"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": "Dependent Thresh... | C | Scaler Missing Checker=medium | [{"type": "Scaler Missing Checker", "severity": "medium"}] | ["Dependent Threshold Checker"] | 9 | C |
7,441 | stack = Ensemble(n_splits=3,
stacker = log_model,
base_models = (rf_model, xgb_model)) | No | 5 | 4 | Model_Train | choose_model_class | 1,881,540 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | 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"] | 9 | A |
7,442 | X_stack.fillna(-1, inplace = True)
test_stack_val.fillna(-1,inplace=True)
y_pred = stack.fit_predict(X_stack, target_stack, test_stack_val) | Yes | 4 | 17 | Data_Transform | correct_missing_values | 1,881,540 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 7 | 6 | [{"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 10"}, {"detector": "framework_specific", "framework": "Pandas", "name": "InPlace Checker", "fix": ... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Dependent Threshold Checker", "Exception Handling Checker", "InPlace Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 9 | B |
7,443 | sub = pd.DataFrame()
sub['ids'] = test_id
sub['prob'] = y_pred
sub.to_csv('stacked_main.csv', index=False) | No | 5 | 25 | Data_Export | save_to_csv | 1,881,540 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | 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"] | 9 | A |
7,444 | # This Python 3 environment comes with many helpful analytics libraries installed<br># It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python<br># For example, here\'s several helpful packages to load in <br><br>import numpy as np # linear algebra<br>import pandas as pd # data processi... | No | 5 | 88 | Debug | list_files | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
7,445 | category_id_df | 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 |
7,446 | # The sorted function Converts dictionary items into a (sorted) list.
# In subsequent steps - We will use this list to iterate over the categories
sorted(category_to_id.items()) | No | 5 | 9 | Data_Transform | sort_values | null | 1 | A | 0 | 0 | 0 | 1 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
7,447 | # Store the entries into the results dataframe and name its columns
BBC Ncv_df = pd.DataFrame(entries, columns=['model_name', 'fold_idx', 'accuracy']) | No | 5 | 12 | Data_Transform | create_dataframe | 1,967,574 | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 9 | null |
7,448 | # Create submission file: 2 colmuns with header id, label
submission = pd.DataFrame({'id':os.listdir(f'{PATH}test1'), 'label':label_probs})
submission['id'] = submission['id'].map(lambda x: x.split('.')[0])
submission['id'] = submission['id'].astype(int)
submission = submission.sort_values('id')
submission.to_csv('../w... | Yes | 4 | 25 | Data_Export | save_to_csv | 1,942,011 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path d... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Hardcoded file path"] | 2 | A |
7,449 | # This Python 3 environment comes with many helpful analytics libraries installed<br># It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python<br># For example, here\'s several helpful packages to load in <br><br>import numpy as np # linear algebra<br>import pandas as pd # data processi... | No | 4 | 88 | Debug | list_files | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
7,450 | from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier
from sklearn.naive_bayes import MultinomialNB
from sklearn.model_selection import cross_val_score
models = [
RandomForestClassifier(n_estimators=200, max_depth=3, random_state=0),
MultinomialNB(),
Log... | No | 5 | 4 | Model_Train | choose_model_class | 1,967,701 | 1 | A | 1 | 0 | 0 | 0 | 5 | 9 | ok | 2 | 2 | [{"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": "Verbose Mode Che... | C | Scaler Missing Checker=medium | [{"type": "Scaler Missing Checker", "severity": "medium"}] | ["Verbose Mode Checker"] | 9 | C |
7,451 | # model.coef_ contains the importance of each feature for each category
model.coef_ | No | 5 | 79 | Visualization | model_coefficients | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
7,452 | test_df | 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 |
7,453 | test_df.head() | No | 5 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
7,454 | test_df.Text.tolist() | No | 5 | 16 | Data_Transform | data_type_conversions | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
7,455 | #translating text column into a list
test_features = tfidf.transform(test_df.Text.tolist())
Y_pred = model.predict(test_features)
Y_pred | Yes | 3 | 8 | Data_Transform | feature_engineering | 1,967,701 | 1 | A | 0 | 0 | 0 | 1 | 0 | 3 | 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"] | 9 | B |
7,456 | 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 |
7,457 | # This Python 3 environment comes with many helpful analytics libraries installed<br># It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python<br># For example, here\'s several helpful packages to load in <br><br>import numpy as np # linear algebra<br>import pandas as pd # data processi... | No | 4 | 45 | Data_Extraction | load_from_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
7,458 | vectorizer = TfidfVectorizer(sublinear_tf=True, min_df=5, norm=\'l2\', encoding=\'latin-1\', ngram_range=(1, 2), stop_words=\'english\')<br>X = vectorizer.fit_transform(data["Text"])<br>print(len(vectorizer.get_feature_names()))<br>print(X.shape) | Yes | 3 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
7,459 | tfidf = TfidfVectorizer(sublinear_tf=True, min_df=5, norm='l2', encoding='latin-1', ngram_range=(1, 2), stop_words='english')
features = tfidf.fit_transform(data.Text).toarray()
print(features)
labels = data.category_id
print(labels)
features.shape | Yes | 3 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
7,460 | from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier
from sklearn.naive_bayes import MultinomialNB
from sklearn.model_selection import cross_val_score
models = [
RandomForestClassifier(n_estimators=500, max_depth=4),
MultinomialNB(),
LogisticRegression(r... | Yes | 3 | 3 | Hyperparam_Tuning | find_best_model_class | null | 1 | A | 2 | 2 | 3 | 0 | 10 | 22 | ok | 6 | 6 | [{"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"}] | ["Exception Handling Checker", "Magic number", "Unit Testing Checker", "Verbose Mode Checker"] | 0 | C |
7,461 | model = models[2]
model.fit(features, labels)
model.coef_ | Yes | 3 | 7 | Model_Train | train_model | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
7,462 | test_data = pd.read_csv("../input/bbc-test-3/BBC News Test.csv")
test_data | No | 5 | 45 | Data_Extraction | load_from_csv | 1,967,841 | 1 | A | 0 | 0 | 0 | 1 | 0 | 2 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Threshold Checker", "fix": "Use threshold-independent metrics alongside threshold-dependent ones.", "benefits": "Provides a comprehensive evaluation of model performance.", "location": ""}, {"detector": "general_ml", "framework": "Genera... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Hardcoded file path"] | 11 | A |
7,463 | submission = pd.DataFrame({
"ArticleId": test_data["ArticleId"],
"Category": submission
})
submission | No | 5 | 55 | Data_Export | prepare_output | 1,967,841 | 1 | A | 0 | 0 | 0 | 1 | 0 | 5 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Th... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Dependent Threshold Checker"] | 11 | A |
7,464 | submission.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 |
7,465 | import numpy as np
import pandas as pd
import sklearn
import matplotlib.pyplot as plt | No | 5 | 22 | Environment | import_modules | 2,033,454 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 6 | A |
7,466 | train = pd.read_csv("../input/train.csv") | No | 5 | 45 | Data_Extraction | load_from_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
7,467 | Xtrain = train
Xtrain = Xtrain.drop(columns=["median_house_value"])
Xtrain.head() | Yes | 4 | 10 | Data_Transform | drop_column | 2,033,454 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | 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"}] | [] | 6 | B |
7,468 | from sklearn import linear_model
from sklearn.neighbors import KNeighborsRegressor | No | 5 | 22 | Environment | import_modules | 2,033,454 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 6 | A |
7,469 | ridge = linear_model.Ridge(alpha = 0.5)
ridge.fit(Xtrain,Ytrain)
ridge.coef_ | Yes | 3 | 7 | Model_Train | train_model | 2,033,454 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 4 | 4 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 6 | B |
7,470 | lasso = linear_model.Lasso(alpha = 0.1)
lasso.fit(Xtrain,Ytrain) | Yes | 4 | 7 | Model_Train | train_model | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
7,471 | KNNRegression = KNeighborsRegressor(n_neighbors=52)
KNNRegression.fit(Xtrain, Ytrain) | Yes | 4 | 7 | Model_Train | train_model | 2,033,454 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 4 | 4 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 6 | B |
7,472 | test = pd.read_csv("../input/test.csv")
test.head() | Yes | 4 | 45 | Data_Extraction | load_from_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
7,473 | pred.to_csv("prediction.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 |
7,474 | # This Python 3 environment comes with many helpful analytics libraries installed<br># It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python<br># For example, here\'s several helpful packages to load in <br><br>import numpy as np # linear algebra<br>import pandas as pd # data processi... | Yes | 3 | 45 | Data_Extraction | load_from_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
7,475 | import matplotlib.pyplot as plt
import matplotlib.cm as cm
from sklearn import linear_model, ensemble, neighbors
import numpy as np
import sympy as sp
import pandas as pd
from pylab import rcParams
from sklearn.metrics import r2_score
from sklearn.model_selection import cross_val_score
from sklearn.feature_selection im... | Yes | 4 | 22 | Environment | import_modules | 2,047,549 | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 3 | null |
7,476 | dataset = pd.read_csv(FOLDER+'train.csv') | No | 5 | 45 | Data_Extraction | load_from_csv | 2,047,549 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
7,477 | dataset.head() | No | 5 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
7,478 | dataset.mean() | No | 5 | 40 | Debug | show_table_attributes | 2,047,549 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
7,479 | dataset.std()/dataset.mean() | No | 5 | 40 | Debug | show_table_attributes | 2,047,549 | 1 | A | 0 | 0 | 0 | 1 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
7,480 | def add_features(dset):
mean_houses = pd.Series(dset['households']/dset['population'], name = 'mean_households')
rooms_ratio = pd.Series(dset['total_rooms']/dset['total_bedrooms'], name = 'ratio' )
return pd.concat([mean_houses, rooms_ratio, dset], axis = 1) | No | 5 | 8 | Data_Transform | feature_engineering | 2,047,549 | 1 | A | 0 | 1 | 0 | 0 | 0 | 4 | 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": "Missing docstring for... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Missing function docstring"] | 3 | A |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.