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,001 | from pandas import Series,DataFrame<br>import pandas as pd<br><br># numpy, matplotlib, seaborn<br>import numpy as np<br><br>names=[<br>\'Field6\',<br>\'Field7\',<br>\'Field8\',<br>\'Field10\',<br>\'CoverageField2A\',<br>\'CoverageField2B\',<br>\'CoverageField3A\',<br>\'CoverageField4B\',<br>\'CoverageField5A\',<br>\'Co... | No | 2 | 23 | Environment | set_options | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
6,002 | import pandas as pd
import numpy as np | 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,003 | df_train_users = pd.read_csv('../input/train_users_2.csv')
df_test_users = pd.read_csv('../input/test_users.csv') | No | 5 | 45 | Data_Extraction | load_from_csv | 31,880 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 2 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path detected: ../input/train_users_2.csv. Consider using configuration files or environment variables.", "fix": "Not specified", "benefits": "Not specified", "location": "Line 3"}, {"detector": "general_ml", "framework": "General ML", "name... | A | no applicable ML-specific findings | [] | ["Hardcoded file path"] | 2 | A |
6,004 | # let\'s look at the destinations accounted for each occurence in the train set<br>df_train_users.groupby("country_destination").count()["id"] | No | 5 | 60 | Data_Transform | groupby | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,005 | # the 5 most frequent "destinations" are ["NDF","US","other","FR","IT"]<br># baseline: predict ["NDF","US","other","FR","IT"] for each user in the test set<br><br>res = [[x, destination] for x in df_test_users["id"] for destination in ["NDF","US","other","FR","IT"]]<br>sub_baseline = pd.DataFrame(np.array(res), columns... | 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,006 | import numpy as np<br>import pandas as pd<br>import math<br>from sklearn.metrics import log_loss<br>from sklearn.preprocessing import StandardScaler<br><br><br># https://github.com/sublee/elo/blob/master/elo.py<br>"""<br> elo<br> ~~~<br> The Elo rating system.<br> :copyright: (c) 2012 by Heungsub Lee<br> ... | 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,007 | # 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,008 | train = pd.read_csv("../input/train.csv")
test = pd.read_csv("../input/test.csv") | No | 5 | 45 | Data_Extraction | load_from_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,009 | def loadData(df, test = None):
dt = pd.to_datetime(df.datetime).dt
df["Year"] = dt.year
df["Month"] = dt.month
df["Day"] = dt.day
df["Hour"] = dt.hour
df.drop("datetime", axis = 1, inplace = True)
if not test:
df.drop("casual", axis = 1, inplace = True)
df.drop("reg... | No | 4 | 21 | Data_Transform | prepare_x_and_y | 67,301 | 1 | A | 1 | 3 | 3 | 0 | 10 | 17 | ok | 6 | 3 | [{"detector": "framework_specific", "framework": "Pandas", "name": "InPlace Checker", "fix": "Assign operations to a new DataFrame variable.", "benefits": "Prevents data loss and improves code clarity.", "location": "Line 14"}, {"detector": "framework_specific", "framework": "Pandas", "name": "InPlace Checker", "fix": ... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "InPlace Checker", "Missing function docstring"] | 5 | A |
6,010 | X, y = loadData(train) | No | 5 | 21 | Data_Transform | prepare_x_and_y | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,011 | new_y = np.log(y + 1) | No | 4 | 21 | Data_Transform | prepare_x_and_y | 67,301 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 5 | A |
6,012 | # use a full grid over all parameters<br>\'\'\'<br>from sklearn.grid_search import GridSearchCV, RandomizedSearchCV<br>from time import time<br>param_grid = {"max_depth": [3, None],<br> "max_features": [1, 3, 10],<br> "min_samples_split": [1, 3, 10],<br> "min_samples_leaf": [1, 3,... | No | 5 | 6 | Hyperparam_Tuning | train_on_grid | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,015 | # RF
X_test, _ = loadData(test, test = True)
rf = RandomForestRegressor().fit(X, new_y)
prediction = rf.predict(X_test)
| No | 4 | 48 | Model_Evaluation | predict_on_test | 67,301 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 11 | 8 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low, Randomness Control Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}, {"type": "Randomness Control Checker", "severity": "low"}] | ["Exception Handling Checker", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker", "Verbose Mode Checker"] | 5 | B |
6,016 | ### xgb
#import xgboost as xgb
#gbm = xgb.XGBClassifier(max_depth=3, n_estimators=300, learning_rate=0.05).fit(train_X, train_y)
#predictions = gbm.predict(test_X) | No | 4 | 48 | Model_Evaluation | predict_on_test | 67,301 | 1 | A | 1 | 0 | 0 | 0 | 5 | 0 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 5 | A |
6,017 | ### Get submission
sample = pd.read_csv("../input/sampleSubmission.csv")
submission = pd.DataFrame()
submission["datetime"] = sample["datetime"]
submission["count"] = pd.Series(prediction)
submission.to_csv("sub.csv", index = False) | No | 3 | 55 | Data_Export | prepare_output | 67,301 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path d... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Hardcoded file path"] | 5 | A |
6,018 | print(check_output(["head", "../input/sampleSubmission.csv"]).decode("utf8")) | No | 5 | 25 | Data_Export | save_to_csv | 67,301 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 1 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path detected: ../input/sampleSubmission.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 |
6,019 | # 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,020 | import random
def random_sampler(filename, k):
sample = []
with open(filename, 'rb') as f:
f.seek(0, 2)
filesize = f.tell()
random_set = sorted(random.sample(range(filesize), k))
for i in range(k):
f.seek(random_set[i])
# Skip current lin... | No | 5 | 15 | Data_Transform | randomize_order | 71,314 | 1 | A | 0 | 2 | 1 | 0 | 0 | 12 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "general_ml", "framework": "General ML", "name": "Missing docstring for... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Missing function docstring"] | 3 | A |
6,021 | TRAIN_SAMPLES = 5*10**6
train_sample = random_sampler('../input/train.csv', TRAIN_SAMPLES) | No | 5 | 15 | Data_Transform | randomize_order | 71,314 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 1 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path detected: ../input/train.csv. Consider using configuration files or environment variables.", "fix": "Not specified", "benefits": "Not specified", "location": "Line 5"}] | A | no applicable ML-specific findings | [] | ["Hardcoded file path"] | 3 | A |
6,022 | train_sample[0].decode().split(',') | No | 4 | 78 | Data_Transform | string_transform | 71,314 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 4 | 4 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Valida... | B | Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}] | ["Column Selection Checker"] | 3 | B |
6,023 | train_sample_ = [row.decode().split(",") for row in train_sample] | No | 5 | 78 | Data_Transform | string_transform | 71,314 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
6,024 | train = pd.DataFrame(train_sample_) | No | 5 | 12 | Data_Transform | create_dataframe | 71,314 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
6,025 | train_df = pd.read_csv('../input/train.csv', nrows=1)
train.columns = train_df.columns | No | 3 | 45 | Data_Extraction | load_from_csv | 71,314 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 1 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path detected: ../input/train.csv. Consider using configuration files or environment variables.", "fix": "Not specified", "benefits": "Not specified", "location": "Line 4"}] | A | no applicable ML-specific findings | [] | ["Hardcoded file path"] | 3 | A |
6,026 | train = train.apply(pd.to_numeric) | No | 5 | 16 | Data_Transform | data_type_conversions | 71,314 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}] | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | [] | 3 | B |
6,027 | train.info() | No | 5 | 40 | Debug | show_table_attributes | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,028 | train['Demanda_uni_equil'] = np.log1p(train['Demanda_uni_equil']) | No | 4 | 21 | Data_Transform | prepare_x_and_y | 71,314 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}] | A | no applicable ML-specific findings | [] | ["Column Selection Checker"] | 3 | A |
6,029 | x_cols = train.columns
x_cols = x_cols.drop(['Venta_uni_hoy', 'Venta_hoy', 'Dev_uni_proxima', 'Dev_proxima', 'Demanda_uni_equil'])
print(x_cols) | No | 5 | 10 | Data_Transform | drop_column | 71,314 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
6,030 | from sklearn.ensemble import RandomForestRegressor
model = RandomForestRegressor() | No | 5 | 4 | Model_Train | choose_model_class | 71,314 | 3 | C | 2 | 0 | 0 | 0 | 10 | 2 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Randomness Control Checker", "fix": "Set random_state in estimators for reproducibility.", "benefits": "Ensures reproducible results and consistent model behaviour.", "location": "Line 5"}, {"detector": "framework_specific", "framework": "ScikitLe... | B | Randomness Control Checker=low | [{"type": "Randomness Control Checker", "severity": "low"}] | ["Verbose Mode Checker"] | 3 | C |
6,031 | model.fit(train[x_cols], train['Demanda_uni_equil']) | No | 5 | 7 | Model_Train | train_model | 71,314 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 5 | 5 | [{"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", "Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 3 | B |
6,032 | test = pd.read_csv('../input/test.csv')
test.info() | No | 4 | 45 | Data_Extraction | load_from_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,033 | test['Demanda_uni_equil'] = np.expm1(model.predict(test[x_cols])) | No | 5 | 48 | Model_Evaluation | predict_on_test | 71,314 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Unit Testing... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Exception Handling Checker", "Unit Testing Checker"] | 3 | A |
6,034 | test[['id', 'Demanda_uni_equil']].to_csv('predictions_rf_random_sampling.csv', index=False) | No | 5 | 25 | Data_Export | save_to_csv | 71,314 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
6,035 | import pandas as pd<br>import numpy as np<br>from scipy import sparse as ssp<br>import pylab as plt<br>from sklearn.preprocessing import LabelEncoder,LabelBinarizer,MinMaxScaler,OneHotEncoder<br>from sklearn.feature_extraction.text import TfidfVectorizer,CountVectorizer<br>from sklearn.decomposition import TruncatedSVD... | No | 3 | 45 | Data_Extraction | load_from_csv | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
6,036 | %matplotlib inline
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import os
from sklearn.preprocessing import LabelEncoder
from sklearn.cross_validation import KFold
from sklearn.metrics import log_loss | No | 5 | 23 | Environment | set_options | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
6,037 | gatrain = pd.read_csv('../input/gender_age_train.csv')
gatest = pd.read_csv('../input/gender_age_test.csv')
gatrain.head(3) | No | 4 | 45 | Data_Extraction | load_from_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,038 | letarget = LabelEncoder().fit(gatrain.group.values)
y = letarget.transform(gatrain.group.values)
n_classes = len(letarget.classes_) | No | 4 | 20 | Data_Transform | categorify | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,039 | phone = pd.read_csv('../input/phone_brand_device_model.csv',encoding='utf-8')
phone.head(3) | No | 4 | 45 | Data_Extraction | load_from_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,040 | phone = phone.drop_duplicates('device_id', keep='first') | No | 5 | 19 | Data_Transform | remove_duplicates | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,041 | lebrand = LabelEncoder().fit(phone.phone_brand)
phone['brand'] = lebrand.transform(phone.phone_brand)
m = phone.phone_brand.str.cat(phone.device_model)
lemodel = LabelEncoder().fit(m)
phone['model'] = lemodel.transform(m) | No | 5 | 20 | Data_Transform | categorify | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,042 | train = gatrain.merge(phone[['device_id','brand','model']], how='left',on='device_id') | No | 5 | 32 | Data_Transform | merge | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,043 | class GenderAgeGroupProb(object):
def __init__(self):
pass
def fit(self, df, by, n_smoothing, weights):
self.by = by
self.n_smoothing = n_smoothing
self.weights = np.divide(weights,sum(weights))
self.classes_ = sorted(df['group'].unique())
self.n_classes_ = l... | No | 4 | 7 | Model_Train | train_model | 87,185 | 1 | A | 3 | 7 | 3 | 0 | 15 | 36 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,044 | n_smoothing = [1,5,10,15,20,50,100]
res = [score(train,['brand','model'],[s,s],[.5,.5]) for s in n_smoothing]
plt.plot(n_smoothing, res)
plt.title('Best score {:.5f} at n_smoothing = {}'.format(np.min(res),n_smoothing[np.argmin(res)]))
plt.xlabel('n_smoothing') | No | 4 | 81 | Visualization | relationship | 87,185 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,045 | brand_weight = [0,0.2,0.4,0.6,0.8,1.0]
res = [score(train,['brand','model'],[15,15],[b,1-b]) for b in brand_weight]
plt.plot(brand_weight, res)
plt.title('Best score {:.5f} at brand_weight = {}'.format(np.min(res),brand_weight[np.argmin(res)]))
plt.xlabel('brand_weight') | No | 5 | 81 | Visualization | relationship | 87,185 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,046 | test = gatest.merge(phone[['device_id','brand','model']], how='left',on='device_id')
test.head(3) | No | 5 | 32 | Data_Transform | merge | 87,185 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,047 | clf = GenderAgeGroupProb().fit(train,['brand','model'],[15,15],[0.4,0.6])
pred = clf.predict_proba(test) | No | 4 | 7 | Model_Train | train_model | 87,185 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,048 | pd.DataFrame(pred,
index = test.device_id,
columns=clf.classes_).to_csv('pbm_subm.csv', index=True) | No | 5 | 25 | Data_Export | save_to_csv | 87,185 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,049 | # This Python 3 environment comes with many helpful analytics libraries installed<br># It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python<br># For example, here\'s several helpful packages to load in <br><br>import numpy as np # linear algebra<br>import pandas as pd # data processi... | Yes | 3 | 10 | Data_Transform | drop_column | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,050 | def getVariables(value=1000):
for var, obj in globals().items():
try:
if(sys.getsizeof(obj) > value and not var.startswith("_")):
print ("{0:30} {1:5}".format(var, sys.getsizeof(obj)))
except:
continue | No | 3 | 23 | Environment | set_options | 89,434 | 2 | B | 2 | 4 | 6 | 0 | 15 | 7 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,051 | def evalerror(preds, dtrain):
labels = dtrain.get_label()
assert len(preds) == len(labels)
labels = labels.tolist()
preds = preds.tolist()
terms_to_sum = [(math.log(labels[i] + 1) - math.log(max(0,preds[i]) + 1)) ** 2.0 for i,pred in enumerate(labels)]
return 'error', (sum(terms_to_sum) * (1.0/... | No | 5 | 84 | Other | not_enough_vertices | 89,434 | 1 | A | 0 | 1 | 0 | 0 | 0 | 7 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,052 | print ('Loading Test...')
dtype_test = {'id':np.uint32,
'Semana': np.uint8,
'Agencia_ID': np.uint16,
'Canal_ID': np.uint8,
'Ruta_SAK': np.uint16,
'Cliente_ID': np.uint32,
'Producto_ID': np.uint16}
%time test = pd.read_csv('../input... | No | 5 | 45 | Data_Extraction | load_from_csv | 89,434 | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,053 | test.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,054 | dtype = {'Semana': np.uint8,
'Agencia_ID': np.uint16,
'Canal_ID': np.uint8,
'Ruta_SAK': np.uint16,
'Cliente_ID': np.uint32,
'Producto_ID': np.uint16,
'Demanda_uni_equil': np.uint16}
filename='../input/train.csv'
%time train = pd.read_csv(filename, usecols=dty... | No | 4 | 45 | Data_Extraction | load_from_csv | 89,434 | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,055 | train = train[train["Semana"]>8]<br>print (\'Training_Shape:\', train.shape) | No | 4 | 14 | Data_Transform | filter | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,056 | ids = test['id']
test = test.drop(['id'],axis = 1)
y = train['Demanda_uni_equil']
X = train[test.columns.values]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=1729)
del(train)
print ('Division_Set_Shapes:', X.shape, y.shape)
print ('Validation_Set_Shapes:', X_train.shape, X_tes... | No | 3 | 21 | Data_Transform | prepare_x_and_y | 89,434 | 1 | A | 0 | 0 | 0 | 0 | 0 | 10 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,057 | params = {}<br>params[\'objective\'] = "reg:linear"<br>params[\'eta\'] = 0.1<br>params[\'max_depth\'] = 5<br>params[\'subsample\'] = 0.8<br>params[\'colsample_bytree\'] = 0.6<br>params[\'silent\'] = True<br>#params[\'nthread\']= 4<br>params[\'booster\'] = "gbtree"<br><br><br>test_preds = np.zeros(test.shape[0])<br>xg_t... | No | 4 | 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,058 | num_rounds = 20
%time xgclassifier = xgb.train(params, xg_train, num_rounds, watchlist, feval = evalerror, early_stopping_rounds= 20, verbose_eval = 10)
del(xg_train) | No | 5 | 7 | Model_Train | train_model | 89,434 | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,059 | preds = xgclassifier.predict(xg_test, ntree_limit=xgclassifier.best_iteration)
print ('RMSLE Score:', rmsle(y_test, preds)) | No | 3 | 49 | Model_Evaluation | compute_test_metric | 89,434 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,060 | print ('RMSLE Score:', rmsle(y_test, preds))
del(preds)
del(y_test) | No | 5 | 49 | Model_Evaluation | compute_test_metric | 89,434 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,061 | import numpy as np
import pandas as pd
import datetime
act_train = pd.read_csv('../input/act_train.csv')
act_test = pd.read_csv('../input/act_test.csv')
people = pd.read_csv('../input/people.csv')
people.sample(10) | Yes | 4 | 8 | Data_Transform | feature_engineering | 91,963 | 1 | A | 0 | 0 | 0 | 0 | 0 | 7 | ok | 5 | 3 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Threshold Checker", "fix": "Use threshold-independent metrics alongside threshold-dependent ones.", "benefits": "Provides a comprehensive evaluation of model performance.", "location": ""}, {"detector": "general_ml", "framework": "Genera... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Hardcoded file path", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness."] | 5 | A |
6,062 | def process_dates(data,min_date):
#min_date=data.min()
min_date
data=data.apply(lambda x: (datetime.datetime.strptime(x,"%Y-%m-%d")
-datetime.datetime.strptime(min_date,"%Y-%m-%d")).days)
data
return data | No | 4 | 8 | Data_Transform | feature_engineering | 91,963 | 1 | A | 1 | 1 | 0 | 2 | 5 | 6 | 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"] | 5 | A |
6,063 | import pandas as pd<br>import numpy as np<br>import datetime<br>import pandas as pd<br>import numpy as np<br>from sklearn.cross_validation import KFold<br>from sklearn.cross_validation import train_test_split<br>from sklearn.metrics import roc_auc_score<br>import xgboost as xgb<br>import random<br>from operator import ... | 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,064 | sub_df = pd.read_csv('../input/sample_submission.csv') | No | 5 | 45 | Data_Extraction | load_from_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,065 | # Size of the dataframe
print(dataset.shape)
# We can see that there are 15120 instances having 55 attributes
#Learning : Data is loaded successfully as dimensions match the data description | 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,066 | # Datatypes of the attributes
print(dataset.dtypes)
# Learning : Data types of all attributes has been inferred as int64 | 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,067 | sub_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,068 | # Statistical description
pandas.set_option('display.max_columns', None)
print(dataset.describe())
# Learning :
# No attribute is missing as count is 15120 for all attributes. Hence, all rows can be used
# Negative value(s) present in Vertical_Distance_To_Hydrology. Hence, some tests such as chi-sq cant be used.
# Wi... | No | 3 | 23 | Environment | set_options | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,069 | train_df = pd.read_csv('../input/act_train.csv') | No | 5 | 45 | Data_Extraction | load_from_csv | 95,831 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 1 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path detected: ../input/act_train.csv. Consider using configuration files or environment variables.", "fix": "Not specified", "benefits": "Not specified", "location": "Line 3"}] | A | no applicable ML-specific findings | [] | ["Hardcoded file path"] | 2 | A |
6,070 | train_df['activity_category'] = train_df['activity_category'].astype('category').cat.codes
columns = ['char_'+str(i) for i in range(1,11)]
train_df[columns] = train_df[columns].apply(lambda x: x.astype('category').cat.codes)
train_df['date'] = pd.to_datetime(train_df['date'])
train_df['day'] = train_df['date'].apply(la... | No | 3 | 8 | Data_Transform | feature_engineering | 95,831 | 1 | A | 0 | 0 | 0 | 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"] | 2 | A |
6,071 | # Skewness of the distribution
print(dataset.skew())
# Values close to 0 show less skew
# Several attributes in Soil_Type show a large skew. Hence, some algos may benefit if skew is corrected | No | 4 | 40 | Debug | show_table_attributes | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,072 | # Number of instances belonging to each class
dataset.groupby('Cover_Type').size()
# We see that all classes have an equal presence. No class re-balancing is necessary | No | 5 | 60 | Data_Transform | groupby | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,073 | import numpy<br><br># Correlation tells relation between two attributes.<br># Correlation requires continous data. Hence, ignore Wilderness_Area and Soil_Type as they are binary<br><br>#sets the number of features considered<br>size = 10 <br><br>#create a dataframe with only \'size\' features<br>data=dataset.iloc[:,:si... | 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,074 | #import plotting libraries
import seaborn as sns
import matplotlib.pyplot as plt
# Scatter plot of only the highly correlated pairs
for v,i,j in s_corr_list:
sns.pairplot(dataset, hue="Cover_Type", size=6, x_vars=cols[i],y_vars=cols[j] )
plt.show()
#The plots show to which class does a point belong to. The cl... | No | 5 | 33 | Visualization | distribution | null | 1 | A | 0 | 1 | 1 | 0 | 0 | 5 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,075 | # We will visualize all the attributes using Violin Plot - a combination of box and density plots
#names of all the attributes
cols = dataset.columns
#number of attributes (exclude target)
size = len(cols)-1
#x-axis has target attribute to distinguish between classes
x = cols[size]
#y-axis shows values of an attri... | No | 5 | 33 | Visualization | distribution | null | 1 | A | 0 | 1 | 1 | 0 | 0 | 7 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,076 | # Group one-hot encoded variables of a category into one single variable<br><br>#names of all the columns<br>cols = dataset.columns<br><br>#number of rows=r , number of columns=c<br>r,c = dataset.shape<br><br>#Create a new dataframe with r rows, one column for each encoded category, and target in the end<br>data = pand... | No | 3 | 20 | Data_Transform | categorify | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,077 | #Removal list initialize
rem = []
#Add constant columns as they don't help in prediction process
for c in dataset.columns:
if dataset[c].std() == 0: #standard deviation is zero
rem.append(c)
#drop the columns
dataset.drop(rem,axis=1,inplace=True)
print(rem)
#Following columns are dropped | No | 5 | 10 | Data_Transform | drop_column | null | 1 | A | 0 | 2 | 3 | 0 | 0 | 6 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,078 | train_df.corr().outcome | No | 5 | 40 | Debug | show_table_attributes | 95,831 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 2 | A |
6,079 | rank_df = pandas.DataFrame(data=[x[7] for x in X_all_add],columns=cols[:c-1])
_ = rank_df.boxplot(rot=90)
#Below plot summarizes the rankings according to the standard feature selection techniques
#Top ranked attributes are ... first 10 attributes, Wilderness_Area1,4 ...Soil_Type 3,4,10,38-40 | No | 3 | 12 | Data_Transform | create_dataframe | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,080 | rank_df = pandas.DataFrame(data=[x[7] for x in X_all_add],columns=cols[:c-1])<br>med = rank_df.median()<br>print(med)<br>#Write medians to output file for exploratory study on ML algorithms<br>with open("median.csv", "w") as subfile:<br> subfile.write("Column,Median\<br>")<br> subfile.write(med.to_string()) | No | 4 | 40 | Debug | show_table_attributes | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
6,081 | # 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 | 53 | Other | something_strange | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,082 | import pandas as pd
import numpy as np
%matplotlib inline
import seaborn as sns
import matplotlib.pyplot as plt
import os
from sklearn.preprocessing import LabelEncoder
from scipy.sparse import csr_matrix, hstack
from sklearn.linear_model import LogisticRegression
from sklearn.cross_validation import StratifiedKFold
fr... | No | 5 | 23 | Environment | set_options | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
6,083 | datadir = '../input'
gatrain = pd.read_csv(os.path.join(datadir,'gender_age_train.csv'),
index_col='device_id')
gatest = pd.read_csv(os.path.join(datadir,'gender_age_test.csv'),
index_col = 'device_id')
phone = pd.read_csv(os.path.join(datadir,'phone_brand_device_model.csv'))
... | No | 4 | 45 | Data_Extraction | load_from_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 13 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,084 | brandencoder = LabelEncoder().fit(phone.phone_brand)
phone['brand'] = brandencoder.transform(phone['phone_brand'])
gatrain['brand'] = phone['brand']
gatest['brand'] = phone['brand']
Xtr_brand = csr_matrix((np.ones(gatrain.shape[0]),
(gatrain.trainrow, gatrain.brand)))
Xte_brand = csr_matrix((np.... | No | 4 | 20 | Data_Transform | categorify | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 9 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,085 | people_df = pd.read_csv('../input/people.csv')
people_df.group_1.unique().shape | No | 3 | 45 | Data_Extraction | load_from_csv | 95,831 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 1 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path detected: ../input/people.csv. Consider using configuration files or environment variables.", "fix": "Not specified", "benefits": "Not specified", "location": "Line 3"}] | A | no applicable ML-specific findings | [] | ["Hardcoded file path"] | 2 | A |
6,086 | people_df = pd.read_csv('../input/people.csv')
columns = ['char_'+str(i) for i in range(1,10)]
people_df[columns] = people_df[columns].apply(lambda x: x.astype('category').cat.codes)
people_df['group_1'] = people_df['group_1'].astype('category').cat.codes
people_df['date'] = pd.to_datetime(people_df['date'])
people_df[... | No | 4 | 8 | Data_Transform | feature_engineering | 95,831 | 1 | A | 0 | 0 | 0 | 0 | 0 | 11 | 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 |
6,087 | train_X = train_df.join(people_df,on = 'people_id', rsuffix='_people') | No | 5 | 32 | Data_Transform | merge | 95,831 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 2 | A |
6,088 | Y = train_X['outcome']
X = train_X.drop(['outcome','people_id','people_id_people','activity_id'],axis = 1) | No | 5 | 21 | Data_Transform | prepare_x_and_y | 95,831 | 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"] | 2 | A |
6,089 | #from sklearn.ensemble import RandomForestClassifier
#clf = RandomForestClassifier(n_estimators = 10)
#clf = clf.fit(X, Y)
import xgboost as xgb
gbm = xgb.XGBClassifier(max_depth=3, n_estimators=300, learning_rate=0.05).fit(X, Y) | No | 5 | 7 | Model_Train | train_model | 95,831 | 2 | B | 1 | 0 | 0 | 0 | 5 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 2 | B |
6,090 | test_df = pd.read_csv('../input/act_test.csv')
test_df['activity_category'] = test_df['activity_category'].astype('category').cat.codes
columns = ['char_'+str(i) for i in range(1,11)]
test_df[columns] = test_df[columns].apply(lambda x: x.astype('category').cat.codes)
test_df['date'] = pd.to_datetime(test_df['date'])
te... | No | 3 | 8 | Data_Transform | feature_engineering | 95,831 | 1 | A | 0 | 0 | 0 | 0 | 0 | 9 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path d... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Hardcoded file path"] | 2 | A |
6,091 | test_X = test_df.join(people_df,on = 'people_id', rsuffix='_people')
X = test_X.drop(['people_id','people_id_people','activity_id'],axis = 1)
#output = clf.predict(X)
output = gbm.predict(X) | No | 4 | 48 | Model_Evaluation | predict_on_test | 95,831 | 2 | B | 1 | 0 | 0 | 0 | 5 | 3 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 2 | B |
6,092 | test_df['outcome'] = output
test_df.to_csv('submission.csv',columns = ['activity_id','outcome'],index = False) | No | 5 | 25 | Data_Export | save_to_csv | 95,831 | 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"] | 2 | A |
6,093 | import pandas as pd | 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,094 | train = pd.read_csv("../input/train.csv")
test = pd.read_csv("../input/test.csv")
submission = pd.read_csv("../input/sampleSubmission.csv") | No | 5 | 45 | Data_Extraction | load_from_csv | 156,200 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 3 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path detected: ../input/train.csv. Consider using configuration files or environment variables.", "fix": "Not specified", "benefits": "Not specified", "location": "Line 2"}, {"detector": "general_ml", "framework": "General ML", "name": "Hard... | A | no applicable ML-specific findings | [] | ["Hardcoded file path"] | 1 | A |
6,095 | print("Train dataset:")
print(train.head())
print("Test dataset:")
print(test.head())
print("Sample submission:")
print(submission.head()) | No | 5 | 41 | Debug | show_table | 156,200 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 1 | A |
6,096 | print(train.describe()) | No | 5 | 40 | Debug | show_table_attributes | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,097 | mean = train.describe()["count"]["mean"] | No | 5 | 40 | Debug | show_table_attributes | 156,200 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Chain Indexing", "fix": "Use single indexing or .loc[], .iloc[] methods.", "benefits": "Enhances code readability and prevents performance issues.", "location": "Line 2"}] | A | no applicable ML-specific findings | [] | ["Chain Indexing"] | 1 | A |
6,098 | m = phone.phone_brand.str.cat(phone.device_model)
modelencoder = LabelEncoder().fit(m)
phone['model'] = modelencoder.transform(m)
gatrain['model'] = phone['model']
gatest['model'] = phone['model']
Xtr_model = csr_matrix((np.ones(gatrain.shape[0]),
(gatrain.trainrow, gatrain.model)))
Xte_model = ... | No | 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 |
6,099 | appencoder = LabelEncoder().fit(appevents.app_id)
appevents['app'] = appencoder.transform(appevents.app_id)
napps = len(appencoder.classes_)
deviceapps = (appevents.merge(events[['device_id']], how='left',left_on='event_id',right_index=True)
.groupby(['device_id','app'])['app'].agg(['size'])
... | Yes | 3 | 20 | Data_Transform | categorify | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 9 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,100 | d = deviceapps.dropna(subset=['trainrow'])
Xtr_app = csr_matrix((np.ones(d.shape[0]), (d.trainrow, d.app)),
shape=(gatrain.shape[0],napps))
d = deviceapps.dropna(subset=['testrow'])
Xte_app = csr_matrix((np.ones(d.shape[0]), (d.testrow, d.app)),
shape=(gatest.shape[0],napps... | Yes | 4 | 17 | Data_Transform | correct_missing_values | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 7 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,101 | applabels = applabels.loc[applabels.app_id.isin(appevents.app_id.unique())]
applabels['app'] = appencoder.transform(applabels.app_id)
labelencoder = LabelEncoder().fit(applabels.label_id)
applabels['label'] = labelencoder.transform(applabels.label_id)
nlabels = len(labelencoder.classes_) | No | 4 | 20 | Data_Transform | categorify | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
6,102 | devicelabels = (deviceapps[['device_id','app']]
.merge(applabels[['app','label']])
.groupby(['device_id','label'])['app'].agg(['size'])
.merge(gatrain[['trainrow']], how='left', left_index=True, right_index=True)
.merge(gatest[['testrow']], how='left', lef... | Yes | 4 | 32 | Data_Transform | merge | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 7 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.