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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
5,158 | train_merge4.dtypes | No | 5 | 70 | Debug | show_data_types | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,159 | train_merge4.isnull().sum() | No | 5 | 39 | EDA | count_missing_values | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,160 | cat_col=list(set(train_merge4.columns)-set(train_merge4._get_numeric_data().columns)) | 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 |
5,161 | train_merge4=categorical_conversion(train_merge4,cat_col) | No | 5 | 16 | Data_Transform | data_type_conversions | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,162 | def label_encoding_conversion(df,cat_col):
le=preprocessing.LabelEncoder()
for i in range(len(cat_col)):
df[cat_col[i]]=le.fit_transform(df[cat_col[i]])
return df | No | 5 | 20 | Data_Transform | categorify | null | 1 | A | 0 | 2 | 1 | 0 | 0 | 5 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,163 | train_merge4.columns | No | 5 | 71 | Debug | show_columns | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,164 | train_merge4=label_encoding_conversion(train_merge4,cat_col) | No | 5 | 20 | Data_Transform | categorify | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,165 | train_merge4.drop(['id'],axis=1,inplace=True) | 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 |
5,166 | target=train_merge4[['fault_severity']] | 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 |
5,167 | train_merge4.drop(['fault_severity'],axis=1,inplace=True) | 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 |
5,168 | test_merge1=merge_fn(test,event_type.drop_duplicates(subset=['id']),'id','left')
test_merge2=merge_fn(test_merge1,severity_type.drop_duplicates(subset=['id']),'id','left')
test_merge3=merge_fn(test_merge2,log_feature.drop_duplicates(subset=['id']),'id','left')
test_merge4=merge_fn(test_merge3,resource_type.drop_duplica... | No | 5 | 32 | Data_Transform | merge | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,169 | test_merge4.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 |
5,170 | severity_type.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 |
5,171 | test_merge4.head(2) | 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 |
5,172 | cat_col | No | 5 | 53 | Other | something_strange | null | 1 | A | 0 | 0 | 0 | 1 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,173 | test_merge4=label_encoding_conversion(test_merge4,cat_col) | No | 5 | 20 | Data_Transform | categorify | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,174 | test_merge4.dtypes | No | 5 | 70 | Debug | show_data_types | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,175 | test_merge4.drop(['id'],axis=1,inplace=True) | 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 |
5,176 | test_merge4.columns | No | 5 | 71 | Debug | show_columns | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,177 | lr=LogisticRegression()
lr.fit(train_merge4,target)
lr_pred=lr.predict(test_merge4)
accuracy_score(pd.DataFrame(lr.predict(train_merge4)),target) | No | 3 | 7 | Model_Train | train_model | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,178 | rf=RandomForestClassifier()
rf.fit(train_merge4,target)
rf_pred=rf.predict(test_merge4)
accuracy_score(pd.DataFrame(rf.predict(train_merge4)),target) | No | 3 | 71 | Debug | show_columns | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,179 |
nb=GaussianNB()
nb.fit(train_merge4,target)
nb.predict(test_merge4)
accuracy_score(pd.DataFrame(nb.predict(train_merge4)),target) | Yes | 3 | 7 | Model_Train | train_model | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,180 |
dt=tree.DecisionTreeClassifier()
dt.fit(train_merge4,target)
dt.predict(test_merge4)
accuracy_score(pd.DataFrame(dt.predict(train_merge4)),target) | Yes | 3 | 7 | Model_Train | train_model | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,181 |
svc_ml=svm.SVC()
svc_ml.fit(train_merge4,target)
svc_ml.predict(test_merge4)
accuracy_score(pd.DataFrame(svc_ml.predict(train_merge4)),target) | Yes | 3 | 7 | Model_Train | train_model | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,182 |
ada=AdaBoostClassifier()
ada.fit(train_merge4,target)
ada.predict(test_merge4)
accuracy_score(pd.DataFrame(ada.predict(train_merge4)),target) | Yes | 3 | 7 | Model_Train | train_model | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,183 |
knn=KNeighborsClassifier()
knn.fit(train_merge4,target)
knn.predict(test_merge4)
accuracy_score(pd.DataFrame(knn.predict(train_merge4)),target) | Yes | 3 | 7 | Model_Train | train_model | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,184 |
gb=ensemble.GradientBoostingClassifier()
gb.fit(train_merge4,target)
gb_pre=gb.predict(test_merge4)
accuracy_score(pd.DataFrame(gb.predict(train_merge4)),target) | Yes | 3 | 7 | Model_Train | train_model | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,185 | list1=[]
tuple_l=()
def data_modeling(X,target,model):
for i in range(len(model)):
ml=model[i]
ml.fit(X,target)
pred=ml.predict(X)
acc_score=accuracy_score(pd.DataFrame(ml.predict(X)),target)
tuple_l=(ml.__class__.__name__,acc_score)
list1.append(tuple_l)
prin... | Yes | 2 | 7 | Model_Train | train_model | null | 1 | A | 1 | 2 | 1 | 0 | 5 | 18 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,186 | modelscore_df=pd.DataFrame(model_score_output,columns=['Classifier',"Accuracy score"])' | Yes | 5 | 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 |
5,187 | modelscore_df | Yes | 5 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 1 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,188 | modelscore_df['classifier code']=np.arange(8) | No | 5 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,189 | modelscore_df.plot.bar(x='classifier code', y='Accuracy score', rot=0) | No | 3 | 12 | Data_Transform | create_dataframe | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,190 | predict_test=rf.predict_proba(test_merge4)
pred_df=pd.DataFrame(predict_test,columns=['predict_0', 'predict_1', 'predict_2'])
submission=pd.concat([test[['id']],pred_df],axis=1)
submission.to_csv('sub.csv',index=False,header=True)
| No | 4 | 25 | Data_Export | save_to_csv | 2,708,187 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | 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"] | 12 | A |
5,191 | import pandas as pd
train = pd.read_csv("../input/train_users.csv")
test = pd.read_csv("../input/test_users.csv")
sessions = pd.read_csv("../input/sessions.csv") | No | 5 | 45 | Data_Extraction | load_from_csv | 25,814 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 4 | 2 | [{"detector": "general_ml", "framework": "General ML", "name": "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "fix": "Not specified", "benefits": "Not specified", "location": ""}, {"detector": "general_ml", "framework": "General ML", "name": "Har... | A | no applicable ML-specific findings | [] | ["Hardcoded file path", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness."] | 5 | A |
5,192 | for data in (train, test):
data['year_created'] = data['date_account_created'].apply(lambda x: 'nan' if str(x) == 'nan' else int(str(x)[:4]) )
data['month_created'] = data['date_account_created'].apply(lambda x: 'nan' if str(x) == 'nan' else int(str(x)[5:7]))
data['week_created'] = data['date_account_crea... | No | 5 | 8 | Data_Transform | feature_engineering | 25,814 | 1 | A | 0 | 7 | 13 | 0 | 0 | 7 | 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"] | 5 | A |
5,193 | for data in (train, test):
data.drop(['date_account_created'], axis=1,inplace=True)
data.drop(['date_first_booking'], axis=1,inplace=True)
train.head() | Yes | 5 | 10 | Data_Transform | drop_column | 25,814 | 1 | A | 0 | 1 | 1 | 0 | 0 | 4 | ok | 3 | 2 | [{"detector": "framework_specific", "framework": "Pandas", "name": "InPlace Checker", "fix": "Assign operations to a new DataFrame variable.", "benefits": "Prevents data loss and improves code clarity.", "location": "Line 7"}, {"detector": "framework_specific", "framework": "Pandas", "name": "InPlace Checker", "fix": "... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["InPlace Checker"] | 5 | B |
5,194 | train = pd.merge(train, sessions, how="left", left_on=["id"], right_on=["user_id"])
test = pd.merge(test, sessions, how="left", left_on=["id"], right_on=["user_id"]) | No | 5 | 32 | Data_Transform | merge | 25,814 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 5 | A |
5,195 | countries = pd.read_csv("../input/countries.csv")
countries.head() | Yes | 4 | 45 | Data_Extraction | load_from_csv | 25,814 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 1 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path detected: ../input/countries.csv. Consider using configuration files or environment variables.", "fix": "Not specified", "benefits": "Not specified", "location": "Line 6"}] | A | no applicable ML-specific findings | [] | ["Hardcoded file path"] | 5 | A |
5,196 | ga_train['trainrow'] = np.arange(ga_train.shape[0])
ga_test['testrow'] = np.arange(ga_test.shape[0]) | No | 4 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,197 | b"# brandtransforminverse_transformbrand\nbrand_encoder = LabelEncoder().fit(device_brand['phone_brand'])\ndevice_brand['brand'] = brand_encoder.transform(device_brand['phone_brand'])\nga_train['brand'] = device_brand['brand'] # device_iddevice_id\nga_test['brand'] = device_brand['brand']\n# devicetrainrow,brand1device... | Yes | 4 | 20 | Data_Transform | categorify | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,198 | m = device_brand.phone_brand.str.cat(device_brand.device_model)
modelencoder = LabelEncoder().fit(m)
device_brand['model'] = modelencoder.transform(m)
ga_train['model'] = device_brand['model']
ga_test['model'] = device_brand['model']
Xtr_model = csr_matrix((np.ones(ga_train.shape[0]),
(ga_train.... | Yes | 4 | 20 | Data_Transform | categorify | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 10 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,199 | b"# app\napp_encoder = LabelEncoder().fit(app_events['app_id'])\napp_events['app'] = app_encoder.transform(app_events['app_id'])" | No | 5 | 20 | Data_Transform | categorify | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,200 | b"napps = len(app_encoder.classes_)\n# devicetrainrow/testrow,app1deviceapp\nd = device_apps.dropna(subset=['trainrow']) # trainrowtestrowNaN\nXtr_app = csr_matrix((np.ones(d.shape[0]), (d['trainrow'], d['app'])), shape=[ga_train.shape[0],napps])\nd = device_apps.dropna(subset=['testrow']) \nXte_app = csr_matrix((np.on... | No | 3 | 17 | Data_Transform | correct_missing_values | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,201 | b"# appapp_labels\n# app_labelsappevents\napp_labels = app_labels.loc[app_labels.app_id.isin(app_events.app_id.unique())]\napp_labels['app'] = app_encoder.transform(app_labels['app_id'])\n# label\nlabel_encoder = LabelEncoder().fit(app_labels['label_id'])\napp_labels['label'] = label_encoder.transform(app_labels['label... | No | 4 | 20 | Data_Transform | categorify | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,202 | b"nlabels = len(label_encoder.classes_) # csr_matrixshape\nd = device_labels.dropna(subset=['trainrow'])\nXtr_label = csr_matrix((np.ones(d.shape[0]), (d.trainrow, d.label)), shape=(ga_train.shape[0],nlabels))\nd = device_labels.dropna(subset=['testrow'])\nXte_label = csr_matrix((np.ones(d.shape[0]), (d.testrow, d.labe... | No | 3 | 17 | Data_Transform | correct_missing_values | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,203 | Xtrain = hstack((Xtr_brand, Xtr_model, Xtr_app, Xtr_label), format='csr')
Xtest = hstack((Xte_brand, Xte_model, Xte_app, Xte_label), format='csr')
print(Xtrain.shape, Xtest.shape) | No | 4 | 11 | Data_Transform | concatenate | 128,409 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 2 | A |
5,204 | target_encoder = LabelEncoder().fit(ga_train['group'])
y = target_encoder.transform(ga_train['group'])
nclasses = len(target_encoder.classes_)
#app_labels | No | 5 | 20 | Data_Transform | categorify | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,208 | from sklearn.model_selection import cross_val_score
from sklearn.ensemble import RandomForestClassifier
rdf = RandomForestClassifier(n_estimators=50, max_depth=None,
min_samples_split=2, random_state=0) | No | 5 | 4 | Model_Train | choose_model_class | 128,409 | 1 | A | 1 | 0 | 0 | 0 | 5 | 4 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Verbose Mode Checker", "fix": "Enable verbose mode for long training processes.", "benefits": "Provides better insights into model training progress.", "location": "Line 5"}] | A | no applicable ML-specific findings | [] | ["Verbose Mode Checker"] | 2 | A |
5,209 | rdf.fit(Xtrain[:70000], y[:70000])
pred = rdf.predict_proba(Xtrain[70001:])
log_loss(y[70001:], pred) | No | 3 | 28 | Model_Train | compute_train_metric | 128,409 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 9 | 8 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}] | ["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"] | 2 | B |
5,210 | pred_rdf = rdf.predict(Xtrain[70001:])
np.mean(pred_rdf==y[70001:]) | No | 4 | 28 | Model_Train | compute_train_metric | 128,409 | 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"] | 2 | A |
5,211 | pred = pd.DataFrame(rdf.predict_proba(Xtrain[70001:]), index=ga_train.iloc[70001:].index, columns=target_encoder.classes_)
pred.head() | No | 3 | 12 | Data_Transform | create_dataframe | 128,409 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | 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"] | 2 | A |
5,212 | predgroup = pd.DataFrame(y[70001:], index=ga_train.iloc[70001:].index)
predgroup.head() | No | 4 | 12 | Data_Transform | create_dataframe | 128,409 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 2 | A |
5,213 | files = [
'countries',
'age_gender_bkts',
'test_users',
'train_users',
'sessions'
]
data = {}
for f in files:
data[f] = pd.read_csv('../input/' + f + '.csv') | No | 4 | 45 | Data_Extraction | load_from_csv | 26,724 | 1 | A | 0 | 1 | 1 | 0 | 0 | 10 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path d... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Hardcoded file path"] | 2 | A |
5,214 | results.to_csv('dummy_results.csv', index=False) | No | 5 | 25 | Data_Export | save_to_csv | 26,724 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 2 | A |
5,215 | # Imports
# pandas
import pandas as pd
from pandas import Series,DataFrame
# numpy, matplotlib, seaborn
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('whitegrid')
%matplotlib inline
# machine learning
from sklearn.linear_model import LogisticRegression
from sklearn.svm impor... | No | 3 | 22 | Environment | import_modules | 27,260 | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 1 | null |
5,216 | #### import the data
train_users = pd.read_csv('../input/train_users.csv')
test_users = pd.read_csv('../input/test_users.csv')
gender = pd.read_csv('../input/age_gender_bkts.csv')
sessions = pd.read_csv('../input/sessions.csv')
countries = pd.read_csv('../input/countries.csv')
all_users = pd.concat((train_users, t... | No | 4 | 45 | Data_Extraction | load_from_csv | 27,260 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | ok | 6 | 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."] | 1 | A |
5,218 | ##### the age variable has a few missing values.. let's go ahead and put the average in for these
average_age = train_users["age"].mean()
train_users["age"][np.isnan(train_users["age"])] = average_age
test_users["age"][np.isnan(test_users["age"])] = average_age' | No | 5 | 17 | Data_Transform | correct_missing_values | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,219 | #### looking at the country distribution through a couple of variables
fig, (axis1, axis2, axis3, axis4, axis5, axis6) = plt.subplots(6,1,figsize=(15,30))
sns.countplot(x='country_destination', data=train_users, palette="husl", ax=axis1)
sns.countplot(x='signup_flow', hue = "country_destination", data=train_users, pa... | No | 5 | 33 | Visualization | distribution | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,220 | ######## need to change the format of our variables so we can use the algo
# signup_method
train_users["signup_method"] = (train_users["signup_method"] == "basic").astype(int)
test_users["signup_method"] = (test_users["signup_method"] == "basic").astype(int)
# signup_flow
train_users["signup_flow"] = (train_users["s... | No | 5 | 16 | Data_Transform | data_type_conversions | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,221 | #### clense the data of non-numeric values
from sklearn import preprocessing
for f in train_users.columns:
if f == "country_destination" or f == "id": continue
if train_users[f].dtype == 'object':
lbl = preprocessing.LabelEncoder()
lbl.fit(np.unique(list(train_users[f].values) + list(test_use... | No | 5 | 20 | Data_Transform | categorify | null | 1 | A | 0 | 4 | 6 | 0 | 0 | 8 | ok | 9 | 7 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Pipeline Checker", "fix": "Use Pipelines for all scikit-learn estimators.", "benefits": "Prevents data leakage and ensures correct model evaluation.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross V... | D | Cross Validation Checker=low, Data Leakage Checker=high, No random seed setting detected=low, Pipeline Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}, {"type": "No random seed setting detected", "severity": "low"}, {"type": "Pipeline Checker", "severity": "low"}] | ["Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 0 | D |
5,222 | # define training and testing sets
X_train = train_users.drop(["country_destination", "id", 'booked', 'age_range'],axis=1)
Y_train = train_users["country_destination"]
X_test = test_users.drop(['id', 'age_range'],axis=1).copy()
##In' | 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 |
5,223 | # modify country_destination to numerical values
country_num_dic = {'NDF': 0, 'US': 1, 'other': 2, 'FR': 3, 'IT': 4, 'GB': 5, 'ES': 6, 'CA': 7, 'DE': 8, 'NL': 9, 'AU': 10, 'PT': 11}
num_country_dic = {y:x for x,y in country_num_dic.items()}
Y_train = Y_train.map(country_num_dic) | No | 5 | 20 | Data_Transform | categorify | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,224 | ### Xgboost
params = {"objective": "multi:softmax", "num_class": 12}
T_train_xgb = xgb.DMatrix(X_train, Y_train)
X_test_xgb = xgb.DMatrix(X_test)
gbm = xgb.train(params, T_train_xgb, 20)
Y_pred = gbm.predict(X_test_xgb) | No | 3 | 20 | Data_Transform | categorify | 27,260 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | 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, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}] | ["Exception Handling Checker", "Unit Testing Checker"] | 1 | B |
5,225 | # Create submission
country_df = pd.DataFrame({
"id": test_users["id"],
"country": Y_pred
})
submission = DataFrame(columns=["id", "country"])
# sort countries according to most probable destination country
for key in country_df['country'].value_counts().index:
submission = pd.concat([submis... | No | 5 | 55 | Data_Export | prepare_output | null | 1 | A | 0 | 1 | 1 | 0 | 0 | 7 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,226 | ##### add ndf to everyone
ndf_only = pd.DataFrame(test_users['id'])
ndf_only['country'] = 'NDF'
##submission_final = pd.concat([submission, ndf_only])
ndf_only.to_csv('airbnb.csv', index=False) | No | 4 | 25 | Data_Export | save_to_csv | 27,260 | 2 | B | 1 | 0 | 0 | 0 | 5 | 3 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 1 | B |
5,227 | ###### uh are the previous submissions formatted incorrectly or something?
######## checking via baseline submission
result = []
for index, row in test_users.iterrows():
if isinstance(row['date_first_booking'], float):
result.append([row['id'], 'NDF'])
result.append([row['id'], 'US'])
result... | No | 4 | 55 | Data_Export | prepare_output | 27,260 | 1 | A | 0 | 2 | 4 | 0 | 0 | 15 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 1 | A |
5,228 | ##result
results = pd.DataFrame(result)
results.columns = ['id', 'country']
results[results['id'] == 'qe9gwamyfk'] | No | 5 | 55 | Data_Export | prepare_output | 27,260 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 1 | A |
5,229 | # Imports
# pandas
import pandas as pd
from pandas import Series,DataFrame
# numpy, matplotlib, seaborn, sklearn
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.ensemble import RandomForestClassifier
sns.set_style('whitegrid')
##%matplotlib inline
#### import the data
train... | No | 3 | 22 | Environment | import_modules | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
5,230 | language_distance = {'language' : ['en', 'du', 'fr', 'es'],
'levenshtein_distance_from_en' : [0, 72.61, 92.06, 92.25]}
language_distance = pd.DataFrame(language_distance)
train_users = pd.merge(train_users, language_distance, on = 'language', how = 'left')
test_users = pd.merge(test_users, langua... | No | 5 | 32 | Data_Transform | merge | 29,721 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 2"}] | A | no applicable ML-specific findings | [] | ["Import Checker"] | 5 | A |
5,231 |
########## fill in the missing values
train_users['levenshtein_distance_from_en'].fillna(-1)
test_users['levenshtein_distance_from_en'].fillna(-1) | No | 5 | 17 | Data_Transform | correct_missing_values | 29,721 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 2"}, {"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection C... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Column Selection Checker", "Import Checker"] | 5 | B |
5,232 | ##train_users['year_account_creation'] = pd.DatetimeIndex(train_users['date_account_created']).year
train_users['timestamp_first_active'] = train_users['timestamp_first_active'].astype(str)
train_users['date_account_created'] = pd.to_datetime(train_users['date_account_created'])
#### converting the first active day t... | No | 3 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,238 | #np.any(np.isnan(train_users['id']))
#print(np.all(np.isfinite(col)))
#np.isnan(train_users.any())
#np.isfinite(train_users.any())
#np.isnan(test_users.any())
#np.isfinite(test_users.any())
#train_users.head()
X_train = train_users_imputed.drop(['signup_app', 'affiliate_provider', 'affiliate_channel', 'levensht... | No | 3 | 21 | Data_Transform | prepare_x_and_y | 29,721 | 3 | C | 3 | 0 | 0 | 0 | 15 | 3 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 2"}, {"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection C... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Column Selection Checker", "Import Checker"] | 5 | C |
5,239 |
###### look at variable importance in the model
importances = clf.feature_importances_
indices = np.argsort(importances)[::-1]
# Print the feature ranking
print("Feature ranking:")
for f in indices:
print(X_train.columns[f], importances[f])
#print("%d. feature %d (%f)" % (f + 1, indices[f], importances[... | No | 5 | 86 | Model_Interpretation | features_selection | 29,721 | 1 | A | 1 | 1 | 1 | 0 | 5 | 5 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 2"}, {"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection C... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Import Checker"] | 5 | A |
5,240 | ### alright, if none of the entries for an id is NDF, then set the 5th obs == NDF
no_ndf_ppl = top_5_records[~top_5_records['id'].isin(top_5_records['id'][top_5_records['variable'] == 'NDF'])]
ndf_ppl = top_5_records[top_5_records['id'].isin(top_5_records['id'][top_5_records['variable'] == 'NDF'])]
no_ndf_ppl_first = ... | No | 2 | 17 | Data_Transform | correct_missing_values | 29,721 | 1 | A | 0 | 0 | 0 | 0 | 0 | 13 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 2"}, {"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection C... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Import Checker"] | 5 | A |
5,241 | #Importing all dependencies
import pandas as pd
import numpy as np
from sklearn.preprocessing import LabelEncoder
from sklearn.cross_validation import train_test_split
from sklearn.preprocessing import StandardScaler
#algorithms
from xgboost.sklearn import XGBClassifier
from sklearn.svm import SVC
from sklearn.neighb... | No | 5 | 22 | Environment | import_modules | 31,420 | 1 | A | 0 | 0 | 0 | 0 | 0 | 11 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 10 | A |
5,242 | #Loading datasets
data_dir = "../input/"
train_users = pd.read_csv(data_dir + 'train_users_2.csv',parse_dates=['date_account_created','timestamp_first_active','date_first_booking'], index_col=False)
sessions=pd.read_csv(data_dir + 'sessions.csv')
test_users=pd.read_csv(data_dir + 'test_users.csv', parse_dates=['date_ac... | No | 5 | 45 | Data_Extraction | load_from_csv | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,243 | #Printing the columns
print(train_users.columns)
print(test_users.columns) | No | 5 | 71 | Debug | show_columns | 31,420 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 10 | A |
5,244 | #Mark test and train users and merge them for data preparation
train_users['type']='Train'
test_users['country_destination']='NULL'
test_users['type']='Test'
users = pd.concat([train_users, test_users], ignore_index=True) | No | 5 | 11 | Data_Transform | concatenate | 31,420 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | 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"] | 10 | A |
5,245 | #verify the counts
print('# of train users: ',train_users.id.count())
print('# of test users: ',test_users.id.count())
print('# of total users: ',train_users.id.count()+test_users.id.count())
print('# of users: ',users.id.count()) | No | 5 | 72 | EDA | count_values | 31,420 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "general_ml", "framework": "General ML", "name... | B | Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}] | [] | 10 | B |
5,246 | def feature_engineering(data):
#Date account created
data['Day_Acct_Created'] = data['date_account_created'].dt.day
data['Month_Acct_Created'] = data['date_account_created'].dt.month
data['Year_Acct_Created'] = data['date_account_created'].dt.year
data['Hour_Acct_Created'] = data['date_account_crea... | No | 4 | 8 | Data_Transform | feature_engineering | 31,420 | 1 | A | 2 | 1 | 0 | 0 | 10 | 34 | ok | 27 | 12 | [{"detector": "framework_specific", "framework": "Pandas", "name": "InPlace Checker", "fix": "Assign operations to a new DataFrame variable.", "benefits": "Prevents data loss and improves code clarity.", "location": "Line 38"}, {"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker"... | D | Cross Validation Checker=low, Cross-validation not detected=low, Data Leakage Checker=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": "No random seed setting detected", "severity": "low"}, {"type": "Pipeline Checker", "severity": "low"}] | ["Column Selection Checker", "Exception Handling Checker", "InPlace Checker", "Missing function docstring", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker", "Verbose Mode Checker"] | 10 | D |
5,247 | temp=feature_engineering(users) | No | 5 | 8 | Data_Transform | feature_engineering | 31,420 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 10 | A |
5,248 | #Manual feature engineering
#gender
#Converting categorial to numeric
temp.gender[temp.gender=='nan']='-1'
temp.gender[temp.gender=='MALE']='0'
temp.gender[temp.gender=='FEMALE']='1'
temp.gender[temp.gender=='OTHER']='2'
#first_affiliate_tracked
temp.first_affiliate_tracked[temp.first_affiliate_tracked=='nan']='-1'
t... | No | 5 | 20 | Data_Transform | categorify | 31,420 | 1 | A | 0 | 0 | 0 | 0 | 0 | 13 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 10 | A |
5,249 | #Split train and test sets
train=temp[temp['type']=='Train']
test=temp[temp['type']=='Test']
print(train.id.count(),test.id.count()) | No | 5 | 13 | Data_Transform | split | 31,420 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Valida... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Column Selection Checker"] | 10 | B |
5,250 | #Creating train_xx and target_xx
train_xx=train[[ 'Day_Acct_Created',
'Month_Acct_Created', 'Year_Acct_Created', 'Hour_Acct_Created',
'DayOfWeek_Acct_Created', 'WeekOfYear_Acct_Created', 'Day_First_Active',
'Month_First_Active', 'Year_First_Active', 'Hour_First_Active',
'DayOfWeek_First_Acti... | No | 5 | 21 | Data_Transform | prepare_x_and_y | 31,420 | 1 | A | 0 | 0 | 0 | 0 | 0 | 21 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 10 | A |
5,251 | target_xx.head() | No | 5 | 41 | Debug | show_table | 31,420 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 10 | A |
5,252 | #Splitting train and test
X = train_xx
y = target_xx
X_test = predict_xx
#Classifier
xgb = RandomForestClassifier()
xgb.fit(X, y)
y_pred = xgb.predict_proba(X_test)
| Yes | 4 | 48 | Model_Evaluation | predict_on_test | 31,420 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | ok | 11 | 9 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low, Randomness Control Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}, {"type": "Randomness Control Checker", "severity": "low"}] | ["Dependent Threshold Checker", "Exception Handling Checker", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker", "Verbose Mode Checker"] | 10 | B |
5,253 | test['x']=y_pred
output=test[['id','x']]
| No | 5 | 55 | Data_Export | prepare_output | 31,420 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 10 | A |
5,254 | output.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 |
5,255 | %matplotlib inline
import numpy as np
import pandas as pd
import datetime
from sklearn.preprocessing import LabelEncoder
from xgboost.sklearn import XGBClassifier
import matplotlib.pyplot as plt | No | 5 | 23 | Environment | set_options | 35,269 | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
5,256 | #Loading data
df_train_raw = pd.read_csv('../input/train_users_2.csv')
df_test = pd.read_csv('../input/test_users.csv')
labels = df_train_raw['country_destination'].values
df_train = df_train_raw.drop(['country_destination'], axis=1)
id_test = df_test['id']
piv_train = df_train.shape[0] | No | 4 | 45 | Data_Extraction | load_from_csv | 35,269 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,257 | #Creating a DataFrame with train+test data
df_all = pd.concat((df_train, df_test), axis=0, ignore_index=True)
#Removing id and date_first_booking
df_all = df_all.drop(['id', 'date_first_booking'], axis=1)
#Filling nan
df_all = df_all.fillna(-1)
#####Feature engineering#######
#date_account_created
df_all.date_account_... | Yes | 4 | 8 | Data_Transform | feature_engineering | 35,269 | 1 | A | 0 | 1 | 1 | 0 | 0 | 29 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,258 | #Splitting train and test
vals = df_all.values
X_train = vals[:piv_train]
le = LabelEncoder()
y_train = le.fit_transform(labels)
X_test = vals[piv_train:] | No | 3 | 13 | Data_Transform | split | 35,269 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,260 | np.random.seed(42)
samples = np.random.choice(piv_train, 50000)
X_train = vals[samples]
y_train = le.fit_transform(labels)[samples] | No | 5 | 21 | Data_Transform | prepare_x_and_y | 35,269 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
5,261 | #Python Modules
import numpy as np
import pandas as pd
from sklearn.preprocessing import LabelEncoder
import xgboost as xgb
import operator | No | 5 | 22 | Environment | import_modules | 68,482 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
5,262 | # Loading data
df_train = pd.read_csv('../input/train_users_2.csv')
df_test = pd.read_csv('../input/test_users.csv')
labels = df_train['country_destination'].values
df_train = df_train.drop(['country_destination'], axis=1)
id_test = df_test['id']
piv_train = df_train.shape[0] | No | 3 | 45 | Data_Extraction | load_from_csv | 68,482 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | ok | 5 | 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 | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Column Selection Checker", "Hardcoded file path", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness."] | 3 | B |
5,263 | # Creating a DataFrame with train+test data
df_all = pd.concat((df_train, df_test), axis=0, ignore_index=True)
#Removing id and date_first_booking
df_all = df_all.drop(['id', 'date_first_booking'], axis=1)
#Filling nan
df_all = df_all.fillna(-1) | Yes | 4 | 17 | Data_Transform | correct_missing_values | 68,482 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
5,264 | # date_account_created
dac = np.vstack(
df_all.date_account_created.astype(str).apply(
lambda x: list(map(int, x.split('-')))
).values
)
df_all['dac_year'] = dac[:,0]
df_all['dac_month'] = dac[:,1]
df_all['dac_day'] = dac[:,2]
df_all = df_all.drop(['date_account_created'], axis=1) | No | 4 | 11 | Data_Transform | concatenate | 68,482 | 1 | A | 0 | 0 | 0 | 0 | 0 | 9 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "Pandas", "name": "DataFrame Conversion Checker", "fix": "Use .to_numpy() instead of .values.", "benefits": "Ensures future compatibility and avoids unexpected behaviour.", "location": "Line 5"}, {"detector": "framework_specific", "framework": "Pandas", "name": "Column S... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "DataFrame Conversion Checker"] | 3 | A |
5,265 | # timestamp_first_active
tfa = np.vstack(
df_all.timestamp_first_active.astype(str).apply(
lambda x: list(map(int, [x[:4], x[4:6], x[6:8],
x[8:10], x[10:12],
x[12:14]]))
).values
)
df_all['tfa_year'] = tfa[:,0]
df_all['tfa_month']... | No | 3 | 8 | Data_Transform | feature_engineering | 68,482 | 1 | A | 0 | 0 | 0 | 0 | 0 | 11 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "Pandas", "name": "DataFrame Conversion Checker", "fix": "Use .to_numpy() instead of .values.", "benefits": "Ensures future compatibility and avoids unexpected behaviour.", "location": "Line 5"}, {"detector": "framework_specific", "framework": "Pandas", "name": "Column S... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "DataFrame Conversion Checker"] | 3 | A |
5,266 | # One-hot-encoding features
ohe_feats = ['gender', 'signup_method', 'signup_flow', 'language',
'affiliate_channel', 'affiliate_provider',
'first_affiliate_tracked', 'signup_app',
'first_device_type', 'first_browser']
for f in ohe_feats:
df_all_dummy = pd.get_dummies(df_all[... | No | 5 | 20 | Data_Transform | categorify | 68,482 | 1 | A | 0 | 1 | 1 | 0 | 0 | 8 | 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"] | 3 | A |
5,267 | # Splitting train and test
X = df_all.iloc[:piv_train,:]
le = LabelEncoder()
y = le.fit_transform(labels)
X_test = df_all.iloc[piv_train:,:] | No | 4 | 13 | Data_Transform | split | 68,482 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 6 | 6 | [{"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, Pipeline Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}, {"type": "Pipeline Checker", "severity": "low"}] | ["Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 3 | D |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.