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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
715 | train = train.drop('Open_Month',axis=1)
test= test.drop('Open_Month',axis=1)
nominal_list.remove('Open_Month') | No | 5 | 10 | Data_Transform | drop_column | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
716 | b"columns = len(num_list)/4+1\n\nfig = plt.figure(figsize=(30, 35))\nplt.subplots_adjust(hspace=0.6, wspace=0.4)\n\nfor i in range(len(num_list)):\n ax = fig.add_subplot(columns, 4, i+1)\n\n # \n sns.regplot(x=num_list[i],y='revenue',data=train, ax=ax)\n plt.xticks(rotation=45)\n # \n# sns.barplo... | No | 5 | 33 | Visualization | distribution | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
717 | train[['City','revenue']].groupby('City').mean().plot(kind='bar')
plt.title('Mean Revenue Generated vs City')
plt.xlabel('City')
plt.ylabel('Mean Revenue Generated') | No | 5 | 33 | Visualization | distribution | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
718 | b"# Cityrevenue1000000\nmean_revenue_per_city = train[['City', 'revenue']].groupby('City', as_index=False).mean()\nmean_revenue_per_city.head()\nmean_revenue_per_city['revenue'] = mean_revenue_per_city['revenue'].apply(lambda x: int(x/1e6)) \n\nmean_revenue_per_city\n\nmean_dict = dict(zip(mean_revenue_per_city.City, m... | No | 3 | 60 | Data_Transform | groupby | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
721 |
print(train['City'].sort_values().unique()) | No | 5 | 57 | Debug | show_unique_values | 12,034,947 | 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"] | 18 | B |
722 | test['City'].sort_values().unique()
| No | 5 | 57 | Debug | show_unique_values | 12,034,947 | 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"] | 18 | A |
723 | b"# City\ncity_train_list = list(train['City'].unique())\ncity_test_list = list(test['City'].unique())" | No | 5 | 57 | Debug | show_unique_values | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
724 | # P1
# PP
distinct_cities = train.loc[:, "City"].unique()
# Pcity
means = []
for i in range(len(num_list)):
temp = []
for city in distinct_cities:
temp.append(train.loc[train.City == city, num_list[i]].mean())
means.append(temp)
city_pvars = pd.DataFrame(columns=["city_var", "means"])
for i ... | No | 5 | 53 | Other | something_strange | null | 1 | A | 0 | 4 | 6 | 0 | 0 | 14 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
725 | from sklearn import cluster
def adjust_cities(full_full_data, train, k):
# As found by box plot of each city's mean over each p-var
relevant_pvars = ["P1", "P2", "P11", "P19", "P20", "P23","P30"]
train = train.loc[:, relevant_pvars]
# Optimal k is 20 as found by DB-Index plot
kmeans ... | No | 5 | 84 | Other | not_enough_vertices | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
726 | num_train = train.shape[0]
num_test = test.shape[0]
print(num_train, num_test)
full_data = pd.concat([train, test], ignore_index=True) | No | 4 | 11 | Data_Transform | concatenate | 12,034,947 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 18 | A |
727 | b"# \nfull_data = adjust_cities(full_data, train, 20)\nfull_data\n\n# City\nfull_data = full_data.drop(['City'], axis=1)" | No | 3 | 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 |
728 | # Split into train and test datasets
train = full_data[:num_train]
test = full_data[num_train:]
# check the shapes
print("Train :",train.shape)
print("Test:",test.shape)
test | No | 4 | 13 | Data_Transform | split | null | 1 | A | 0 | 0 | 0 | 1 | 0 | 5 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
729 | train[['City_Cluster','revenue']].groupby('City_Cluster').mean().plot(kind='bar')
plt.title('Mean Revenue Generated vs City Cluster')
plt.xlabel('City Cluster')
plt.ylabel('Mean Revenue Generated') | No | 5 | 33 | Visualization | distribution | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
730 | mean_revenue_per_city = train[['City_Cluster', 'revenue']].groupby('City_Cluster', as_index=False).mean()
mean_revenue_per_city.head()
mean_revenue_per_city['revenue'] = mean_revenue_per_city['revenue'].apply(lambda x: int(x/1e6))
mean_revenue_per_city
mean_dict = dict(zip(mean_revenue_per_city.City_Cluster, mean_re... | No | 2 | 60 | Data_Transform | groupby | null | 1 | A | 0 | 0 | 0 | 2 | 0 | 6 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
731 | b"city_rev = []\n\nfor i in full_data['City_Cluster']:\n for key, value in mean_dict.items():\n if i == key:\n city_rev.append(value)\n \ndf_city_rev = pd.DataFrame({'city_rev':city_rev})\nfull_data = pd.concat([full_data,df_city_rev],axis=1)\nfull_data.head\n\n# \nnominal_list.extend(['... | 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 |
732 | from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
le_count = 0
# Iterate through the columns
# for col in application_full_data:
for i in range(len(nominal_list)):
# if application_full_data[col].dtype == 'object':
# If 2 or fewer unique categories
if len(list(full_data[no... | No | 5 | 20 | Data_Transform | categorify | null | 1 | A | 0 | 2 | 3 | 0 | 0 | 9 | ok | 8 | 7 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Pipeline Checker", "fix": "Use Pipelines for all scikit-learn estimators.", "benefits": "Prevents data leakage and ensures correct model evaluation.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross V... | D | Cross Validation Checker=low, Data Leakage Checker=high, No random seed setting detected=low, Pipeline Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}, {"type": "No random seed setting detected", "severity": "low"}, {"type": "Pipeline Checker", "severity": "low"}] | ["Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 0 | D |
733 | # one-hot encoding of categorical variables
full_data = pd.get_dummies(full_data)
print('full_dataing Features shape: ', full_data.shape) | No | 4 | 20 | Data_Transform | categorify | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
734 | #
# for col in num_list:
# outliers = tukey_outliers(train[col])
# if len(outliers):
# print(f"* {col} has these tukey outliers,\
{outliers}\
")
# else:
# print(f"* {col} doesn't have any tukey outliers.\
")' | No | 5 | 53 | Other | something_strange | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
736 | columns = len(num_list)/4+1
# boxplot
fig = plt.figure(figsize=(15,20))
plt.subplots_adjust(hspace=0.2, wspace=0.8)
for i in range(len(num_list)):
ax = fig.add_subplot(columns, 4, i+1)
sns.boxplot(y=full_data[num_list[i]], data=full_data, ax=ax)
plt.show() | 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 |
739 | skewed_data = train[num_list].apply(lambda x: skew(x)).sort_values(ascending=False)
skewed_data[:10] | No | 3 | 47 | Model_Evaluation | statistical_test | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
741 | # Split into train and test datasets
train = full_data[:num_train]
test = full_data[num_train:]
# check the shapes
print("Train :",train.shape)
print("Test:",test.shape) | No | 4 | 13 | Data_Transform | split | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
742 | sns.set(font_scale=1.1)
correlation_train = train.corr()
mask = np.triu(correlation_train.corr())
fig = plt.figure(figsize=(50,50))
sns.heatmap(correlation_train,
annot=True,
fmt='.1f',
cmap='coolwarm',
square=True,
# mask=mask,
linewidths=1)
plt.... | No | 5 | 80 | Visualization | heatmap | null | 1 | A | 1 | 0 | 0 | 0 | 5 | 11 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
743 | # 10
train = train[cols]
#
train_X = train.drop("revenue",axis=1)
train_y = train["revenue"]
#revenue
train_y = np.log1p(train_y)
#
tmp_cols = train_X.columns
test_X = test[tmp_cols]
#
print("train_X: "+str(train_X.shape))
print("train_y: "+str(train_y.shape))
print("test_X: "+str(test_X.shape))' | No | 3 | 13 | Data_Transform | split | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
744 | #
from sklearn.model_selection import train_test_split
#
(X_train, X_test, y_train, y_test) = train_test_split(train_X, train_y , test_size = 0.3 , random_state = 0)
print("X_train: "+str(X_train.shape))
print("X_test: "+str(X_test.shape))
print("y_train: "+str(y_train.shape))
print("y_test: "+str(y_test.shape))' | No | 4 | 13 | Data_Transform | split | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
745 | from sklearn.model_selection import GridSearchCV, cross_val_score, learning_curve
from sklearn.metrics import mean_absolute_error
from sklearn.linear_model import Lasso
from sklearn.linear_model import LinearRegression
from sklearn.linear_model import Ridge
from sklearn.linear_model import ElasticNet
from sklearn.neigh... | No | 5 | 22 | Environment | import_modules | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 13 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 0 | A |
746 | #
random_state = 2
classifiers = []
classifiers.append(Lasso(random_state=random_state))
classifiers.append(LinearRegression())
classifiers.append(Ridge(random_state=random_state))
classifiers.append(ElasticNet(random_state=random_state))
classifiers.append(KNeighborsRegressor())
classifiers.append(SVR())
classifiers.a... | No | 5 | 4 | Model_Train | choose_model_class | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
747 | #classifier
cv_results = []
for classifier in classifiers :
cv_results.append(cross_val_score(classifier, X_train, y_train, scoring='neg_mean_squared_error', cv =10, n_jobs=4))
#classifier
cv_means = []
cv_std = []
for cv_result in cv_results:
cv_means.append(cv_result.mean())
cv_std.append(cv_result.... | No | 3 | 28 | Model_Train | compute_train_metric | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
748 | g = sns.barplot("CrossValMeans","Algorithm",data = cv_res, palette="Set3",orient = "h",**{'xerr':cv_std})
g.set_xlabel("Mean Accuracy")
g = g.set_title("Cross validation scores")' | No | 5 | 84 | Other | not_enough_vertices | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
749 | cv_res.sort_values(ascending=False, by='CrossValMeans') | No | 5 | 9 | Data_Transform | sort_values | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
750 | from sklearn import datasets
from sklearn.linear_model import Ridge
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_absolute_error
import optuna
def objective(trial):
params = {
'alpha': trial.suggest_loguniform("alpha", 0.1, 5),
'fit_intercept': trial.sugges... | No | 3 | 7 | Model_Train | train_model | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
751 | b"# optuna \nstudy = optuna.create_study()\nstudy.optimize(objective, n_trials=100)\n\n# \nprint(f'best score: {study.best_value:.4f}, best params: {study.best_params}')" | No | 4 | 2 | Hyperparam_Tuning | find_best_params | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
752 | params = {'alpha': 1.9510706324753746, 'fit_intercept': True, 'normalize': True}
reg = Ridge(**params)
reg.fit(X_train, y_train)
prediction_log = reg.predict(test_X)
prediction =np.exp(prediction_log)
print(prediction) | No | 3 | 48 | Model_Evaluation | predict_on_test | 12,034,947 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | ok | 8 | 7 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}] | ["Exception Handling Checker", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker", "Verbose Mode Checker"] | 18 | B |
753 | # CSV(submission)
submission = pd.DataFrame({"Id":test_Id, "Prediction":prediction})
submission.to_csv("submission.csv", index=False)' | No | 3 | 25 | Data_Export | save_to_csv | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
761 | %matplotlib inline
import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib
from scipy import stats
from scipy.stats import norm, skew
from sklearn import preprocessing
from sklearn.metrics import r2_score
from sklearn.metrics import mean_squared_error
fro... | No | 3 | 22 | Environment | import_modules | 12,343,159 | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 15 | null |
762 | df = pd.read_csv('/kaggle/input/restaurant-revenue-prediction/train.csv.zip')
df.shape | 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 |
763 | test_df = pd.read_csv('/kaggle/input/restaurant-revenue-prediction/test.csv.zip')
test_df.shape | No | 5 | 45 | Data_Extraction | load_from_csv | 12,343,159 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 3 | 2 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 9"}, {"detector": "framework_specific", "framework": "General", "name": "Import Checker", ... | A | no applicable ML-specific findings | [] | ["Hardcoded file path", "Import Checker"] | 15 | A |
764 | 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 |
765 | def display_all(df):
with pd.option_context("display.max_rows", 1000, "display.max_columns", 1000):
display(df)
display_all(df.head().transpose()) | No | 5 | 41 | Debug | show_table | 12,343,159 | 1 | A | 0 | 1 | 0 | 0 | 0 | 4 | ok | 2 | 1 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 9"}, {"detector": "framework_specific", "framework": "General", "name": "Import Checker", ... | A | no applicable ML-specific findings | [] | ["Import Checker"] | 15 | A |
766 | df.isnull().sum().sort_index()/len(df) | No | 5 | 39 | EDA | count_missing_values | null | 1 | A | 0 | 0 | 0 | 1 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
767 | fig, ax = plt.subplots(1,2, figsize=(19, 5))
g1 = sns.countplot(df['Type'],palette="Set2", ax=ax[0]);
g2 = sns.countplot(test_df['Type'],palette="Set2", ax=ax[1]);
fig.show()' | No | 5 | 33 | Visualization | distribution | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
768 | fig, ax = plt.subplots(1,2, figsize=(19, 5))
g1 = sns.countplot(df['City Group'],palette="Set2", ax=ax[0]);
g2 = sns.countplot(test_df['City Group'],palette="Set2", ax=ax[1]);
fig.show()' | No | 5 | 33 | Visualization | distribution | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
769 | (df['City'].nunique(), test_df['City'].nunique()) | No | 5 | 54 | EDA | count_unique_values | 12,343,159 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 2 | 1 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 9"}, {"detector": "framework_specific", "framework": "General", "name": "Import Checker", ... | A | no applicable ML-specific findings | [] | ["Import Checker"] | 15 | A |
770 | test_df.loc[test_df['Type']=='MB', 'Type'] = 'DT' | No | 5 | 8 | Data_Transform | feature_engineering | 12,343,159 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 2 | 1 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 9"}, {"detector": "framework_specific", "framework": "General", "name": "Import Checker", ... | A | no applicable ML-specific findings | [] | ["Import Checker"] | 15 | A |
771 | df.drop('City', axis=1, inplace=True)
test_df.drop('City', axis=1, inplace=True) | No | 5 | 10 | Data_Transform | drop_column | 12,343,159 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 2 | 1 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 9"}, {"detector": "framework_specific", "framework": "General", "name": "Import Checker", ... | A | no applicable ML-specific findings | [] | ["Import Checker"] | 15 | A |
772 | import datetime
df.drop('Id',axis=1,inplace=True)
df['Open Date'] = pd.to_datetime(df['Open Date'])
test_df['Open Date'] = pd.to_datetime(test_df['Open Date'])
launch_date = datetime.datetime(2015, 3, 23)
# scale days open
df['Days Open'] = (launch_date - df['Open Date']).dt.days / 1000
test_df['Days Open'] = (launch... | Yes | 3 | 8 | Data_Transform | feature_engineering | 12,343,159 | 2 | B | 1 | 0 | 0 | 0 | 16 | 9 | ok | 2 | 1 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 9"}, {"detector": "framework_specific", "framework": "General", "name": "Import Checker", ... | A | no applicable ML-specific findings | [] | ["Import Checker"] | 15 | B |
773 | plt.rc('figure', max_open_warning = 0)
for i in range(1,38):
fig, ax = plt.subplots(1,2, figsize=(19, 5))
g1 = sns.distplot(df['P{}'.format(i)], ax=ax[0], kde=False);
g2 = sns.distplot(test_df['P{}'.format(i)], ax=ax[1], kde=False);
fig.show() | No | 5 | 33 | Visualization | distribution | 12,343,159 | 1 | A | 0 | 1 | 1 | 0 | 0 | 6 | ok | 2 | 1 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 9"}, {"detector": "framework_specific", "framework": "General", "name": "Import Checker", ... | A | no applicable ML-specific findings | [] | ["Import Checker"] | 15 | A |
774 | df.dtypes | No | 1 | 37 | EDA | count_data_types | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
775 | b"(mu, sigma) = norm.fit(df['revenue'])\nf, (ax1, ax2) = plt.subplots(1, 2, figsize=(19, 5))\nax1 = sns.distplot(df['revenue'] , fit=norm, ax=ax1)\nax1.legend([f'Normal distribution ($\\mu=$ {mu:.3f} and $\\sigma=$ {sigma:.3f})'], loc='best')\nax1.set_ylabel('Frequency')\nax1.set_title('Revenue Distribution')\nax2 = st... | No | 5 | 33 | Visualization | distribution | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
776 | b"# Revenue is right skewed, taking the log will make it more normally distributed for the linear models\n# Remember to use expm1 on predictions to transform back to dollar amount\n(mu, sigma) = norm.fit(np.log1p(df['revenue']))\nf, (ax1, ax2) = plt.subplots(1, 2, figsize=(19, 5))\nax1 = sns.distplot(np.log1p(df['reven... | No | 4 | 33 | Visualization | distribution | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
778 | # Correlation between numeric features with revenue
plt.figure(figsize=(10, 8))
sns.heatmap(df.drop(['revenue','City Group','Type'], axis=1).corr(), square=True)
plt.suptitle('Pearson Correlation Heatmap')
plt.show(); | No | 5 | 80 | Visualization | heatmap | 12,343,159 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 2 | 1 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 9"}, {"detector": "framework_specific", "framework": "General", "name": "Import Checker", ... | A | no applicable ML-specific findings | [] | ["Import Checker"] | 15 | A |
779 | corr_with_revenue = df.drop(['City Group','Type'],axis=1).corr()['revenue'].sort_values(ascending=False)
plt.figure(figsize=(10,7))
corr_with_revenue.drop('revenue').plot.bar()
plt.show(); | No | 5 | 33 | Visualization | distribution | 12,343,159 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 2 | 1 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 9"}, {"detector": "framework_specific", "framework": "General", "name": "Import Checker", ... | A | no applicable ML-specific findings | [] | ["Import Checker"] | 15 | A |
780 | sns.pairplot(df[df.corr()['revenue'].sort_values(ascending=False).index[:5]])
plt.show(); | No | 5 | 81 | Visualization | relationship | 12,343,159 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 2 | 1 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 9"}, {"detector": "framework_specific", "framework": "General", "name": "Import Checker", ... | A | no applicable ML-specific findings | [] | ["Import Checker"] | 15 | A |
781 | # copy_df = df.copy()
# copy_test_df = test_df.copy()
# numeric_features = df.dtypes[df.dtypes != "object"].index
# skewed_features = df[numeric_features].apply(lambda x: skew(x))
# skewed_features = skewed_features[skewed_features > 0.5].index
# df[skewed_features] = np.log1p(df[skewed_features])
# test_df[skewed_feat... | No | 4 | 17 | Data_Transform | correct_missing_values | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
782 | # drop_first=True for Dummy Encoding for object types, and drop_first=False for OHE
columnsToEncode = df.select_dtypes(include=[object]).columns
df = pd.get_dummies(df, columns=columnsToEncode, drop_first=False)
test_df = pd.get_dummies(test_df, columns=columnsToEncode, drop_first=False) | No | 5 | 20 | Data_Transform | categorify | 12,343,159 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 2 | 1 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 9"}, {"detector": "framework_specific", "framework": "General", "name": "Import Checker", ... | A | no applicable ML-specific findings | [] | ["Import Checker"] | 15 | A |
783 | df['revenue'] = np.log1p(df['revenue'])
X, y = df.drop('revenue', axis=1), df['revenue']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=118) | No | 3 | 13 | Data_Transform | split | 12,343,159 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 3 | 2 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 9"}, {"detector": "framework_specific", "framework": "General", "name": "Import Checker", ... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Import Checker"] | 15 | B |
784 | from sklearn.model_selection import GridSearchCV
from sklearn.linear_model import Ridge
from sklearn.linear_model import Lasso | 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 |
785 | params_ridge = {
'alpha' : [.01, .1, .5, .7, .9, .95, .99, 1, 5, 10, 20],
'fit_intercept' : [True, False],
'normalize' : [True,False],
'solver' : ['svd', 'cholesky', 'lsqr', 'sparse_cg', 'sag', 'saga']
}
ridge_model = Ridge()
ridge_regressor = GridSearchCV(ridge_model, params_ridge, scoring='neg_root_m... | No | 4 | 6 | Hyperparam_Tuning | train_on_grid | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
786 | ridge_model = Ridge(alpha=ridge_regressor.best_params_["alpha"], fit_intercept=ridge_regressor.best_params_["fit_intercept"],
normalize=ridge_regressor.best_params_["normalize"], solver=ridge_regressor.best_params_["solver"])
ridge_model.fit(X_train, y_train)
y_train_pred = ridge_model.predict(X_tr... | No | 3 | 28 | Model_Train | compute_train_metric | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
787 | # Ridge Model Feature Importance
ridge_feature_coef = pd.Series(index = X_train.columns, data = np.abs(ridge_model.coef_))
ridge_feature_coef.sort_values().plot(kind = 'bar', figsize = (13,5)); | No | 3 | 79 | Visualization | model_coefficients | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
788 | params_lasso = {
'alpha' : [.01, .1, .5, .7, .9, .95, .99, 1, 5, 10, 20],
'fit_intercept' : [True, False],
'normalize' : [True,False],
}
lasso_model = Lasso()
lasso_regressor = GridSearchCV(lasso_model, params_lasso, scoring='neg_root_mean_squared_error', cv=5, n_jobs=-1)
lasso_regressor.fit(X_train, y_tra... | No | 4 | 6 | Hyperparam_Tuning | train_on_grid | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
789 | lasso_model = Lasso(alpha=lasso_regressor.best_params_["alpha"], fit_intercept=lasso_regressor.best_params_["fit_intercept"],
normalize=lasso_regressor.best_params_["normalize"])
lasso_model.fit(X_train, y_train)
y_train_pred = lasso_model.predict(X_train)
y_pred = lasso_model.predict(X_test)
print... | No | 4 | 28 | Model_Train | compute_train_metric | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
790 | # Lasso Model Feature Importance
lasso_feature_coef = pd.Series(index = X_train.columns, data = np.abs(lasso_model.coef_))
lasso_feature_coef.sort_values().plot(kind = 'bar', figsize = (13,5)); | No | 3 | 79 | Visualization | model_coefficients | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
791 | from sklearn.linear_model import ElasticNetCV, ElasticNet
# Use ElasticNetCV to tune alpha automatically instead of redundantly using ElasticNet and GridSearchCV
el_model = ElasticNetCV(l1_ratio=[.1, .5, .7, .9, .95, .99, 1], eps=5e-2, cv=10, n_jobs=-1)
el_model.fit(X_train, y_train)
print(f'Optimal alpha: {e... | No | 4 | 6 | Hyperparam_Tuning | train_on_grid | 12,343,159 | 1 | A | 1 | 0 | 0 | 0 | 5 | 6 | ok | 6 | 5 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 9"}, {"detector": "framework_specific", "framework": "General", "name": "Import Checker", ... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Exception Handling Checker", "Import Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 15 | B |
792 | y_train_pred = el_model.predict(X_train)
y_pred = el_model.predict(X_test)
print('Train r2 score: ', r2_score(y_train_pred, y_train))
print('Test r2 score: ', r2_score(y_test, y_pred))
train_rmse = np.sqrt(mean_squared_error(y_train_pred, y_train))
test_rmse = np.sqrt(mean_squared_error(y_test, y_pred))
print(f'Train R... | No | 3 | 28 | Model_Train | compute_train_metric | 12,343,159 | 1 | A | 0 | 0 | 0 | 0 | 0 | 8 | ok | 7 | 5 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 9"}, {"detector": "framework_specific", "framework": "General", "name": "Import Checker", ... | B | No random seed setting detected=low | [{"type": "No random seed setting detected", "severity": "low"}] | ["Exception Handling Checker", "Import Checker", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker"] | 15 | B |
793 | # ElasticNet Model Feature Importance
el_feature_coef = pd.Series(index = X_train.columns, data = np.abs(el_model.coef_))
n_features = (el_feature_coef>0).sum()
print(f'{n_features} features with reduction of {(1-n_features/len(el_feature_coef))*100:2.2f}%')
el_feature_coef.sort_values().plot(kind = 'bar', figsize = (1... | No | 5 | 79 | Visualization | model_coefficients | 12,343,159 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 2 | 1 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 9"}, {"detector": "framework_specific", "framework": "General", "name": "Import Checker", ... | A | no applicable ML-specific findings | [] | ["Import Checker"] | 15 | A |
794 | import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
import seaborn as sns
import os
from math import sqrt | No | 5 | 22 | Environment | import_modules | 13,503,938 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 9 | A |
795 | for dirname, _, filenames in os.walk('/kaggle/input'):
for filename in filenames:
print(os.path.join(dirname, filename)) | No | 5 | 88 | Debug | list_files | null | 1 | A | 0 | 2 | 3 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
796 | PATH='/kaggle/input/restaurant-revenue-prediction'
train_df=pd.read_csv(os.path.join(PATH,'train.csv.zip'))
test_df=pd.read_csv(os.path.join(PATH,'test.csv.zip')) | No | 5 | 45 | Data_Extraction | load_from_csv | 13,503,938 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 4 | 3 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Datatype Checker", "fix": "Set data types explicitly when importing data.", "benefits": "Ensures correct data format and reduces memory usage.", "location": "Line 12"}, {"detector": "framework_specific", "framework": "Pandas", "name": "Datatype Checker... | A | no applicable ML-specific findings | [] | ["Datatype Checker", "Hardcoded file path", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness."] | 9 | A |
797 | print('Train Data Shape:',train_df.shape)
print('Test Data Shape:',test_df.shape)
print('Features:',train_df.columns) | No | 4 | 58 | Debug | show_shape | 13,503,938 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 9 | A |
798 | train_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 |
799 | sns.distplot(train_df['revenue'],hist=False)
plt.title('Target Variable Distribution')
plt.show() | No | 5 | 33 | Visualization | distribution | 13,503,938 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}] | A | no applicable ML-specific findings | [] | ["Column Selection Checker"] | 9 | A |
800 | train_df.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 |
801 | def get_month(date):
return int(date.split('/')[0])
def get_year(date):
return int(date.split('/')[-1])
train_df['Month']=train_df['Open Date'].apply(get_month)
train_df['Year']=train_df['Open Date'].apply(get_year) | No | 5 | 8 | Data_Transform | feature_engineering | 13,503,938 | 1 | A | 0 | 2 | 0 | 0 | 0 | 6 | ok | 6 | 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, 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", "Hardcoded file path"] | 9 | B |
802 | test_df['Month']=test_df['Open Date'].apply(get_month)
test_df['Year']=test_df['Open Date'].apply(get_year) | No | 5 | 8 | Data_Transform | feature_engineering | 13,503,938 | 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"] | 9 | A |
803 | print(train_df['Id'].shape) # the id has all unique values hence removing it
train_df.drop('Id',axis=1,inplace=True)
test_indexes=test_df['Id']
test_df.drop('Id',axis=1,inplace=True) | No | 3 | 10 | Data_Transform | drop_column | 13,503,938 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 4 | 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 11"}, {"detector": "framework_specific", "framework": "Pandas", "name": "InPlace Checker", "fix": ... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Column Selection Checker", "InPlace Checker"] | 9 | B |
804 | plt.figure(figsize=(10,5))
sns.countplot(x='Month',data=train_df)
plt.xlabel('Opening Month')
plt.ylabel('Openings')
plt.title('No of openings per month')
plt.show() | No | 5 | 75 | Visualization | time_series | 13,503,938 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 9 | A |
805 | plt.figure(figsize=(13,5))
months_revenue_mean=train_df.groupby('Month')['revenue'].mean()
sns.pointplot(x=months_revenue_mean.index,y=months_revenue_mean.values)
plt.title('Revenue Vs Month')
plt.show() | No | 5 | 33 | Visualization | distribution | 13,503,938 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "general_ml", "framework": "General ML", "name... | B | Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}] | [] | 9 | B |
806 | (train_df['Month']=='05').sum()
(train_df['Month']=='06').sum()
(train_df['Month']=='07').sum() | No | 5 | 72 | EDA | count_values | 13,503,938 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | 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"] | 9 | B |
807 | plt.figure(figsize=(13,5))
sns.countplot(x='Year',data=train_df)
plt.ylabel('Number of Openings')
plt.title('Number Of Openings Per Year')
plt.show() | No | 5 | 75 | Visualization | time_series | 13,503,938 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 9 | A |
808 | plt.figure(figsize=(14,5))
year_revenue_means=train_df.groupby('Year')['revenue'].mean()
sns.pointplot(year_revenue_means.index,year_revenue_means.values)
plt.xlabel('Revenue')
plt.ylabel('Year')
plt.title('Revenue Per Year')
plt.show() | No | 5 | 33 | Visualization | distribution | 13,503,938 | 1 | A | 0 | 0 | 0 | 0 | 0 | 7 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "general_ml", "framework": "General ML", "name... | B | Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}] | [] | 9 | B |
809 | print('Datapoints in Year 2013:',(train_df['Year']=='2013').sum())
print('Datapoints in Year 2014:',(train_df['Year']=='2014').sum()) | No | 5 | 40 | Debug | show_table_attributes | 13,503,938 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | 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"] | 9 | B |
810 | print("City Group Categoies:",train_df['City Group'].unique())' | No | 5 | 57 | Debug | show_unique_values | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
811 | sns.countplot('City Group', data=train_df)
plt.title('City Group Counts')
plt.show() | No | 5 | 33 | Visualization | distribution | 13,503,938 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 9 | A |
812 | train_df['City Group'].value_counts() | No | 5 | 72 | EDA | count_values | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
813 | city_group_revenue_means=train_df.groupby('City Group')['revenue'].sum()
city_group_revenue_means | No | 5 | 60 | Data_Transform | groupby | 13,503,938 | 1 | A | 0 | 0 | 0 | 1 | 0 | 2 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "general_ml", "framework": "General ML", "name... | B | Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}] | [] | 9 | B |
814 | sns.lineplot(x='City Group',y='revenue',data=train_df) | No | 5 | 81 | Visualization | relationship | 13,503,938 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 9 | A |
815 | ## converting it into dummies
city_group_dummies=pd.get_dummies(train_df['City Group'])
train_df=pd.concat([train_df,city_group_dummies],axis=1) | No | 4 | 11 | Data_Transform | concatenate | 13,503,938 | 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"] | 9 | A |
816 | test_city_group_dummies=pd.get_dummies(test_df['City Group'])
test_df=pd.concat([test_df,test_city_group_dummies],axis=1) | No | 4 | 11 | Data_Transform | concatenate | 13,503,938 | 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"] | 9 | A |
817 | print('Tyes in train df:',train_df['Type'].unique())
print('Types in test df:',test_df['Type'].unique()) | No | 5 | 57 | Debug | show_unique_values | 13,503,938 | 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"] | 9 | B |
818 | fig,ax = plt.subplots(1,2,figsize=(9,5))
sns.countplot(train_df.Type,ax=ax[0])
ax[0].set_title('Train set')
sns.countplot(test_df.Type,ax=ax[1])
ax[1].set_title('Test set')
plt.show() | No | 5 | 33 | Visualization | distribution | 13,503,938 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | 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"] | 9 | A |
819 | type_map={'IL':0,'FC':1,'DT':2,'MB':3}
train_df['Type']=train_df['Type'].apply(lambda type:type_map[type])
test_df['Type']=test_df['Type'].apply(lambda type:type_map[type]) | No | 4 | 20 | Data_Transform | categorify | 13,503,938 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Valida... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Column Selection Checker"] | 9 | B |
820 | ## converting the type into dummies
type_dummies=pd.get_dummies(train_df['Type'])
train_df=pd.concat([train_df,type_dummies],axis=1)
train_df['3']=[0]*train_df.shape[0] | No | 4 | 11 | Data_Transform | concatenate | 13,503,938 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}] | A | no applicable ML-specific findings | [] | ["Column Selection Checker"] | 9 | A |
821 | test_type_dummies=pd.get_dummies(test_df['Type'])
test_df=pd.concat([test_df,test_type_dummies],axis=1) | No | 4 | 11 | Data_Transform | concatenate | 13,503,938 | 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"] | 9 | A |
822 | train_df['City'].unique() | No | 5 | 57 | Debug | show_unique_values | 13,503,938 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Valida... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Column Selection Checker"] | 9 | B |
823 | # dropping all the columns which have been utilized already
train_df.drop(['Open Date','City','City Group','Type'],axis=1,inplace=True)
test_df.drop(['Open Date','City','City Group','Type'],axis=1,inplace=True) | No | 5 | 10 | Data_Transform | drop_column | 13,503,938 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 3 | 2 | [{"detector": "framework_specific", "framework": "Pandas", "name": "InPlace Checker", "fix": "Assign operations to a new DataFrame variable.", "benefits": "Prevents data loss and improves code clarity.", "location": "Line 12"}, {"detector": "framework_specific", "framework": "Pandas", "name": "InPlace Checker", "fix": ... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["InPlace Checker"] | 9 | B |
824 | test_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 |
825 | from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import RandomForestRegressor
from sklearn.svm import SVR
from sklearn.metrics import mean_absolute_error,mean_squared_error,r2_score
from sklearn.mo... | No | 5 | 22 | Environment | import_modules | 13,503,938 | 1 | A | 0 | 0 | 0 | 0 | 0 | 7 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 9 | A |
826 | print('Train Data Shape After EDA:',train_df.shape)
print('Test Data Shape After EDA:',test_df.shape) | No | 5 | 58 | Debug | show_shape | 13,503,938 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 9 | A |
827 | Y=train_df['revenue']
train_df.drop('revenue',axis=1,inplace=True)
X=train_df.values
X_Test=test_df.values | No | 5 | 21 | Data_Transform | prepare_x_and_y | 13,503,938 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 3 | 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 11"}, {"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker"... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Column Selection Checker", "InPlace Checker"] | 9 | B |
828 | X.shape,X_Test.shape | No | 5 | 58 | Debug | show_shape | 13,503,938 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 9 | A |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.