id int64 0 7.95k | code_block stringlengths 1 52.9k | too_long stringclasses 2
values | marks int64 1 5 | graph_vertex_id float64 1 88 | graph_vertex_class stringclasses 12
values | graph_vertex_subclass stringclasses 70
values | kernel_id float64 25.8k 14.7M ⌀ | sqale_rating float64 1 4 | maintainability_rating stringclasses 4
values | code_smells int64 0 36 | complexity float64 0 15 ⌀ | cognitive_complexity int64 0 33 | bugs int64 0 7 | sqale_index int64 0 125 | ncloc float64 0 101 ⌀ | mlscent_analysis_status stringclasses 3
values | mlscent_smell_count int64 0 31 | mlscent_unique_smell_count int64 0 12 | mlscent_findings_json stringlengths 2 7.76k | mlscent_ml_rating stringclasses 5
values | mlscent_ml_rating_basis stringclasses 52
values | mlscent_ml_findings_json stringclasses 50
values | mlscent_ignored_findings_json stringclasses 199
values | context_line_count int64 0 33 | combined_rating stringclasses 5
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
6,203 | # This Python 3 environment comes with many helpful analytics libraries installed<br># It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python<br># For example, here\'s several helpful packages to load in <br><br>import numpy as np # linear algebra<br>import pandas as pd # data processi... | No | 5 | 88 | Debug | list_files | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,204 | train_data[\'building_id\'] = train_data[\'building_id\'].apply(lambda x: 1 if x != "0" else 0)<br> | No | 5 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,205 | # Read the training and test data
train_df = pd.read_json("../input/train.json")
test_df = pd.read_json("../input/test.json")
#Look at the size of test and train data
print("train data shape: ", train_df.shape[0]);
print("test data shape: ", test_df.shape[0]);
| Yes | 3 | 44 | Data_Extraction | load_from_disk | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,206 | def split_X_y(train_data, features):
X = train_data[features]
y = train_data[target]
return X, y
| No | 4 | 21 | Data_Transform | prepare_x_and_y | 201,234 | 2 | B | 1 | 1 | 0 | 0 | 10 | 4 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Threshold Checker", "fix": "Use threshold-independent metrics alongside threshold-dependent ones.", "benefits": "Provides a comprehensive evaluation of model performance.", "location": ""}, {"detector": "general_ml", "framework": "Genera... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Missing function docstring"] | 4 | B |
6,207 | # Convert the features like features, photos, description into numeric by computing their length<br># Generate hash for the building_id, manager_id<br>train_df["num_photos"] = train_df["photos"].apply(len)<br>train_df["num_features"] = train_df["features"].apply(len)<br>train_df["num_description_words"] = train_df["des... | No | 5 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,208 | # Select the features and prepare the Input and target variables
selected_features = ["bedrooms", "bathrooms", "price", "num_photos", "num_features", "num_description_words", "building_gen_id", "manager_gen_id"]
X = train_df[selected_features]
Y = train_df["interest_level"]
X.head()
| Yes | 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 |
6,209 | #Split the input into training and validation sets
from sklearn.model_selection import train_test_split
X_train, X_val, Y_train, Y_val = train_test_split(X, Y, test_size=0.33)
#Pass the input to the algo and calculate the loss
from sklearn.ensemble import RandomForestClassifier
algo = RandomForestClassifier(n_estimator... | Yes | 3 | 13 | Data_Transform | split | null | 2 | B | 3 | 0 | 0 | 0 | 15 | 8 | ok | 12 | 9 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low, Randomness Control Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}, {"type": "Randomness Control Checker", "severity": "low"}] | ["Dependent Threshold Checker", "Exception Handling Checker", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker", "Verbose Mode Checker"] | 0 | B |
6,210 | X_test = test_df[selected_features]
y_predict_test = algo.predict_proba(X_test)
| No | 5 | 48 | Model_Evaluation | predict_on_test | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,211 | sub = pd.DataFrame()
sub["listing_id"] = test_df["listing_id"]
for label in ["high", "medium", "low"]:
sub[label] = y_predict_test[:, labels2idx[label]]
sub.to_csv("categoral_numeric.csv", index=False)
print("process is done1")
| No | 5 | 25 | Data_Export | save_to_csv | null | 1 | A | 0 | 1 | 1 | 0 | 0 | 6 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,212 | import numpy as np
import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.preprocessing import LabelEncoder
from sklearn.model_selection import StratifiedKFold
import random
from math import exp
import xgboost as xgb
from sklearn.ensemble import RandomForestClassifier
from sklearn.... | No | 4 | 44 | Data_Extraction | load_from_disk | 213,630 | 1 | A | 0 | 0 | 0 | 0 | 0 | 17 | ok | 3 | 2 | [{"detector": "general_ml", "framework": "General ML", "name": "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "fix": "Not specified", "benefits": "Not specified", "location": ""}, {"detector": "general_ml", "framework": "General ML", "name": "Har... | A | no applicable ML-specific findings | [] | ["Hardcoded file path", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness."] | 8 | A |
6,213 | print(train_df.shape)
print(test_df.shape)
| No | 5 | 58 | Debug | show_shape | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,214 | train_df.head(5)
| No | 5 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,215 | df = pd.read_json(open("../input/train.json", "r"))
df["num_photos"] = df["photos"].apply(len)
df["num_features"] = df["features"].apply(len)
df["num_description_words"] = df["description"].apply(lambda x: len(x.split(" ")))
df["created"] = pd.to_datetime(df["created"])
df["created_year"] = df["created"].dt.year
df["c... | Yes | 4 | 8 | Data_Transform | feature_engineering | 213,630 | 1 | A | 0 | 0 | 0 | 0 | 0 | 8 | 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": "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."] | 8 | A |
6,216 | num_feats = ["bathrooms", "bedrooms", "latitude", "longitude", "price",
"num_photos", "num_features", "num_description_words",
"created_year", "created_month", "created_day"]
X = df[num_feats]
y = df["interest_level"]
X.head()
| Yes | 4 | 21 | Data_Transform | prepare_x_and_y | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,217 | X_train.loc[10000,"photos"]
| No | 5 | 14 | Data_Transform | filter | 213,630 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 8 | A |
6,218 | X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.33)
clf = RandomForestClassifier(n_estimators=1000)
clf.fit(X_train, y_train)
y_val_pred = clf.predict_proba(X_val)
log_loss(y_val, y_val_pred)
| Yes | 3 | 13 | Data_Transform | split | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,219 | df = pd.read_json(open("../input/test.json", "r"))
print(df.shape)
df["num_photos"] = df["photos"].apply(len)
df["num_features"] = df["features"].apply(len)
df["num_description_words"] = df["description"].apply(lambda x: len(x.split(" ")))
df["created"] = pd.to_datetime(df["created"])
df["created_year"] = df["created"]... | Yes | 4 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 11 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,220 | sub = pd.DataFrame()
sub["listing_id"] = df["listing_id"]
for label in ["high", "medium", "low"]:
sub[label] = y[:, labels2idx[label]]
sub.to_csv("submission_rf.csv", index=False)
| No | 5 | 25 | Data_Export | save_to_csv | null | 1 | A | 0 | 1 | 1 | 0 | 0 | 5 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,221 | %matplotlib inline<br>import matplotlib.pylab as plt<br>import numpy as np<br>import pandas as pd<br>import time as time<br>from sklearn.preprocessing import StandardScaler, Imputer, LabelBinarizer<br>from sklearn.metrics import log_loss<br>from sklearn.neural_network import MLPClassifier<br>from sklearn.grid_search im... | No | 5 | 53 | Other | something_strange | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
6,222 | def build_model(name):
clf = None
if name == 'Random Forest':
clf = RandomForestClassifier()
if name == 'gbm':
clf = GradientBoostingClassifier()
return clf
| No | 5 | 4 | Model_Train | choose_model_class | 201,234 | 1 | A | 0 | 3 | 2 | 0 | 0 | 7 | ok | 5 | 4 | [{"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 8"}, {"detector": "framework_specific", "framework": "ScikitLe... | B | Randomness Control Checker=low | [{"type": "Randomness Control Checker", "severity": "low"}] | ["Dependent Threshold Checker", "Missing function docstring", "Verbose Mode Checker"] | 4 | B |
6,223 | def fit_model(clf, X_train, y_train):
return clf.fit(X_train, y_train)
| No | 5 | 7 | Model_Train | train_model | 201,234 | 1 | A | 0 | 1 | 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 | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Dependent Threshold Checker", "Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 4 | B |
6,224 | df = pd.read_json('../input/train.json')
df_test = pd.read_json('../input/test.json')
df['created'] = pd.to_datetime(df.created)
df_test['created'] = pd.to_datetime(df_test.created) | Yes | 3 | 44 | Data_Extraction | load_from_disk | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,225 | def model_and_predict(model_name, data, features):
X, y = split_X_y(data, features)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=0)
clf = build_model(model_name)
clf = fit_model(clf, X_train, y_train)
y_pred = clf.predict(X_test)
accuracy = accuracy_sc... | Yes | 3 | 48 | Model_Evaluation | predict_on_test | 201,234 | 1 | A | 0 | 1 | 0 | 0 | 0 | 12 | ok | 10 | 8 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low, Cross-validation not detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}] | ["Dependent Threshold Checker", "Exception Handling 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"] | 4 | B |
6,226 | # Normalize
for i in range(x_train.shape[1]):
x_test[:, i] = (x_test[:, i] - np.mean(x_train[:, i]))/np.std(x_train[:, i])
x_train[:, i] = (x_train[:, i] - np.mean(x_train[:, i]))/np.std(x_train[:, i]) | No | 5 | 18 | Data_Transform | normalization | null | 1 | A | 0 | 1 | 1 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,227 | train_features = ['bathrooms', 'rooms', 'living_rooms', 'building_id', 'price_level',
'months_with_less_listings']
clf, accuracy, log_score = model_and_predict('Random Forest', train_copy, train_features)
scores.append(accuracy)
log_scores.append(log_score)
| Yes | 4 | 27 | Model_Train | predict_on_train | 201,234 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Threshold Checker", "fix": "Use threshold-independent metrics alongside threshold-dependent ones.", "benefits": "Provides a comprehensive evaluation of model performance.", "location": ""}, {"detector": "framework_specific", "framework":... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Exception Handling Checker", "Unit Testing Checker"] | 4 | A |
6,228 | test_data[\'rooms\'] = test_data[\'bedrooms\'] + test_data[\'bathrooms\']<br>test_data[\'living_rooms\'] = test_data[\'bedrooms\'] - test_data[\'bathrooms\']<br>test_data[\'even_rooms\'] = test_data[\'rooms\'].apply(lambda x : (x%2) == 0)<br><br>test_data[\'created\'] = pd.to_datetime(test_data[\'created\'])<br>test_da... | No | 5 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,229 | X_test = test_data[train_features]
y_proba = clf.predict_proba(X_test)
| No | 5 | 48 | Model_Evaluation | predict_on_test | 201,234 | 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"] | 4 | A |
6,230 | import os
import sys
import operator
import numpy as np
import pandas as pd
from scipy import sparse
import xgboost as xgb
import random
from sklearn import model_selection, preprocessing, ensemble
from sklearn.metrics import log_loss
from sklearn.feature_extraction.text import TfidfVectorizer, CountVectorizer
#input d... | No | 5 | 44 | Data_Extraction | load_from_disk | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 13 | ok | 3 | 2 | [{"detector": "general_ml", "framework": "General ML", "name": "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "fix": "Not specified", "benefits": "Not specified", "location": ""}, {"detector": "general_ml", "framework": "General ML", "name": "Har... | A | no applicable ML-specific findings | [] | ["Hardcoded file path", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness."] | 0 | A |
6,231 | #basic features
train_df["price_t"] =train_df["price"]/train_df["bedrooms"]
test_df["price_t"] = test_df["price"]/test_df["bedrooms"]
train_df["room_sum"] = train_df["bedrooms"]+train_df["bathrooms"]
test_df["room_sum"] = test_df["bedrooms"]+test_df["bathrooms"]
# count of photos #
train_df["num_photos"] = train_df... | No | 5 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 11 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,232 |
train_X = sparse.hstack([train_df[features_to_use], tr_sparse]).tocsr()
test_X = sparse.hstack([test_df[features_to_use], te_sparse]).tocsr()
target_num_map = {'high':0, 'medium':1, 'low':2}
train_y = np.array(train_df['interest_level'].apply(lambda x: target_num_map[x]))
print(train_X.shape, test_X.shape) | Yes | 4 | 21 | Data_Transform | prepare_x_and_y | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,233 | results_df = pd.DataFrame(results)
| No | 5 | 12 | Data_Transform | create_dataframe | 201,234 | 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"] | 4 | A |
6,234 | result = pd.concat([results_df, id_df], axis=1)
| No | 5 | 11 | Data_Transform | concatenate | 201,234 | 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"] | 4 | A |
6,235 | train[\'display_address\'] = train[\'display_address\'].apply(lambda x: x.strip("."))<br>train[\'display_address\'] = train[\'display_address\'].apply(lambda x: x.lower())<br>ga = train.groupby([\'display_address\'])[\'display_address\'].count().fillna(0)<br>ga = pd.DataFrame(ga)<br>ga.columns = [\'display_count\']<br... | 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 |
6,236 | # This Python 3 environment comes with many helpful analytics libraries installed<br># It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python<br># For example, here\'s several helpful packages to load in <br><br>import numpy as np # linear algebra<br>import pandas as pd # data processi... | No | 5 | 88 | Debug | list_files | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,237 | train = pd.read_json('../input/train.json')
### and test if everything OK
train.head() | Yes | 3 | 44 | Data_Extraction | load_from_disk | 232,409 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "general_ml", "framework": "General ML", "name... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Hardcoded file path"] | 5 | B |
6,238 | train['num_photos'] = train['photos'].apply(len)
train['num_features'] = train['features'].apply(len)
train['num_description_words'] = train['description'].apply(lambda x: len(x.split(' ')))
train['rooms'] = train['bathrooms'] + train['bedrooms']
ulimit = np.percentile(train.price.values, 99)
train['price'].loc[train[... | No | 5 | 8 | Data_Transform | feature_engineering | 232,409 | 1 | A | 0 | 0 | 0 | 0 | 0 | 10 | ok | 5 | 5 | [{"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 11"}, {"detector": "framework_specific", "framework": "Pandas", "name": "Column ... | 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", "DataFrame Conversion Checker"] | 5 | B |
6,239 | X = train[['bathrooms','bedrooms','price','num_photos',
'num_features','num_description_words','rooms','rooms_per_price',
'bath_per_beds','latitude','longitude','building_count','manager_count','display_count']]
y = train['labels']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_... | Yes | 4 | 21 | Data_Transform | prepare_x_and_y | 232,409 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}] | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | [] | 5 | B |
6,240 | gbc = GradientBoostingClassifier(loss='deviance', learning_rate=0.05, n_estimators=600,
subsample=1.0, criterion='friedman_mse', min_samples_split=2,
min_samples_leaf=1, min_weight_fraction_leaf=0.0,
max_depth=5, in... | Yes | 4 | 4 | Model_Train | choose_model_class | 232,409 | 1 | A | 0 | 0 | 0 | 0 | 0 | 8 | ok | 8 | 7 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low, Cross-validation not detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not 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"] | 5 | B |
6,241 | print(log_loss(y_test,out)) | No | 5 | 49 | Model_Evaluation | compute_test_metric | 232,409 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 5 | A |
6,242 |
test.loc[test['bedrooms'] == 0,'bath_per_beds'] = 0
X = test[['bathrooms','bedrooms','price','num_photos',
'num_features','num_description_words','rooms','room_per_price',
'bath_per_beds','latitude','longitude','building_count','manager_count','display_count']]
X = X.fillna(0) | No | 5 | 17 | Data_Transform | correct_missing_values | 232,409 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 5 | A |
6,243 | out = gbc.predict_proba(X) | No | 5 | 48 | Model_Evaluation | predict_on_test | 232,409 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Threshold Checker", "fix": "Use threshold-independent metrics alongside threshold-dependent ones.", "benefits": "Provides a comprehensive evaluation of model performance.", "location": ""}, {"detector": "framework_specific", "framework":... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Exception Handling Checker", "Unit Testing Checker"] | 5 | A |
6,244 | def runXGB(train_X, train_y, test_X, test_y=None, feature_names=None, seed_val=0, num_rounds=1000):<br> param = {}<br> param[\'objective\'] = \'multi:softprob\'<br> param[\'eta\'] = 0.03<br> param[\'max_depth\'] = 6<br> param[\'silent\'] = 1<br> param[\'num_class\'] = 3<br> param[\'eval_metric\'] =... | Yes | 3 | 59 | Model_Train | init_hyperparams | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,245 | result.head(3)
| No | 5 | 41 | Debug | show_table | 201,234 | 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"] | 4 | A |
6,246 | result.to_csv("submission.csv", index=False)
| No | 5 | 25 | Data_Export | save_to_csv | 201,234 | 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"] | 4 | A |
6,247 | import numpy as np
import pandas as pd | No | 5 | 22 | Environment | import_modules | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 0 | A |
6,248 | data_path = "../input/"<br>train_file = data_path + "train.json"<br>test_file = data_path + "test.json"<br>train_df = pd.read_json(train_file)<br>test_df = pd.read_json(test_file)<br><br>train_df = train_df.fillna(\'\')<br>test_df = test_df.fillna(\'\')<br><br>train_df[\'photos_num\'] = train_df.photos.apply(lambda x: ... | Yes | 3 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,249 | cols = ['bathrooms', 'bedrooms', 'building_id', \\<br> 'description', 'display_address', 'latitude', \\<br> 'longitude', 'manager_id', 'price', 'street_address', \\<br> 'photos_num', 'features_num']<br>df_merged = pd.merge(train_df, test_df, \\<br> on=cols, \\<br> ... | Yes | 3 | 32 | Data_Transform | merge | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,250 | fname = 'sample_submission.csv'
subm = pd.read_csv(data_path + fname)
subm = subm.merge(df_merged[['listing_id','interest_level']], on='listing_id') | Yes | 4 | 45 | Data_Extraction | load_from_csv | 235,856 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 2 | A |
6,251 | print('Number of duplicates = ' + str(np.sum(subm.duplicated(subset='listing_id')))) | No | 4 | 38 | EDA | count_duplicates | 235,856 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "NumPy", "name": "Missing Axis Specification", "fix": "Specify axis in array operations.", "benefits": "Improves performance and avoids unexpected behaviour.", "location": "Line 3"}] | C | Missing Axis Specification=medium | [{"type": "Missing Axis Specification", "severity": "medium"}] | [] | 2 | C |
6,252 | subm.sort_values('listing_id').loc[subm.duplicated(subset='listing_id', keep=False)].head(10) | Yes | 4 | 41 | Debug | show_table | 235,856 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 2 | A |
6,253 | print('Number of duplicates in train = ' + \\<br> str(np.sum(train_df.duplicated(subset=cols, keep=False))))<br>print('Number of duplicates in test = ' + \\<br> str(np.sum(test_df.duplicated(subset=cols, keep=False)))) | No | 5 | 38 | EDA | count_duplicates | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,254 | subm.low.loc[subm.interest_level=='low'] = 1.0
subm.medium.loc[subm.interest_level=='low'] = 0.0
subm.high.loc[subm.interest_level=='low'] = 0.0
subm.low.loc[subm.interest_level=='medium'] = 0.0
subm.medium.loc[subm.interest_level=='medium'] = 1.0
subm.high.loc[subm.interest_level=='medium'] = 0.0
subm.low.loc[subm.i... | Yes | 4 | 14 | Data_Transform | filter | 235,856 | 1 | A | 0 | 0 | 0 | 0 | 0 | 12 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 2 | A |
6,255 | subm.to_csv('submission.csv', index=True) | No | 5 | 25 | Data_Export | save_to_csv | 235,856 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 2 | A |
6,256 | # This Python 3 environment comes with many helpful analytics libraries installed<br># It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python<br># For example, here\'s several helpful packages to load in <br><br>import numpy as np # linear algebra<br>import pandas as pd # data processi... | Yes | 4 | 44 | Data_Extraction | load_from_disk | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,257 | trainingData.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 |
6,258 | sns.countplot(trainingData.interest_level, order=['low', 'medium', 'high']);
plt.xlabel('Interest Level');
plt.ylabel('Number of occurrences'); | No | 5 | 33 | Visualization | distribution | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,259 |
trainingData['numPics'] = trainingData['photos'].apply(len)
trainingData.info() | Yes | 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 |
6,260 | features = [x for sublist in trainingData[\'features\'] for x in sublist]<br><br>for x in features:<br> if "*" in x: features.remove(x)<br><br>features = set(features)<br><br>features.discard(\'<null>\')<br><br>has_ac = [ s for s in features if any(ac_name in s for ac_name in [\'A/C\', "AC", "Air Conditioning"] ) an... | No | 5 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,261 | labelEncoder = LabelEncoder()
trainingData['interest'] = labelEncoder.fit_transform(trainingData['interest_level'])
trainingDataSub = trainingData.loc[trainingData['interest']==0]
trainingDataSub = trainingDataSub.append(trainingData.loc[trainingData['interest']==1].sample(15000))
trainingDataSub = trainingDataSub.... | Yes | 3 | 21 | Data_Transform | prepare_x_and_y | 238,491 | 1 | A | 0 | 0 | 0 | 0 | 0 | 8 | 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... | B | Cross Validation Checker=low, Pipeline Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Pipeline Checker", "severity": "low"}] | ["Exception Handling Checker", "Potential data leakage: Preprocessing applied before train-test split (module-level code)", "Unit Testing Checker", "Verbose Mode Checker"] | 1 | B |
6,262 | trainingData.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 |
6,263 | from sklearn import neural_network
regr = neural_network.MLPClassifier(hidden_layer_sizes = (50,50,10))
regr.fit(X_train, y_train) | Yes | 4 | 4 | Model_Train | choose_model_class | 238,491 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 4 | 4 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 1 | B |
6,264 | deepfor = RandomForestClassifier(n_estimators=3, random_state=52)
deepfor.fit(X_train, y_train)
| Yes | 3 | 4 | Model_Train | choose_model_class | 238,491 | 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"] | 1 | B |
6,265 | testingData = pd.read_json('../input/test.json')
testingData['numPics'] = testingData['photos'].apply(len) | Yes | 4 | 44 | Data_Extraction | load_from_disk | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,266 | features = [x for sublist in testingData[\'features\'] for x in sublist]<br><br>for x in features:<br> if "*" in x: features.remove(x)<br><br>features = set(features)<br><br>features.discard(\'<null>\')<br><br>has_ac = [ s for s in features if any(ac_name in s for ac_name in [\'A/C\', "AC", "Air Conditioning"] ) and... | No | 4 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,267 | X = testingData[[\'bathrooms\', \'bedrooms\', \'latitude\', \'longitude\', \'price\', \'numPics\', \'has_ac\', \'included_offer\', \'concierge\', \'laundry\']]<br><br>predictions = regr.predict_proba(X)<br><br>output = pd.DataFrame(testingData[\'listing_id\'], columns = [\'listing_id\'])<br><br>output[\'high\'] = predi... | 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 |
6,268 | # objective is to predict a number of listing enquiries based on features
train = pd.read_json("../input/train.json", "r")
test = pd.read_json("../input/test.json", "r")
sample_sub = pd.read_csv("../input/sample_submission.csv") | Yes | 4 | 44 | Data_Extraction | load_from_disk | 238,749 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | 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."] | 4 | A |
6,269 | sample_sub.head()
# the above is what our submission is supposed to look like | No | 5 | 41 | Debug | show_table | 238,749 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 4 | A |
6,270 | from sklearn.naive_bayes import GaussianNB | 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 |
6,271 | gnb = GaussianNB() | No | 5 | 4 | Model_Train | choose_model_class | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,272 | train.index = train['listing_id']
train = train.drop('interest_level', 1)
model = gnb.fit(train, train_target) | Yes | 3 | 10 | Data_Transform | drop_column | 238,749 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | 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, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}] | ["Column Selection Checker", "Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 4 | B |
6,273 | y = model.predict_proba(test) | No | 5 | 48 | Model_Evaluation | predict_on_test | 238,749 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Threshold Checker", "fix": "Use threshold-independent metrics alongside threshold-dependent ones.", "benefits": "Provides a comprehensive evaluation of model performance.", "location": ""}, {"detector": "framework_specific", "framework":... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Exception Handling Checker", "Unit Testing Checker"] | 4 | A |
6,274 | y_dat = pd.DataFrame(y) | No | 5 | 12 | Data_Transform | create_dataframe | 238,749 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 4 | A |
6,275 | #y_dat.copy(deep = False)
y_dat.loc[:,'listing_id'] = test.index | No | 5 | 8 | Data_Transform | feature_engineering | 238,749 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 4 | A |
6,276 | y_dat.rename(columns = {'0':'medium', '1':'low', '2':'high'}, inplace = True) | No | 5 | 61 | Data_Transform | rename_columns | 238,749 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "Pandas", "name": "InPlace Checker", "fix": "Assign operations to a new DataFrame variable.", "benefits": "Prevents data loss and improves code clarity.", "location": "Line 5"}] | A | no applicable ML-specific findings | [] | ["InPlace Checker"] | 4 | A |
6,277 | data.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 |
6,278 | #medium, low, high<br>#writer = pd.ExcelWriter(\'/Users/reshmasekar/Desktop/sub.xlsx\', engine=\'xlsxwriter\')<br># Convert the dataframe to an XlsxWriter Excel object.<br>data.to_csv("sub_rf_4.csv", index = False)<br>#y_dat.to_excel("/Users/reshmasekar/Desktop") | No | 5 | 25 | Data_Export | save_to_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,279 | train.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 |
6,280 | from sklearn import neural_network
#regr = neural_network.MLPClassifier(hidden_layer_sizes = (50,50,10))
#regr.fit(X_train, y_train) | No | 5 | 22 | Environment | import_modules | 239,421 | 3 | C | 1 | 0 | 0 | 0 | 5 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 2 | C |
6,281 | from sklearn.cluster import KMeans
regr = RandomForestClassifier(n_estimators=300, random_state=52)
regr.fit(X_train, y_train)
pred = regr.predict(X_test)
print(confusion_matrix(pred, y_test))
print(accuracy_score(pred, y_test))
print(labelEncoder.classes_) | Yes | 3 | 4 | Model_Train | choose_model_class | 239,421 | 1 | A | 0 | 0 | 0 | 0 | 0 | 7 | ok | 8 | 6 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low | [{"type": "Cross Validation 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"] | 2 | B |
6,282 | import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from sklearn import linear_model
from os.path import pardir, curdir, join
| No | 5 | 22 | Environment | import_modules | 241,252 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
6,283 | df_train = pd.read_csv("../input/train.csv")
df_store = pd.read_csv("../input/store.csv")
df_test = pd.read_csv("../input/test.csv")
| No | 5 | 45 | Data_Extraction | load_from_csv | 241,252 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | 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."] | 3 | A |
6,284 | df_test['Month'] = df_test['Date'].apply(lambda x: int(x[5:7]))
df_train['Month'] = df_train['Date'].apply(lambda x: int(x[5:7]))
| No | 5 | 16 | Data_Transform | data_type_conversions | 241,252 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Valida... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Column Selection Checker"] | 3 | B |
6,285 | df_store['CompetitionDistance'] == df_store['CompetitionDistance'].apply(lambda x: np.log(x))
| No | 5 | 8 | Data_Transform | feature_engineering | 241,252 | 1 | A | 0 | 0 | 0 | 1 | 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"] | 3 | A |
6,286 | df_test = df_test.fillna(df_test.mean())
| No | 5 | 17 | Data_Transform | correct_missing_values | 241,252 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
6,287 | closed_store_ids = df_test["Id"][df_test["Open"] == 0].values
df_test = df_test[df_test["Open"] != 0]
| No | 5 | 14 | Data_Transform | filter | 241,252 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}] | A | no applicable ML-specific findings | [] | ["Column Selection Checker"] | 3 | A |
6,288 | df_test = df_test.drop(['Date', 'StateHoliday'], axis=1)
| No | 5 | 10 | Data_Transform | drop_column | 241,252 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
6,289 | from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import log_loss
| No | 5 | 22 | Environment | import_modules | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 0 | A |
6,290 | df = pd.read_json(open("../input/train.json", "r"))
print(df.shape)
| Yes | 4 | 44 | Data_Extraction | load_from_disk | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,291 | df.head()
| No | 5 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,292 | print(df.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 |
6,293 | df["num_photos"] = df["photos"].apply(len)
df["num_features"] = df["features"].apply(len)
df["num_description_words"] = df["description"].apply(lambda x: len(x.split(" ")))
df["created"] = pd.to_datetime(df["created"])
df["created_year"] = df["created"].dt.year
df["created_month"] = df["created"].dt.month
df["created_d... | No | 5 | 8 | Data_Transform | feature_engineering | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 7 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,294 | num_feats = ["bathrooms", "bedrooms", "price"]
X = df[num_feats]
y = df["interest_level"]
X.head()
| Yes | 4 | 21 | Data_Transform | prepare_x_and_y | 241,414 | 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"] | 5 | A |
6,295 | X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.33)
| No | 5 | 13 | Data_Transform | split | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,296 | clf = RandomForestClassifier(n_estimators=1000)
clf.fit(X_train, y_train)
y_val_pred = clf.predict_proba(X_val)
log_loss(y_val, y_val_pred)
| Yes | 3 | 4 | Model_Train | choose_model_class | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,297 | # Save the test IDs for Kaggle submission
test_ids = act_test['activity_id']
def preprocess_acts(data,min_date, train_set=True):
# Getting rid of data feature for now
dates=data['date']
dates=process_dates(dates,min_date)
data = data.drop(['date', 'activity_id'], axis=1)
if(train_set):
... | Yes | 2 | 8 | Data_Transform | feature_engineering | 91,963 | 1 | A | 1 | 6 | 4 | 0 | 0 | 33 | 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": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Th... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Dependent Threshold Checker", "Missing function docstring"] | 5 | A |
6,298 | #find minimum date
min_date=pd.concat([people['date'],act_train['date'],act_test['date']]).min()
min_date | No | 3 | 11 | Data_Transform | concatenate | 91,963 | 1 | A | 0 | 0 | 0 | 1 | 0 | 2 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Valida... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Column Selection Checker", "Dependent Threshold Checker"] | 5 | B |
6,299 | # Preprocess each df
min_date=pd.concat([people['date'],act_train['date'],act_test['date']]).min()
peeps = preprocess_people(people,min_date)
actions_train = preprocess_acts(act_train,min_date,train_set=True)
actions_test = preprocess_acts(act_test,min_date,train_set=False)
print (peeps.columns)
print (actions_train.co... | Yes | 4 | 71 | Debug | show_columns | 91,963 | 1 | A | 0 | 0 | 0 | 0 | 0 | 7 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Valida... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Column Selection Checker", "Dependent Threshold Checker"] | 5 | B |
6,300 | actions_train.sample(10) | No | 5 | 41 | Debug | show_table | 91,963 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Dependent Threshold Checker"] | 5 | B |
6,301 | # Merege into a unified table
# Training
features = actions_train.merge(peeps, how='left', on='people_id')
features=features.drop(['people_id'],axis=1)
labels = act_train['outcome']
# Testing
test = actions_test.merge(peeps, how='left', on='people_id')
test=test.drop(['people_id'],axis=1)
# Check it out...
features.... | No | 4 | 32 | Data_Transform | merge | 91,963 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Valida... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Column Selection Checker", "Dependent Threshold Checker"] | 5 | B |
6,302 | columnss=list(features.columns)
columnss
#features['group_1'].nunique() | No | 5 | 71 | Debug | show_columns | 91,963 | 1 | A | 0 | 0 | 0 | 1 | 0 | 2 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Threshold Checker", "fix": "Use threshold-independent metrics alongside threshold-dependent ones.", "benefits": "Provides a comprehensive evaluation of model performance.", "location": ""}] | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker"] | 5 | A |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.