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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3,090 | # Check missing value
select_test_df.isnull().sum().value_counts() | No | 5 | 39 | EDA | count_missing_values | 13,885,246 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 13 | A |
3,091 | # Impute missing value in numeric columns with median
numeric_cols = select_test_df.select_dtypes(include=['number']).columns.values
for col in numeric_cols:
if col in list(col_pct_miss_df.column_name):
med = df[col].median()
select_test_df[col] = select_test_df[col].fillna(med)
not_numer... | No | 5 | 17 | Data_Transform | correct_missing_values | 13,885,246 | 1 | A | 0 | 3 | 4 | 0 | 0 | 9 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}] | A | no applicable ML-specific findings | [] | ["Column Selection Checker"] | 13 | A |
3,092 | # Find columns that contain missing value
nan_columns = select_test_df.isna().any()
columns_with_nan = select_test_df.columns[nan_columns].tolist()
columns_with_nan | No | 3 | 71 | Debug | show_columns | 13,885,246 | 1 | A | 0 | 0 | 0 | 1 | 0 | 3 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 13 | A |
3,093 | # Replace missing value with zero
select_test_df[columns_with_nan] = select_test_df[columns_with_nan].fillna(0) | No | 5 | 17 | Data_Transform | correct_missing_values | 13,885,246 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}] | A | no applicable ML-specific findings | [] | ["Column Selection Checker"] | 13 | A |
3,094 | select_test_df.head() | No | 5 | 41 | Debug | show_table | 13,885,246 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 13 | A |
3,095 | # Random Forest
test_df_rf = test_df.copy()
test_df_rf['loss'] = rf.predict(select_test_df.loc[:,select_test_df.columns != 'id'])
test_df_rf.head() | No | 5 | 48 | Model_Evaluation | predict_on_test | 13,885,246 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Unit Testing... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Exception Handling Checker", "Unit Testing Checker"] | 13 | A |
3,096 | # Export sample_submission of random forest
sample_submission = test_df_rf[['id','loss']]
sample_submission.to_csv('sample_submission_rf.csv', index = False) | No | 5 | 25 | Data_Export | save_to_csv | 13,885,246 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 13 | A |
3,097 | import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rcParams
import seaborn as sb
from collections import Counter
import warnings
warnings.filterwarnings("ignore")
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC
from sklearn.tree import Decision... | No | 5 | 23 | Environment | set_options | 10,712,817 | 1 | A | 0 | 0 | 0 | 0 | 0 | 24 | 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"] | 19 | A |
3,098 | import tensorflow as tf
# GPU device Check.
device_name = tf.test.gpu_device_name()
if device_name == '/device:GPU:0':
print('Found GPU at: {}'.format(device_name))
else:
raise SystemError('GPU device not found') | Yes | 4 | 22 | Environment | import_modules | null | 1 | A | 0 | 1 | 2 | 0 | 0 | 6 | ok | 1 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path detected: /device:GPU:0. Consider using configuration files or environment variables.", "fix": "Not specified", "benefits": "Not specified", "location": "Line 5"}] | A | no applicable ML-specific findings | [] | ["Hardcoded file path"] | 0 | A |
3,099 | # Reading data
train = pd.read_csv('../input/higgs-boson/training.zip')
test = pd.read_csv('../input/higgs-boson/test.zip') | No | 5 | 45 | Data_Extraction | load_from_csv | 10,712,817 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 4 | 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."] | 19 | A |
3,100 | b"print(train.columns.values,'\\n')\nprint(test.columns.values)" | No | 5 | 71 | Debug | show_columns | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
3,101 | train = train.drop(['Weight'], 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 |
3,102 | print(train['Label'].value_counts())
rcParams['figure.figsize'] = 10,5
sb.barplot(x = train['Label'].value_counts().index, y = train['Label'].value_counts().values)
plt.title('Label counts')
plt.show() | No | 5 | 33 | Visualization | distribution | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
3,103 | # getting dummy variables column
enc = LabelEncoder()
train['Label'] = enc.fit_transform(train['Label'])
train.head() | No | 4 | 20 | Data_Transform | categorify | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
3,104 | y = train["Label"]
X = train
X_test = test | No | 5 | 21 | Data_Transform | prepare_x_and_y | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
3,105 | X.set_index(['EventId'],inplace = True)
X_test.set_index(['EventId'],inplace = True)
X = X.drop(['Label'], axis=1)
X.head() | No | 4 | 21 | Data_Transform | prepare_x_and_y | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
3,106 | X_test.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 |
3,109 | #Normalizing
from sklearn.preprocessing import normalize
X = normalize(X)
X_test = normalize(X_test) | No | 5 | 18 | Data_Transform | normalization | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 0 | A |
3,110 | b"# print(X.isnull().sum(),'\\n')\n# print(X_test.isnull().sum())" | No | 5 | 53 | Other | something_strange | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
3,115 | b"#print(X.isnull().sum(),'\\n')\n#print(X_test.isnull().sum())" | No | 5 | 53 | Other | something_strange | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
3,118 | import pandas as pd
from sklearn import ensemble | No | 5 | 22 | Environment | import_modules | 30,650 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 2 | A |
3,119 | # The competition datafiles are in the directory ../input
file_train = "../input/train.csv"
file_test = "../input/test.csv"
df_train = pd.read_csv(file_train)
df_test = pd.read_csv(file_test)
df_train.head() | Yes | 3 | 45 | Data_Extraction | load_from_csv | 30,650 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 4 | 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 | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Hardcoded file path", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness."] | 2 | B |
3,120 | feature_cols = [col for col in df_train.columns if col not in ['Cover_Type','Id']]
X_train = df_train[feature_cols]
X_test = df_test[feature_cols]
y = df_train['Cover_Type'] # target
test_ids = df_test['Id'] # for submission | No | 5 | 21 | Data_Transform | prepare_x_and_y | 30,650 | 1 | A | 0 | 1 | 0 | 0 | 0 | 5 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}] | A | no applicable ML-specific findings | [] | ["Column Selection Checker"] | 2 | A |
3,121 | clf = ensemble.RandomForestClassifier(n_estimators=200,n_jobs=-1,random_state=0)
clf.fit(X_train, y) | Yes | 3 | 4 | Model_Train | choose_model_class | 30,650 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 5 | 4 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 2 | B |
3,122 | file_submission = "rf200.submission.csv"
with open(file_submission, "w") as outfile:
outfile.write("Id,Cover_Type\
")
for e, val in enumerate(list(clf.predict(X_test))):
outfile.write("%s,%s\
"%(test_ids[e],val))' | No | 5 | 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 |
3,123 | import time
import pandas as pd
from sklearn.cross_validation import train_test_split
from sklearn import ensemble
from sklearn.metrics import accuracy_score
import numpy as np
loc_test = "../input/test.csv"
loc_train = "../input/train.csv"
loc_submission = "forest-cover-type-prediction.AspiringGuru.csv"
df_test = p... | Yes | 1 | 22 | Environment | import_modules | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
3,124 | df=pd.read_csv("../input/train.csv")
test=pd.read_csv("../input/test.csv")
y=df["Cover_Type"]
x=df.iloc[:,:-1]
id=df.iloc[:,:1] | Yes | 2 | 22 | Environment | import_modules | 812,592 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 4 | 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": "general_ml", "framework": "General ML", "name": "No error handling det... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Hardcoded file path", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness."] | 3 | A |
3,125 | from sklearn.tree import DecisionTreeClassifier
reg=DecisionTreeClassifier()
reg.fit(x,y) | Yes | 2 | 4 | Model_Train | choose_model_class | 812,592 | 3 | C | 2 | 0 | 0 | 0 | 10 | 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"] | 3 | C |
3,126 | pred=reg.predict(test) | No | 5 | 48 | Model_Evaluation | predict_on_test | 812,592 | 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 |
3,127 | mysubmission=pd.DataFrame({'Id':test.Id,'Cover_Type':pred}) | No | 5 | 55 | Data_Export | prepare_output | 812,592 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
3,128 | mysubmission.to_csv("submission.csv",index=False) | No | 5 | 25 | Data_Export | save_to_csv | 812,592 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
3,129 | temp = pd.read_csv("submission.csv")
temp | No | 5 | 45 | Data_Extraction | load_from_csv | 812,592 | 1 | A | 0 | 0 | 0 | 1 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
3,130 | from IPython.display import display
import matplotlib.pyplot as plt
import seaborn as sns | No | 5 | 22 | Environment | import_modules | 899,692 | 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"] | 8 | A |
3,131 | train_set = pd.read_csv('../input/train.csv')
test_set = pd.read_csv('../input/test.csv') | No | 5 | 45 | Data_Extraction | load_from_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
3,132 | display(train_set.head())
display(train_set.describe()) | No | 4 | 40 | Debug | show_table_attributes | 899,692 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 5 | 5 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low, 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", "Logging Checker"] | 8 | B |
3,133 | display(train_set.keys())
display(len(train_set.keys())) | No | 5 | 40 | Debug | show_table_attributes | 899,692 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 5 | 5 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low, 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", "Logging Checker"] | 8 | B |
3,134 | # How about using this features directly? (Not using the scaling and normalization)
fig = plt.figure()
fig.set_size_inches(35, 35)
sns.set(font_scale=2)
# Delete 'Id' and change cover type to dummy variables
cont_var_train_set = train_set.drop('Id', axis=1).drop(cate_vars, axis=1)
# Categorical feature : cannot using... | Yes | 1 | 80 | Visualization | heatmap | 899,692 | 1 | A | 0 | 0 | 0 | 0 | 0 | 7 | ok | 5 | 5 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low, 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", "Logging Checker"] | 8 | B |
3,135 | from sklearn.preprocessing import StandardScaler | 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 |
3,136 | # using scaler
scaler = StandardScaler()
scaler.fit(scaled_feat)
scaled_feat = scaler.transform(scaled_feat)
scaled_feat = pd.DataFrame(scaled_feat, columns=cont_vars)
scaled_feat.head() | Yes | 1 | 4 | Model_Train | choose_model_class | 899,692 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 10 | 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... | D | Cross Validation Checker=low, Data Leakage Checker=high, No random seed setting detected=low, Pipeline Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}, {"type": "No random seed setting detected", "severity": "low"}, {"type": "Pipeline Checker", "severity": "low"}] | ["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"] | 8 | D |
3,137 | fig = plt.figure()
fig.set_size_inches(35, 35)
correlation2 = pd.concat([scaled_feat, dummy_labels], axis=1).corr()
sns.heatmap(correlation2, cmap='viridis', annot=True, linewidths=3) | Yes | 2 | 11 | Data_Transform | concatenate | 899,692 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | 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 |
3,138 | from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, classification_report | No | 5 | 22 | Environment | import_modules | 899,692 | 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"] | 8 | A |
3,139 | # Spliting the datasets
features = pd.concat([scaled_feat, train_set[cate_vars]], axis=1)
features.head() | Yes | 2 | 11 | Data_Transform | concatenate | 899,692 | 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"] | 8 | A |
3,140 | rf_model = RandomForestClassifier(max_depth=7, n_estimators=300)
rf_model.fit(x_train, y_train) | Yes | 2 | 4 | Model_Train | choose_model_class | 899,692 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | 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... | B | Cross Validation Checker=low, Randomness Control Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Randomness Control Checker", "severity": "low"}] | ["Dependent Threshold Checker", "Exception Handling Checker", "Logging Checker", "Memory Release Checker", "Model Evaluation Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 8 | B |
3,141 | # Predicting naively
pred = rf_model.predict(x_test)
display(accuracy_score(y_test, pred))
display(classification_report(y_test, pred)) | Yes | 3 | 48 | Model_Evaluation | predict_on_test | 899,692 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 5 | 4 | [{"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", "Memory Release Checker", "Unit Testing Checker"] | 8 | A |
3,142 | # See the importance of features
importances = rf_model.feature_importances_
indices = np.argsort(importances)
fig = plt.figure()
fig.set_size_inches(20, 20)
sns.set(font_scale=1.5)
plt.title('Feature Importances')
plt.barh(range(len(indices)), importances[indices], color='b', align='center')
plt.yticks(range(len(ind... | Yes | 3 | 79 | Visualization | model_coefficients | 899,692 | 1 | A | 0 | 0 | 0 | 0 | 0 | 9 | 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"] | 8 | A |
3,143 | # dimensional reduction
from sklearn.decomposition import PCA
import numpy as np
pca = PCA(n_components=None, random_state=20180425)
pca.fit(features) | Yes | 2 | 22 | Environment | import_modules | 899,692 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 8 | 8 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Scaler Missing Checker", "fix": "Apply scaling before scaling-sensitive operations.", "benefits": "Improves model performance and accuracy.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Pipeline Checker... | D | Cross Validation Checker=low, Data Leakage Checker=high, Pipeline Checker=low, Scaler Missing Checker=medium | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}, {"type": "Pipeline Checker", "severity": "low"}, {"type": "Scaler Missing Checker", "severity": "medium"}] | ["Dependent Threshold Checker", "Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 8 | D |
3,144 | pca_var = pca.explained_variance_ratio_
fig, ax = plt.subplots(1, 2, figsize=(16, 8))
ax1, ax2 = ax.flatten()
ax1.plot(pca_var)
ax2.plot(np.cumsum(pca_var)) | No | 5 | 33 | Visualization | distribution | 899,692 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "NumPy", "name": "Missing Axis Specification", "fix": "Specify axis in array operations.", "benefits": "Improves performance and avoids unexpected behaviour.", "location": "Line 15"}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Thres... | C | Missing Axis Specification=medium | [{"type": "Missing Axis Specification", "severity": "medium"}] | ["Dependent Threshold Checker"] | 8 | C |
3,145 | train_set.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 |
3,146 | wilderness_area_col = train_set['Wilderness_Area'].astype(int)
soil_type_col = train_set['Soil_Type'].astype(int)
display(wilderness_area_col.head())
display(soil_type_col.head()) | Yes | 3 | 16 | Data_Transform | data_type_conversions | 899,692 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | 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", "Logging Checker"] | 8 | B |
3,148 | import scipy.stats as ss | No | 5 | 22 | Environment | import_modules | 899,692 | 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 |
3,149 | cate_vars_1 = ['Wilderness_Area', 'Soil_Type'] | No | 5 | 77 | Other | define_variables | 899,692 | 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 |
3,150 | input_features = pd.concat([scaled_feat, wilderness_area_col, soil_type_col], axis=1)
labels = train_set['Cover_Type']
display(input_features.head())
display(labels.head()) | Yes | 1 | 11 | Data_Transform | concatenate | 899,692 | 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"] | 8 | A |
3,151 | x_train, x_test, y_train, y_test = train_test_split(input_features, labels, random_state=20190501, test_size=0.3) | No | 5 | 13 | Data_Transform | split | 899,692 | 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"}] | ["Dependent Threshold Checker", "Logging Checker"] | 8 | B |
3,152 | test_set_rf = test_set.copy() | No | 5 | 77 | Other | define_variables | 899,692 | 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 |
3,153 | test_set_rf_cont = test_set_rf[cont_vars]
scaler.fit(test_set_rf_cont)
test_set_rf_cont = scaler.transform(test_set_rf_cont)
test_set_rf_cont = pd.DataFrame(test_set_rf_cont, columns=cont_vars)
test_set_rf_cate = test_set_rf[cate_vars]
scaled_test_set_rf = pd.concat([test_set_rf_cont, test_set_rf_cate], axis=1)
scale... | Yes | 2 | 12 | Data_Transform | create_dataframe | 899,692 | 1 | A | 0 | 0 | 0 | 0 | 0 | 7 | ok | 10 | 9 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Valida... | D | Cross Validation Checker=low, Data Leakage Checker=high, 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"}] | ["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"] | 8 | D |
3,154 | rf_pred = rf_model.predict(scaled_test_set_rf)
rf_result = pd.concat([test_set['Id'], pd.DataFrame({'Cover_Type': rf_pred})], axis=1)
rf_result.to_csv("rf_submission.csv", index=False)' | Yes | 3 | 48 | Model_Evaluation | predict_on_test | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
3,155 | # 1. scaling the continous features
test_cont_feat = test_set_copy[cont_vars]
scaler.fit(test_cont_feat)
test_scaled_cont_feat = scaler.transform(test_cont_feat)
test_scaled_cont_feat = pd.DataFrame(test_scaled_cont_feat, columns=cont_vars)
# 2. categorical features
test_cate_feat = test_set_copy[cate_vars_1].astype(i... | Yes | 1 | 12 | Data_Transform | create_dataframe | 899,692 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | ok | 10 | 9 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Valida... | D | Cross Validation Checker=low, Data Leakage Checker=high, 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"}] | ["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"] | 8 | D |
3,156 | display(test_cont_feat.head())
display(test_scaled_cont_feat.head())
display(test_input_features.head()) | No | 5 | 41 | Debug | show_table | 899,692 | 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"] | 8 | A |
3,157 | result = pd.concat([test_set['Id'], pd.DataFrame({'Cover_Type': result})], axis=1) | Yes | 4 | 11 | Data_Transform | concatenate | 899,692 | 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"] | 8 | A |
3,158 | result.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 |
3,159 | result.to_csv("submission.csv", index=False) | No | 5 | 25 | Data_Export | save_to_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
3,160 | # -*- coding: utf-8 -*-
"""
Cincia de Dados e Visualizao com Python
Exemplo: Forest Cover Type
URL (problema): https://www.kaggle.com/c/forest-cover-type-prediction
URL (soluo): https://www.kaggle.com/ivarvb/forest-cover-type
Autor: Ivar Vargas Belizario
E-mail: ivar@usp.br
"""
import numpy as np
import pandas as pd
... | No | 2 | 22 | Environment | import_modules | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
3,161 | import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import matplotlib.pyplot as plt
import seaborn as sns | Yes | 4 | 22 | Environment | import_modules | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 0 | A |
3,162 | #data imports
data_train = pd.read_csv("../input/train.csv")
data_test = pd.read_csv("../input/test.csv")
data_train.head() | Yes | 4 | 45 | Data_Extraction | load_from_csv | 2,824,153 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 5 | 4 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Dependent Threshold Checker", "Hardcoded file path", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness."] | 7 | B |
3,163 | keras.backend.clear_session()
model = keras.models.Sequential()
model.add(keras.layers.Conv2D(64, (3, 3), activation='relu', input_shape=(32, 32, 3)))
model.add(keras.layers.BatchNormalization())
model.add(keras.layers.Conv2D(64, (2, 2), activation='relu',padding='same'))
model.add(keras.layers.MaxPooling2D(1, 1))
m... | No | 5 | 4 | Model_Train | choose_model_class | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
3,164 |
history = model.fit(train_generator,
steps_per_epoch=(train_size//batch_size),
epochs= 5,
validation_data=validation_generator,
validation_steps=(validation_size//batch_size)
) | No | 5 | 7 | Model_Train | train_model | 9,829,311 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
3,165 | test_labels.head(2) | No | 5 | 41 | Debug | show_table | 9,829,311 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
3,166 | if os.path.exists("./test"):
shutil.rmtree("./test")
if os.path.exists("./train"):
shutil.rmtree("./train")
if not os.path.exists("./data"):
os.mkdir("./data")
shutil.unpack_archive('/kaggle/input/cifar-10/test.7z', '/kaggle/working/data')' | Yes | 2 | 88 | Debug | list_files | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
3,167 | test_dir = os.listdir("./data/test");
test_dir_len = len(test_dir)
print('min:\\t',min(test_dir))
print('max:\\t',max(test_dir))
print(".\\\\test:\\t",test_dir_len)
print("files:\\t\\t",test_dir[:3])' | No | 3 | 88 | Debug | list_files | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
3,168 | test_data_generator = ImageDataGenerator(rescale=1./255.)
test_generator = test_data_generator.flow_from_directory(directory='/kaggle/working/data',
batch_size=batch_size,
shuffle=False,color_mode='rgb',
target_size=(32,32),
class_mode=None) | No | 5 | 84 | Other | not_enough_vertices | 9,829,311 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
3,169 | predict_test = model.predict_generator(test_generator) | No | 5 | 48 | Model_Evaluation | predict_on_test | 9,829,311 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
3,170 | predict_generator = np.argmax(predict_test, axis=1)
print(class_names)
predict_generator[:2],[class_names[int(i)] for i in predict_generator[:2]] | No | 4 | 14 | Data_Transform | filter | 9,829,311 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
3,171 | submission = pd.DataFrame(columns = ['id','label'],dtype=str)
submission["label"] = [class_names[int(i)] for i in predict_generator]
submission["id"] = [ (''.join(filter(str.isdigit, name ))) for name in test_generator.filenames]
submission.head(101)' | Yes | 4 | 12 | Data_Transform | create_dataframe | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
3,172 | submission.values[50:100] | No | 5 | 41 | Debug | show_table | 9,829,311 | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
3,173 | index = 0
fig = plt.figure(figsize = (16,10))
for item in submission.values[50:70]:
index += 1
plt.subplot(5, 5, index)
test_path = '/kaggle/working/data/test/'+item[0]+'.png'
test_image = load_img(test_path, target_size=(32,32))
plt.imshow(test_image)
plt.colorbar()
plt.grid(False)
... | No | 5 | 56 | Visualization | plot_predictions | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
3,174 | shutil.rmtree("./data") | No | 5 | 84 | Other | not_enough_vertices | 9,829,311 | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
3,176 | # This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load in
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O... | Yes | 5 | 88 | Debug | list_files | 4,011,534 | 1 | A | 0 | 0 | 0 | 0 | 0 | 12 | ok | 1 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path detected: ../input. Consider using configuration files or environment variables.", "fix": "Not specified", "benefits": "Not specified", "location": "Line 35"}] | A | no applicable ML-specific findings | [] | ["Hardcoded file path"] | 12 | A |
3,177 | test = pd.read_csv("../input/test.csv")
train = pd.read_csv("../input/train.csv") | No | 5 | 45 | Data_Extraction | load_from_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
3,178 | train.sample()
| No | 5 | 41 | Debug | show_table | 4,011,534 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}] | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | [] | 12 | B |
3,179 | #check for missing values
train.info() | No | 5 | 40 | Debug | show_table_attributes | 4,011,534 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}] | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | [] | 12 | B |
3,180 | sns.heatmap(train.isnull(),cbar = False) | No | 5 | 80 | Visualization | heatmap | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
3,181 | distance=pd.DataFrame(train,columns = ['Horizontal_Distance_To_Hydrology','Horizontal_Distance_To_Roadways',
'Hillshade_Noon','Horizontal_Distance_To_Fire_Points'])
for column in distance:
plt.figure()
distance.boxplot([column]) | Yes | 4 | 12 | Data_Transform | create_dataframe | 4,011,534 | 1 | A | 0 | 1 | 1 | 0 | 0 | 5 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 12 | A |
3,183 | #Cover type is the target to be predicted.
#Train test split
x_train,x_test,y_train,y_test= train_test_split(train.drop('Cover_Type',axis = 1),train['Cover_Type'],test_size = 0.3,random_state = 17) | No | 5 | 13 | Data_Transform | split | 4,011,534 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Valida... | B | Cross Validation Checker=low, Cross-validation not detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}] | ["Column Selection Checker"] | 12 | B |
3,184 | #Building logistic regression model
logreg = LogisticRegression()
logreg.fit(x_train,y_train) | Yes | 5 | 7 | Model_Train | train_model | 4,011,534 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 5 | 5 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Scaler Missing Checker", "fix": "Apply scaling before scaling-sensitive operations.", "benefits": "Improves model performance and accuracy.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation... | C | Cross Validation Checker=low, Scaler Missing Checker=medium | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Scaler Missing Checker", "severity": "medium"}] | ["Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 12 | C |
3,185 | #Predicting logistic regression results
logreg.predict(x_test) | No | 5 | 48 | Model_Evaluation | predict_on_test | 4,011,534 | 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"] | 12 | A |
3,186 | #Logistic regression test scores
score = logreg.score(x_test, y_test)
print(score) | No | 5 | 49 | Model_Evaluation | compute_test_metric | 4,011,534 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Unit Testing Checker", "fix": "Write unit tests for data processing and model components.", "benefits": "Ensures code reliability and prevents bugs.", "location": ""}] | A | no applicable ML-specific findings | [] | ["Unit Testing Checker"] | 12 | A |
3,187 | #Random Forest
from sklearn.ensemble import RandomForestClassifier
from sklearn.tree import DecisionTreeClassifier | No | 5 | 22 | Environment | import_modules | 4,011,534 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 12 | A |
3,188 | tree_model = DecisionTreeClassifier()
ensemble_model = RandomForestClassifier()
| No | 5 | 4 | Model_Train | choose_model_class | 4,011,534 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Randomness Control Checker", "fix": "Set random_state in estimators for reproducibility.", "benefits": "Ensures reproducible results and consistent model behaviour.", "location": "Line 14"}, {"detector": "framework_specific", "framework": "ScikitL... | B | Randomness Control Checker=low | [{"type": "Randomness Control Checker", "severity": "low"}] | ["Verbose Mode Checker"] | 12 | B |
3,189 | tree_model.fit(x_train,y_train) | No | 5 | 7 | Model_Train | train_model | 4,011,534 | 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"] | 12 | B |
3,190 | ensemble_model.fit(x_train,y_train) | No | 5 | 7 | Model_Train | train_model | 4,011,534 | 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"] | 12 | B |
3,191 | tree_predict=tree_model.predict(x_test)
tree_model.score(x_test,y_test) | Yes | 4 | 48 | Model_Evaluation | predict_on_test | 4,011,534 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Unit Testing Checker", "fix": "Write unit tests for data processing and model components.", "benefits": "Ensures code reliability and prevents bugs.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Excepti... | A | no applicable ML-specific findings | [] | ["Exception Handling Checker", "Unit Testing Checker"] | 12 | A |
3,192 | ensemble_predict= ensemble_model.predict(test)
print (ensemble_predict)
ensemble_model.score(x_test,y_test) | Yes | 4 | 48 | Model_Evaluation | predict_on_test | 4,011,534 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | 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"] | 12 | A |
3,194 | submission.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 |
3,195 | x_test.shape
test.shape
| No | 5 | 58 | Debug | show_shape | 4,011,534 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 12 | A |
3,196 | #current public score is 0.66,this should be improved
#checking the variance of each feature
train1 = train
test1 = test
sel = VarianceThreshold(threshold=(.8 * (1 - .8)))
sel.fit_transform(train1)
train1.head(40)
#this is based on this article ,https://scikit-learn.org/stable/modules/feature_selection.html
#could se... | Yes | 3 | 86 | Model_Interpretation | features_selection | 4,011,534 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 7 | 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... | D | Cross Validation Checker=low, Cross-validation not detected=low, Data Leakage Checker=high, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}, {"type": "No random seed setting detected", "severity": "low"}] | ["Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 12 | D |
3,197 | tree_model.fit | No | 5 | 7 | Model_Train | train_model | 4,011,534 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 12 | A |
3,198 | tree_model.predict(test1)
tree_model.score(x_test,y_test) | Yes | 4 | 48 | Model_Evaluation | predict_on_test | 4,011,534 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Unit Testing Checker", "fix": "Write unit tests for data processing and model components.", "benefits": "Ensures code reliability and prevents bugs.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Excepti... | A | no applicable ML-specific findings | [] | ["Exception Handling Checker", "Unit Testing Checker"] | 12 | A |
3,199 | pd.DataFrame([train.mean(), train.std(), train.var()], index=['Mean', 'Std. dev', 'Variance'])
| No | 3 | 12 | Data_Transform | create_dataframe | 4,011,534 | 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": "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"}] | [] | 12 | B |
3,201 | x=pd.DataFrame(ensemble_model.feature_importances_,
index=x_train.columns, columns=['Importance']).sort_values(
by='Importance', ascending=False)[:10]
print(x) | No | 4 | 79 | Visualization | model_coefficients | 4,011,534 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}] | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | [] | 12 | B |
3,202 | #Modelling based on important features alone
train2 = train
test2 = test
train_imp = train2[['Id','Elevation','Horizontal_Distance_To_Roadways','Horizontal_Distance_To_Fire_Points',
'Horizontal_Distance_To_Hydrology','Vertical_Distance_To_Hydrology','Hillshade_9am',
'Aspect','Hil... | No | 5 | 12 | Data_Transform | create_dataframe | 4,011,534 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 12 | A |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.