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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
6,703 | from sklearn.preprocessing import QuantileTransformer
sc = QuantileTransformer()
X = sc.fit_transform(X)
X_test = sc.transform(X_test) | No | 4 | 8 | Data_Transform | feature_engineering | 1,270,236 | 1 | A | 1 | 0 | 0 | 0 | 5 | 4 | ok | 9 | 8 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | D | Cross Validation Checker=low, Data Leakage Checker=high, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}, {"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"] | 7 | D |
6,704 | from sklearn.kernel_approximation import AdditiveChi2Sampler
sc = AdditiveChi2Sampler()
X = sc.fit_transform(X)
X_test = sc.transform(X_test) | No | 3 | 8 | Data_Transform | feature_engineering | 1,270,236 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 9 | 8 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | D | Cross Validation Checker=low, Data Leakage Checker=high, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}, {"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"] | 7 | D |
6,705 | from sklearn.ensemble import AdaBoostClassifier
clf = AdaBoostClassifier(n_estimators = 60 , learning_rate = 0.3)
clf.fit(X, Y)
Y_pred = clf.predict(X)
from sklearn.metrics import accuracy_score
accuracy_score(Y, Y_pred) | Yes | 3 | 4 | Model_Train | choose_model_class | 1,270,236 | 1 | A | 1 | 0 | 0 | 0 | 5 | 6 | ok | 10 | 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... | C | Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low, Only accuracy metric=medium | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}, {"type": "Only accuracy metric", "severity": "medium"}] | ["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"] | 7 | C |
6,706 | Y_test_pred = clf.predict(X_test) | No | 5 | 48 | Model_Evaluation | predict_on_test | 1,270,236 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Threshold Checker", "fix": "Use threshold-independent metrics alongside threshold-dependent ones.", "benefits": "Provides a comprehensive evaluation of model performance.", "location": ""}, {"detector": "framework_specific", "framework":... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Exception Handling Checker", "Unit Testing Checker"] | 7 | A |
6,707 | cols = { \'PlayerID\': [i+901 for i in range(440)] , \'TARGET_5Yrs\': Y_test_pred }<br>submission = pd.DataFrame(cols)<br>print(submission)<br><br>submission.to_csv("submission.csv", index=False) | Yes | 4 | 25 | Data_Export | save_to_csv | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,708 | import numpy as np
import pandas as pd
from sklearn.model_selection import KFold
from sklearn.metrics import accuracy_score
from sklearn.ensemble import AdaBoostClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.ensemble import AdaBoostClassifier
from sklearn.ensemble import GradientBoostingCl... | No | 5 | 22 | Environment | import_modules | 1,274,949 | 1 | A | 0 | 0 | 0 | 0 | 0 | 16 | 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 |
6,709 | data = pd.read_csv("../input/train.csv")
test = pd.read_csv("../input/test.csv")
submition = pd.read_csv("../input/sample_submission.csv") | No | 5 | 45 | Data_Extraction | load_from_csv | 1,274,949 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 5 | 3 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Threshold Checker", "fix": "Use threshold-independent metrics alongside threshold-dependent ones.", "benefits": "Provides a comprehensive evaluation of model performance.", "location": ""}, {"detector": "general_ml", "framework": "Genera... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Hardcoded file path", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness."] | 15 | A |
6,710 | input_label = np.array(data.get('TARGET_5Yrs'))
data = data.drop(['PlayerID','Name','TARGET_5Yrs'] ,axis=1)
data = data.fillna(data.mean())
test = test.drop(['PlayerID','Name'] ,axis=1)
test = test.fillna(test.mean()) | Yes | 3 | 10 | Data_Transform | drop_column | 1,274,949 | 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 16"}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Depen... | A | no applicable ML-specific findings | [] | ["Array Creation Efficiency", "Dependent Threshold Checker"] | 15 | A |
6,712 | quantile = QuantileTransformer(n_quantiles=3000)
data[np.array(data.columns[:])] = quantile.fit_transform(data[np.array(data.columns[:])])
test[np.array(test.columns[:])] = quantile.transform(test[np.array(test.columns[:])]) | No | 5 | 8 | Data_Transform | feature_engineering | 1,274,949 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 14 | 10 | [{"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 17"}, {"detector": "framework_specific", "framework": "NumPy", "name": "Array Creat... | D | Cross Validation Checker=low, Data Leakage Checker=high, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}, {"type": "No random seed setting detected", "severity": "low"}] | ["Array Creation Efficiency", "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"] | 15 | D |
6,717 | gradientBoosting_clf = GradientBoostingClassifier(n_estimators=350, learning_rate=.1,max_depth=1)
gradientBoosting_clf.fit(data,input_label)
gradientBoosting_given_labels = gradientBoosting_clf.predict(final) | Yes | 3 | 4 | Model_Train | choose_model_class | 1,274,949 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 10 | 8 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}] | ["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 |
6,718 | submition.iloc[:,1] = gradientBoosting_given_labels | No | 5 | 14 | Data_Transform | filter | 1,274,949 | 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 |
6,719 | submition.to_csv("submission_6.csv", index=False) | No | 5 | 25 | Data_Export | save_to_csv | 1,274,949 | 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 |
6,720 | #imports
import csv
import numpy as np
from sklearn import datasets
from sklearn import svm
from sklearn.preprocessing import Imputer
import pandas as pd
from sklearn.model_selection import cross_val_score
from sklearn import preprocessing
from sklearn import metrics
from sklearn.preprocessing import StandardScaler
fro... | No | 5 | 22 | Environment | import_modules | 1,275,111 | 1 | A | 0 | 0 | 0 | 0 | 0 | 11 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 18 | A |
6,721 | #reading datasets
train = pd.read_csv("../input/trainecsv/train.csv")
test = pd.read_csv("../input/iust-nba-rookies/test.csv")
# print(train.info())
#print(test.info()) | No | 5 | 45 | Data_Extraction | load_from_csv | 1,275,111 | 2 | B | 1 | 0 | 0 | 0 | 5 | 2 | 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."] | 18 | B |
6,722 | #DATA preporcessing
#standardizing
std_scale = preprocessing.StandardScaler().fit(train)
train_std = std_scale.transform(train)
test_std = std_scale.transform(test)
# #PCA
# pca_std = PCA(n_components=10).fit(train_std)
# train_stdwPCA = pca_std.transform(train_std)
# test_stdwPCA = pca_std.transform(test_std)
#nor... | No | 5 | 18 | Data_Transform | normalization | 1,275,111 | 1 | A | 1 | 0 | 0 | 0 | 5 | 5 | ok | 11 | 9 | [{"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... | E | Cross Validation Checker=low, Data Leakage Checker=high, Inconsistent scaling methods=high, No random seed setting detected=low, Pipeline Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}, {"type": "Inconsistent scaling methods", "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"] | 18 | E |
6,726 | # #KNN (3)
from sklearn.neighbors import KNeighborsClassifier
# #find best k for knn
# accs=[]
# ks=[]
# for k in range (1,50):
# Tknn=KNeighborsClassifier(n_neighbors=k)
# acc=cross_val_score(Tknn, train_normalized, train_labels, cv=10, scoring='accuracy')
# accs.append(acc.mean())
# ks.append(k)
# p... | Yes | 4 | 7 | Model_Train | train_model | 1,275,111 | 4 | D | 7 | 0 | 0 | 0 | 35 | 3 | ok | 8 | 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, Cross-validation not detected=low, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}] | ["Exception Handling Checker", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker", "Verbose Mode Checker"] | 18 | D |
6,727 | #MLP (4)
from sklearn.neural_network import MLPClassifier
MLP = MLPClassifier(solver='lbfgs', alpha=1e-5,hidden_layer_sizes=(25, 10), random_state=1).fit(train_normalized,train_labels)
trainpred=MLP.predict(train_normalized)
#testpred=MLP.predict(test_normalized)
#print(metrics.accuracy_score(train_labels, trainpred... | Yes | 3 | 7 | Model_Train | train_model | 1,275,111 | 4 | D | 4 | 0 | 0 | 0 | 20 | 3 | ok | 8 | 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, Cross-validation not detected=low, Randomness Control Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "Randomness Control 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"] | 18 | D |
6,730 | #GradientBoosting (7)
from sklearn.ensemble import GradientBoostingClassifier
GBC_clf = GradientBoostingClassifier(n_estimators=2000, learning_rate=0.008, max_depth=1, random_state=1).fit(train_normalized, train_labels)
trainpred=GBC_clf.predict(train_normalized)
#testpred=GBC_clf.predict(test_normalized)
#print(met... | Yes | 3 | 7 | Model_Train | train_model | 1,275,111 | 3 | C | 3 | 0 | 0 | 0 | 15 | 3 | ok | 9 | 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, Cross-validation not detected=low, Randomness Control Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "Randomness Control 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"] | 18 | C |
6,731 | #randomForest (8)
from sklearn.ensemble import RandomForestClassifier
random_forest_clf = RandomForestClassifier(n_estimators=100).fit(train_normalized,train_labels)
#acc_random_forest = cross_val_score(random_forest_clf, train, train_labels, cv=10, scoring='accuracy')
trainpred=random_forest_clf.predict(train_normal... | Yes | 3 | 7 | Model_Train | train_model | 1,275,111 | 4 | D | 5 | 0 | 0 | 0 | 25 | 3 | ok | 11 | 8 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low, 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"}] | ["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"] | 18 | D |
6,732 | #DecisionTree (9)
from sklearn.tree import DecisionTreeClassifier
DT_clf = DecisionTreeClassifier(max_depth=15, min_samples_split=3,random_state=6)
DT_clf.fit(train_normalized,train_labels)
trainpred=DT_clf.predict(train_normalized)
#testpred=DT_clf.predict(test_normalized)
#print(metrics.accuracy_score(train_labels... | Yes | 3 | 7 | Model_Train | train_model | 1,275,111 | 3 | C | 4 | 0 | 0 | 0 | 20 | 4 | ok | 7 | 6 | [{"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 | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not 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", "Verbose Mode Checker"] | 18 | C |
6,733 | # ExtraTreesClassifier (10)
from sklearn.ensemble import ExtraTreesClassifier
ET_clf = ExtraTreesClassifier(n_estimators=30, max_depth=12,min_samples_split=3, random_state=0)
ET_clf.fit(train_normalized,train_labels)
trainpred=ET_clf.predict(train_normalized)
#testpred=ET_clf.predict(test_normalized)
#print(metrics.... | Yes | 3 | 7 | Model_Train | train_model | 1,275,111 | 3 | C | 3 | 0 | 0 | 0 | 15 | 4 | ok | 7 | 6 | [{"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 | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not 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", "Verbose Mode Checker"] | 18 | C |
6,735 | #AdaBoost Classifier (12)
from sklearn.ensemble import AdaBoostClassifier
AdB_clf = AdaBoostClassifier(n_estimators=450)
AdB_clf.fit(train_normalized,train_labels)
trainpred=AdB_clf.predict(train_normalized)
#testpred=AdB_clf.predict(test_normalized)
#print(metrics.accuracy_score(train_labels, trainpred))
# AdB_acc... | Yes | 3 | 7 | Model_Train | train_model | 1,275,111 | 4 | D | 5 | 0 | 0 | 0 | 25 | 4 | ok | 8 | 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, Cross-validation not detected=low, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}] | ["Exception Handling Checker", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker", "Verbose Mode Checker"] | 18 | D |
6,738 | #voting <br>from sklearn.ensemble import VotingClassifier<br># from sklearn.model_selection import GridSearchCV<br><br>ens_clf=VotingClassifier(estimators=[(\'kn\', knn), (\'ml\', MLP),(\'gbc\', GBC_clf), (\'rf\', random_forest_clf), <br> (\'dt\', DT_clf), (\'et\', ET_clf), (\'adb\',... | Yes | 3 | 7 | Model_Train | train_model | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,739 | #predicting results<br><br>result=ens_clf.predict(test_normalized)<br><br>cols = { \'PlayerID\': [i+901 for i in range(440)] , \'TARGET_5Yrs\': result }<br>submission = pd.DataFrame(cols)<br><br><br>submission.to_csv("submission.csv", index=False)<br><br>print(submission.info())<br>print (submission)<br>print("done") | Yes | 3 | 48 | Model_Evaluation | predict_on_test | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,740 | from sklearn.neighbors import KNeighborsClassifier
from sklearn.preprocessing import Imputer
from sklearn.svm import SVC
from sklearn.tree import DecisionTreeClassifier
from sklearn.preprocessing import StandardScaler
from statsmodels.compat import pandas as pd
import pandas as pd
from sklearn.discriminant_analysis imp... | No | 5 | 22 | Environment | import_modules | 1,277,153 | 1 | A | 0 | 0 | 0 | 0 | 0 | 13 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 16 | A |
6,741 | test = pd.read_csv("../input/test.csv")<br>test_x = test.iloc[:, 2:].values<br>imp = Imputer(missing_values = \'NaN\', strategy = \'mean\', axis = 0)<br>imp=imp.fit(test_x)<br>test_x = imp.transform(test_x)<br>dataset = pd.read_csv("../input/train.csv")<br>print(dataset.info())<br>X = dataset.iloc[:, 2:-1].values<br>im... | Yes | 3 | 17 | Data_Transform | correct_missing_values | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
6,742 | #Classifiers<br>#Choosing best one<br>#/////////////////////////<br># model = Sequential()<br># model.add(Dense(20, input_dim=input_dim))<br># model.add(Activation(\'relu\'))<br># model.add(Dropout(0.15))<br># model.add(Dense(10))<br># model.add(Activation(\'relu\'))<br># model.add(Dropout(0.25))<br># model.add(Dense(1... | Yes | 3 | 7 | Model_Train | train_model | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,743 | cols = { \'PlayerID\': [i+901 for i in range(440)] , \'TARGET_5Yrs\': [eclf1.predict([test_x[i]])[0] for i in range(440)] }<br>submission = pd.DataFrame(cols)<br>print(submission)<br>submission.to_csv("submission1.csv", index=False) | Yes | 4 | 25 | Data_Export | save_to_csv | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,744 | import pandas as pd
import numpy as np
import sklearn
from sklearn import preprocessing
from sklearn.decomposition import PCA
from sklearn.ensemble import IsolationForest
from sklearn import svm
import statistics
import matplotlib.pyplot as plt
from sklearn.neural_network import MLPClassifier
from sklearn.neighbor... | No | 5 | 22 | Environment | import_modules | 1,278,958 | 1 | A | 0 | 0 | 0 | 0 | 0 | 18 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 16 | A |
6,745 | t_data = pd.read_csv("../input/train.csv")
ts_data = pd.read_csv("../input/test.csv") | No | 5 | 45 | Data_Extraction | load_from_csv | 1,278,958 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | 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."] | 16 | A |
6,746 | ddata = t_data.drop(["PlayerID","Name"], axis=1)
sdata = ts_data.drop(["PlayerID","Name"], axis=1) | No | 5 | 10 | Data_Transform | drop_column | 1,278,958 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 16 | A |
6,747 | ddata = ddata.interpolate()
ddata = ddata.replace([np.inf], np.float64.max)
ddata = ddata.replace([-np.inf], np.float64.min)
features = ddata.loc[:, ddata.columns.values[:len(ddata.columns.values)-1]].values
labels = ddata.loc[:, ['TARGET_5Yrs']].values
st_features = preprocessing.StandardScaler().fit_transform(featu... | Yes | 3 | 17 | Data_Transform | correct_missing_values | 1,278,958 | 1 | A | 0 | 0 | 0 | 0 | 0 | 11 | ok | 12 | 10 | [{"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... | E | Cross Validation Checker=low, Cross-validation not detected=low, Data Leakage Checker=high, Inconsistent scaling methods=high, No random seed setting detected=low, Pipeline Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}, {"type": "Inconsistent scaling methods", "severity": "high"}, {"type": "No random seed setting detected", "severity": "low"}, {"type": "Pipeline C... | ["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"] | 16 | E |
6,748 | pca = PCA(n_components=10)<br><br>pca.fit(features)<br>principalComponents = pca.transform(features)<br>test_principalComponenta = pca.transform(sfeatures)<br>print(principalComponents.shape, "\<br>", test_principalComponenta.shape) | Yes | 4 | 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 |
6,756 | names = ["Nearest Neighbors", "Linear SVM", "RBF SVM", "Gaussian Process",
"Decision Tree", "Random Forest", "Neural Net", "AdaBoost",
"Naive Bayes", "QDA"]
classifiers = [
KNeighborsClassifier(3),
SVC(kernel="linear", C=0.025),
SVC(gamma=2, C=1),
GaussianProcessClassifier(1.0 * RBF(1... | Yes | 3 | 4 | Model_Train | choose_model_class | 1,278,958 | 1 | A | 0 | 1 | 1 | 0 | 0 | 22 | ok | 12 | 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"] | 16 | B |
6,757 | cols = { \'PlayerID\': [i+901 for i in range(440)] , \'TARGET_5Yrs\': res3 }<br>submission = pd.DataFrame(cols)<br>submission.to_csv("submission.csv", index=False)<br>print(submission) | Yes | 4 | 25 | Data_Export | save_to_csv | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,758 | import numpy as np<br>import pandas as pd<br><br>from sklearn.model_selection import train_test_split<br>from sklearn.preprocessing import StandardScaler<br>from sklearn.preprocessing import QuantileTransformer<br>from sklearn.utils import shuffle<br>from scipy.stats import mode<br>from sklearn.metrics import f1_score<... | No | 2 | 22 | Environment | import_modules | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
6,759 | import numpy as np<br>import pandas as pd<br>import sklearn as sk<br>from sklearn import svm<br>from sklearn import ensemble<br>from sklearn.ensemble import AdaBoostClassifier<br>from sklearn.ensemble import RandomForestClassifier<br>from sklearn.ensemble import ExtraTreesClassifier<br>from sklearn.tree import Decision... | No | 3 | 45 | Data_Extraction | load_from_csv | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
6,760 | # testing various classifiers to choose the best accuracy.<br><br># linear SVM<br># clf = svm.SVC()<br># clf.fit(X, y)<br>#<br># SVM with sigmoid kernel<br># clf = svm.SVC(kernel=\'sigmoid\')<br># clf.fit(X, y)<br>#<br># SVM with rbf kernel<br># clf = svm.SVC(kernel=\'rbf\')<br># clf.fit(X, y)<br>#<br># SVM with poly k... | Yes | 3 | 7 | Model_Train | train_model | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,761 | # 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 |
6,762 | train=pd.read_csv('../input/train.csv')
train.info() | Yes | 4 | 45 | Data_Extraction | load_from_csv | 1,318,352 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "general_ml", "framework": "General ML", "name... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Hardcoded file path"] | 7 | B |
6,763 | train[\'date\']=train.datetime.apply(lambda x: x.split()[0])<br>train[\'hour\']=train.datetime.apply(lambda x:x.split()[1].split(\':\')[0])<br>train[\'weekday\'] = train.date.apply(lambda dateString : calendar.day_name[datetime.strptime(dateString,"%Y-%m-%d").weekday()])<br>train[\'month\']=train.date.apply(lambda date... | No | 5 | 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 |
6,764 | category_vars=['hour','weekday','month','season','weather','holiday','workingday']
for var in category_vars:
train[var]=train[var].astype('category')
train.info() | Yes | 4 | 16 | Data_Transform | data_type_conversions | 1,318,352 | 1 | A | 0 | 1 | 1 | 0 | 0 | 4 | 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"] | 7 | B |
6,765 | train=train.drop('datetime',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 |
6,766 | #model.(valdn_x, valdn_y, batch_size=32, verbose=1)
predictions = model.predict(test_x, batch_size=32, verbose=1) | No | 5 | 48 | Model_Evaluation | predict_on_test | 1,002,729 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Unit Testing Checker", "fix": "Write unit tests for data processing and model components.", "benefits": "Ensures code reliability and prevents bugs.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Excepti... | A | no applicable ML-specific findings | [] | ["Exception Handling Checker", "Unit Testing Checker"] | 3 | A |
6,767 | with open(\'submission.csv\',\'w\') as f:<br> f.write(\'id,label\<br>\')<br> for index in range(len(test_imgs)):<br> img_id =basename(test_imgs[index]).split(".")[0]<br> prob = (predictions[index,0])<br> #print("index: {}, img_id: {}, prob:{}".format(index,img_id, prob))<br> f.write("{... | Yes | 3 | 25 | Data_Export | save_to_csv | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,768 | # 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 | 22 | Environment | import_modules | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,773 | from keras.layers import Conv2D,Dense,MaxPooling2D,BatchNormalization,Activation,Flatten
from keras import Sequential
from keras.initializers import glorot_normal
from keras import optimizers
from keras.models import Model
from keras.applications.imagenet_utils import decode_predictions | No | 5 | 22 | Environment | import_modules | 1,361,826 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
6,788 | #################################TRYING OUT THE RESNET 50 ARCHITECTURE################################################
import random
l=[1,2,3]
| Yes | 3 | 22 | Environment | import_modules | 1,361,826 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
6,800 | from keras.applications import VGG19
v=VGG19(weights="imagenet",include_top=False,input_shape=(120,120,3)) | Yes | 3 | 22 | Environment | import_modules | 1,361,826 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
6,801 | #########defining the new model by defining my own last layer
new_model=v.output
new_model=Flatten()(new_model)
new_model=Dense(10)(new_model)
new_model=Activation("relu")(new_model)
new_model=Dense(1,activation="sigmoid")(new_model)
final_model=Model(input=v.input,output=new_model) | No | 5 | 4 | Model_Train | choose_model_class | 1,361,826 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
6,802 | ###freezin all layers except from last 3 layers
total_layers=len(final_model.layers)
print(total_layers)
for x in range(0,total_layers-4):
final_model.layers[x].trainable=False
# final_model.layers | No | 5 | 84 | Other | not_enough_vertices | 1,361,826 | 1 | A | 0 | 1 | 1 | 0 | 0 | 4 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
6,803 | ###train test split
from sklearn.model_selection import train_test_split
train_x,test_x,train_y,test_y=train_test_split(data,labels,test_size=0.2,random_state=100)
| No | 5 | 13 | Data_Transform | split | 1,361,826 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}] | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | [] | 3 | B |
6,804 | ####compiling the model
o=optimizers.adam()
final_model.compile(loss="binary_crossentropy",metrics=["accuracy"],optimizer=o) | Yes | 4 | 59 | Model_Train | init_hyperparams | 1,361,826 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
6,805 | final_model.fit(train_x,train_y,batch_size=32,epochs=15,validation_split=0.2) | No | 5 | 7 | Model_Train | train_model | 1,361,826 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 4 | 4 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 3 | B |
6,806 | preds=final_model.predict(test_x)
new_preds=[]
for x in preds:
if x >0.5:
new_preds.append(1)
else:
new_preds.append(0)
new_preds=np.array(new_preds)
new_preds=new_preds.reshape(len(new_preds),1) | No | 5 | 48 | Model_Evaluation | predict_on_test | 1,361,826 | 1 | A | 0 | 2 | 4 | 0 | 0 | 9 | ok | 3 | 3 | [{"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 11"}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Unit ... | A | no applicable ML-specific findings | [] | ["Array Creation Efficiency", "Exception Handling Checker", "Unit Testing Checker"] | 3 | A |
6,807 | sum(new_preds==test_y)/len(test_y)
train_x=[]
test_x=[]
data=[]
labels=[] | No | 5 | 77 | Other | define_variables | 1,361,826 | 1 | A | 0 | 0 | 0 | 1 | 0 | 5 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
6,809 | ########importing test file
data=[]
input_file_names=[]
#####get the file names of the images to read them one by one
for (dirpath, dirnames, filenames) in walk("../input/dogs-vs-cats-redux-kernels-edition/test/"):
input_file_names=filenames
for x in input_file_names:
img_file_name=x##getting name of the imag... | No | 5 | 84 | Other | not_enough_vertices | 1,361,826 | 1 | A | 0 | 2 | 2 | 0 | 0 | 11 | ok | 3 | 2 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Exception Handling Checker", "fix": "Implement proper exception handling for model operations.", "benefits": "Improves code robustness and error reporting.", "location": "Line 15"}, {"detector": "general_ml", "framework": "General ML", "name": "Ha... | A | no applicable ML-specific findings | [] | ["Exception Handling Checker", "Hardcoded file path"] | 3 | A |
6,810 | data=np.array(data)/255.
preds=final_model.predict(data) | No | 5 | 27 | Model_Train | predict_on_train | 1,361,826 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 3 | 3 | [{"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 4"}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Unit T... | A | no applicable ML-specific findings | [] | ["Array Creation Efficiency", "Exception Handling Checker", "Unit Testing Checker"] | 3 | A |
6,811 | df=pd.DataFrame({'id':new_input_test_file_names,
'label':preds}) | No | 5 | 12 | Data_Transform | create_dataframe | 1,361,826 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
6,812 | df.to_csv("submission2.csv",index=False) | No | 5 | 25 | Data_Export | save_to_csv | 1,361,826 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
6,813 | #import libraries
import pandas as pd
import numpy as np
import os, random ,cv2
import keras
from sklearn.model_selection import train_test_split
from keras.models import Sequential
from keras.layers import Conv2D, Dense, Flatten, Dropout, Activation, MaxPool2D
from keras.optimizers import Adam, RMSprop
from keras.loss... | No | 5 | 22 | Environment | import_modules | 1,390,653 | 1 | A | 1 | 0 | 0 | 0 | 5 | 11 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
6,814 | #specify train and test datasets paths
train_path = '../input/train/'
test_path = '../input/test/'
#define image dimensions
rows = 150
cols = 150
channels = 3 | No | 5 | 77 | Other | define_variables | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,815 | #create a list of train image paths "including image name"<br>train_images = [train_path+i for i in os.listdir(train_path)]<br>train_dogs = [train_path+i for i in os.listdir(train_path) if \'dog\' in i]<br>train_cats = [train_path+i for i in os.listdir(train_path) if \'cat\' in i] | No | 5 | 77 | Other | define_variables | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,816 | #create a list of test image paths "including image name"
test_images = [test_path+i for i in os.listdir(test_path)] | No | 5 | 77 | Other | define_variables | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,817 | train_images = train_dogs[:3000] + train_cats[:3000]
#randomly shuffle train images
random.shuffle(train_images) | Yes | 3 | 21 | Data_Transform | prepare_x_and_y | 1,390,653 | 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": "Randomness C... | B | Randomness Control Checker=low | [{"type": "Randomness Control Checker", "severity": "low"}] | ["Column Selection Checker"] | 3 | B |
6,818 | def prep_data(image_path_list):
x=[]
y=[]
for i in image_path_list:
x.append(cv2.resize(plt.imread(i), #read then resize image
(rows,cols), interpolation=cv2.INTER_CUBIC)) #appened new image to x
for j in image_path_list: #create a label and append it to y
if 'dog' in j:
... | No | 5 | 21 | Data_Transform | prepare_x_and_y | 1,390,653 | 1 | A | 0 | 4 | 5 | 0 | 0 | 12 | ok | 1 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Missing docstring for function: prep_data. Consider adding documentation for parameters and return values.", "fix": "Not specified", "benefits": "Not specified", "location": "Line 4"}] | A | no applicable ML-specific findings | [] | ["Missing function docstring"] | 3 | A |
6,819 | X, y = prep_data(train_images) | No | 5 | 21 | Data_Transform | prepare_x_and_y | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,820 | #split X,y into a train and validation data sets
X_train, X_val, y_train, y_val = train_test_split(X,y, test_size=(1/3), random_state=1) | No | 5 | 13 | Data_Transform | split | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,821 | X_test, y_test = prep_data(test_images) | No | 5 | 21 | Data_Transform | prepare_x_and_y | 1,390,653 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
6,822 | #create a keras CNN model from sctarch
model = Sequential()
model.add(Conv2D(32,(3,3), input_shape=(rows, cols, 3)))
model.add(Activation('relu'))
model.add(MaxPool2D(pool_size=(2,2)))
model.add(Conv2D(64,(3,3)))
model.add(Activation('relu'))
model.add(MaxPool2D(pool_size=(2,2)))
model.add(Conv2D(128,(3,3)))
model.a... | No | 5 | 4 | Model_Train | choose_model_class | 1,390,653 | 1 | A | 0 | 0 | 0 | 0 | 0 | 22 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
6,823 | model.compile(optimizer='RMSprop', metrics=['accuracy'], loss='binary_crossentropy') | No | 5 | 84 | Other | not_enough_vertices | 1,390,653 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
6,824 | #create a data generator object with some image augmentation specs
datagen = ImageDataGenerator(
rescale=1./ 255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True
)
| No | 5 | 84 | Other | not_enough_vertices | 1,390,653 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
6,825 | #create an iterator for both train and valid sets
train_gen = datagen.flow(x=np.array(X_train), y=y_train, batch_size=50)
valid_gen = datagen.flow(x=np.array(X_val), y=y_val, batch_size=50) | No | 5 | 77 | Other | define_variables | 1,390,653 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 2 | 1 | [{"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 5"}, {"detector": "framework_specific", "framework": "NumPy", "name": "Array Creati... | A | no applicable ML-specific findings | [] | ["Array Creation Efficiency"] | 3 | A |
6,826 | #train/validate model
model.fit_generator(train_gen, steps_per_epoch=40, epochs=50, verbose=1, validation_data=valid_gen, validation_steps=20) | No | 5 | 7 | Model_Train | train_model | 1,390,653 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Exception Handling Checker", "Unit Testing Checker"] | 3 | B |
6,827 | #create a data generator object for testing
datagen = ImageDataGenerator(rescale = 1./255) | No | 5 | 84 | Other | not_enough_vertices | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,828 | test_gen = datagen.flow(np.array(X_test), batch_size = 100) | No | 5 | 84 | Other | not_enough_vertices | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,829 | #predict
predictions = model.predict_generator(test_gen, steps=125, verbose=1) | 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 |
6,830 | #submit
id_num = range(1, len(predictions_dogs) + 1)
submission = pd.DataFrame({"id": id_num, "label":predictions_dogs})
submission.to_csv("submission.csv", index = False) | No | 5 | 25 | Data_Export | save_to_csv | 1,390,653 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
6,831 | import numpy as np # linear algebra<br>import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)<br>import math<br>import IPython.display as ipd<br>import keras<br>from keras.models import *<br>from keras.callbacks import *<br>from keras.layers import *<br>from keras.preprocessing.image import random_brigh... | No | 3 | 22 | Environment | import_modules | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 0 | A |
6,832 | sns.countplot(x='class', data=train); | No | 5 | 33 | Visualization | distribution | 1,423,929 | 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"] | 8 | A |
6,833 | def make_model(size=(256,256)):
def make_cnn(kernel_nums, x):
for n in kernel_nums:
x = Conv2D(n, kernel_size=3, strides=1, activation='relu', padding='same')(x)
x = MaxPooling2D(pool_size=2, strides=2, padding='same')(x)
x = BatchNormalization()(x)
x = Spatia... | No | 5 | 4 | Model_Train | choose_model_class | 1,423,929 | 1 | A | 1 | 4 | 3 | 0 | 1 | 20 | 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": "Dependent Th... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Dependent Threshold Checker", "Missing function docstring"] | 8 | A |
6,834 | SIZE = (256,256)
model = make_model(size=SIZE)
model.summary()
#keras.utils.plot_model(model, to_file='model.png', show_shapes=True)
#ipd.Image(filename='model.png') | No | 5 | 4 | Model_Train | choose_model_class | 1,423,929 | 2 | B | 1 | 0 | 0 | 0 | 5 | 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"] | 8 | B |
6,835 | model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['acc'])
batch_size=150
X_train, X_valid, y_train, y_valid = train_test_split(train['file'].values, train['class_id'].values, test_size=0.1)
model.fit_generator(image_generator(X_train, TRAIN_DIR, labels=y_train, size=SIZE, batch_size=batch_size, rando... | Yes | 4 | 7 | Model_Train | train_model | 1,423,929 | 1 | A | 0 | 0 | 0 | 0 | 0 | 11 | ok | 8 | 8 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Valida... | B | Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low, Randomness Control Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}, {"type": "Randomness Control Checker", "severity": "low"}] | ["Column Selection Checker", "Dependent Threshold Checker", "Exception Handling Checker", "Unit Testing Checker"] | 8 | B |
6,836 | predicted_probs = model.predict_generator(image_generator(X_valid, TRAIN_DIR, size=SIZE, batch_size=batch_size, random_preproc=False),
steps=int(math.ceil(len(y_valid)/batch_size))
)
predicted = np.round(predicted_probs)
print(clas... | Yes | 3 | 48 | Model_Evaluation | predict_on_test | 1,423,929 | 1 | A | 0 | 0 | 0 | 0 | 0 | 7 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Threshold Checker", "fix": "Use threshold-independent metrics alongside threshold-dependent ones.", "benefits": "Provides a comprehensive evaluation of model performance.", "location": ""}, {"detector": "framework_specific", "framework":... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Exception Handling Checker", "Unit Testing Checker"] | 8 | A |
6,837 | predicted_probs = model.predict_generator(image_generator(test['file'], TEST_DIR, size=SIZE, batch_size=batch_size, random_preproc=False),
steps=int(math.ceil(len(test['file'])/batch_size))
)
test['label'] = predicted_probs
test[['... | Yes | 3 | 48 | Model_Evaluation | predict_on_test | 1,423,929 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Threshold Checker", "fix": "Use threshold-independent metrics alongside threshold-dependent ones.", "benefits": "Provides a comprehensive evaluation of model performance.", "location": ""}, {"detector": "framework_specific", "framework":... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Exception Handling Checker", "Unit Testing Checker"] | 8 | A |
6,838 | PATH = "../input/"
TMP_PATH = "/tmp/tmp"
MODEL_PATH = "/tmp/model/"
sz=224 | No | 5 | 77 | Other | define_variables | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,839 | fnames = np.array([f'train/{f}' for f in sorted(os.listdir(f'{PATH}train'))])
labels = np.array([(0 if 'cat' in fname else 1) for fname in fnames]) | No | 5 | 77 | Other | define_variables | null | 1 | A | 0 | 1 | 1 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,840 | from fastai.imports import *
from fastai.transforms import *
from fastai.conv_learner import *
from fastai.model import *
from fastai.dataset import *
from fastai.sgdr import *
from fastai.plots import * | No | 5 | 22 | Environment | import_modules | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 7 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,845 | arch=resnet50
| No | 5 | 4 | Model_Train | choose_model_class | 1,443,020 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 2 | A |
6,846 | data = ImageClassifierData.from_names_and_array(
path=PATH,
fnames=fnames,
y=labels,
classes=['dogs', 'cats'],
test_name='test',
tfms= tfms_from_model(resnet34, sz, aug_tfms=transforms_side_on, max_zoom=1.1) #data augmentation
)
learn = ConvLearner.pretrained(arch, data, precompute=True, ... | No | 5 | 30 | Model_Train | load_pretrained | 1,443,020 | 1 | A | 0 | 0 | 0 | 0 | 0 | 9 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 2 | A |
6,847 | learn.fit(0.01,4) | No | 5 | 7 | Model_Train | train_model | 1,443,020 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 2 | A |
6,848 | learn.precompute=False
learn.fit(1e-2, 3, cycle_len=2) | No | 5 | 7 | Model_Train | train_model | 1,443,020 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 2 | A |
6,851 | lr=np.array([1e-4,1e-3,1e-2]) | No | 5 | 5 | Hyperparam_Tuning | define_search_space | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,852 | learn.fit(lr, 3, cycle_len=1, cycle_mult=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 |
6,854 | log_predictions,y = learn.TTA(is_test=True)
prob_predictions = np.mean(np.exp(log_predictions),0)
probs = prob_predictions[:,1] | No | 5 | 8 | Data_Transform | feature_engineering | 1,443,020 | 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 |
6,858 | log_predictions.shape | No | 5 | 58 | Debug | show_shape | 1,443,020 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 2 | A |
6,859 | ids= fnames = np.array([f'{f}' for f in os.listdir(f'{PATH}test')]) | No | 5 | 77 | Other | define_variables | 1,443,020 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 1 | 1 | [{"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 3"}] | A | no applicable ML-specific findings | [] | ["Array Creation Efficiency"] | 2 | A |
6,860 | ids= [i.replace(".jpg","") for i in ids]
ids[0] | No | 5 | 77 | Other | define_variables | 1,443,020 | 1 | A | 0 | 0 | 0 | 1 | 0 | 2 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}] | A | no applicable ML-specific findings | [] | ["Column Selection Checker"] | 2 | A |
6,861 | ans= pd.DataFrame({"id":ids,"label":probs})<br>ans= ans.sort_values(\'id\')<br>ans.head() | Yes | 3 | 9 | Data_Transform | sort_values | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,862 | ans.describe() | No | 5 | 40 | Debug | show_table_attributes | 1,443,020 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 2 | A |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.