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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
405 | import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
import seaborn as sns
from datetime import datetime | No | 5 | 22 | Environment | import_modules | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 0 | A |
406 | model_eval('Fatalities') | No | 5 | 53 | Other | something_strange | 8,706,858 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 1 | A |
407 | def model(case):
state = df['Province_State'].unique()
confirmed = []
for s in state:
train_ts = df[df['Province_State'] == s][:57]
pred_ts = df[df['Province_State'] == s][57:]
a = 9999
for pdq in pdq_results:
try:
model = ARIMA(train_ts[c... | No | 3 | 48 | Model_Evaluation | predict_on_test | 8,706,858 | 1 | A | 2 | 4 | 11 | 0 | 10 | 26 | ok | 8 | 6 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}] | ["Magic number", "Missing function docstring", "Unit Testing Checker", "Verbose Mode Checker"] | 1 | B |
408 | print('Importing training and test data')
train_df = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-2/train.csv')
test_df = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-2/test.csv')
# Update dataframe
train_df['Province_State'] = train_df['Province_State'].fillna('')
train_df['Region'] = trai... | No | 4 | 8 | Data_Transform | feature_engineering | 8,710,137 | 1 | A | 0 | 1 | 1 | 0 | 0 | 21 | ok | 5 | 3 | [{"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 30"}, {"detector": "framework_specific", "framework": "Pandas", "name": "Chain Indexi... | A | no applicable ML-specific findings | [] | ["Chain Indexing", "Column Selection Checker", "Hardcoded file path"] | 2 | A |
409 | model('ConfirmedCases') | No | 3 | 48 | Model_Evaluation | predict_on_test | 8,706,858 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 1 | A |
410 | model('Fatalities') | No | 3 | 48 | Model_Evaluation | predict_on_test | 8,706,858 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 1 | A |
411 | results = test[['ForecastId', 'ConfirmedCases', 'Fatalities']]
results.to_csv('submission.csv', index = False) | No | 5 | 25 | Data_Export | save_to_csv | 8,706,858 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 1 | A |
412 | train_max_date = train_df[train_df['Region']=='Sweden']['Date'].max()
dt_train_max = datetime.strptime(train_max_date, '%Y-%m-%d')
train_max_day = dt_train_max.timetuple().tm_yday - dt_train_min.timetuple().tm_yday
#print(train_max_day)
#int(train_data["Sweden"][train_data["Sweden"]['DayNo']==69]['ConfirmedCases'].toli... | No | 5 | 77 | Other | define_variables | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
413 | def sigmoid(x, a, b, c):
return a*np.exp(c*(x-b))/(np.exp(c*(x-b))+1) | No | 5 | 84 | Other | not_enough_vertices | null | 1 | A | 0 | 1 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
414 | import numpy as np
import pandas as pd | No | 4 | 22 | Environment | import_modules | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 0 | A |
415 | # HYPEROPT
def auc_model(params):
params = {
"n_estimators": int(params["n_estimators"]),
"max_features": int(params["max_features"]),
"min_samples_leaf": int(params["min_samples_leaf"]),
"min_samples_split": int(params["min_samples_split"]),
}
clf = RandomForestRegressor(**p... | No | 4 | 1 | Hyperparam_Tuning | find_best_score | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
416 | failed_confirmed = []
failed_fatalities = []
confirmed_popt = {}
fatalities_popt = {}
for region in regions:
x_data = train_data[region]['DayNo']
y_ConfirmedCases_data = train_data[region]['ConfirmedCases']
y_Fatalities_data = train_data[region]['Fatalities']
# Fit data to function
try:
po... | 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 |
417 | # Handle failed data
confirmed_coeffs = [x for x in confirmed_popt.values()]
mean_confirmed_coeffs = np.mean(confirmed_coeffs, axis=0)
print(mean_confirmed_coeffs)
fatalities_coeffs = [x for x in fatalities_popt.values()]
mean_fatalities_coeffs = np.mean(fatalities_coeffs, axis=0)
print(mean_fatalities_coeffs)
for ... | 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 |
418 | sub = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-2/submission.csv')
test_regions = test_df.Region.unique()
total_count = 0
for region in test_regions:
forecastIds = test_data[region]['ForecastId']
x_test_data = test_data[region]['DayNo']
y_conf_test_data = np.nan_to_num(sigmoid(x_test_data,... | No | 3 | 8 | Data_Transform | feature_engineering | 8,710,137 | 1 | A | 0 | 3 | 7 | 0 | 0 | 22 | ok | 6 | 3 | [{"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 8"}, {"detector": "framework_specific", "framework": "Pandas", "name": "Chain Indexin... | A | no applicable ML-specific findings | [] | ["Chain Indexing", "Column Selection Checker", "Hardcoded file path"] | 2 | A |
419 | # This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load in
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O... | No | 3 | 45 | Data_Extraction | load_from_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | ok | 2 | 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 7"}, {"detector": "general_ml", "framework": "General ML", "name": "Hard... | A | no applicable ML-specific findings | [] | ["Hardcoded file path"] | 0 | A |
420 | trainData['Open Date'] = pd.to_datetime(trainData['Open Date'], format='%m/%d/%Y')
testData['Open Date'] = pd.to_datetime(testData['Open Date'], format='%m/%d/%Y')
trainData['OpenDays']=""
testData['OpenDays']=""
dateLastTrain = pd.DataFrame({'Date':np.repeat(['01/01/2015'],[len(trainData)]) })
dateLastTrain['Date... | No | 4 | 16 | Data_Transform | data_type_conversions | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
421 | cityPerc = trainData[["City Group", "revenue"]].groupby(['City Group'],as_index=False).mean()
#sns.barplot(x='City Group', y='revenue', data=cityPerc)
citygroupDummy = pd.get_dummies(trainData['City Group'])
trainData = trainData.join(citygroupDummy)
citygroupDummyTest = pd.get_dummies(testData['City Group'])
testDat... | No | 4 | 10 | Data_Transform | drop_column | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
422 | #Regression on everything
from sklearn.ensemble import RandomForestRegressor
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_context("notebook", font_scale=1.1)
sns.set_style("ticks")
import numpy
xTrain = pd.DataFrame({'OpenDays':trainData['OpenDays'].apply(numpy.log),
'Big Cities'... | 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 |
423 | pred = cls.predict(xTest)
pred = numpy.exp(pred) | No | 5 | 48 | Model_Evaluation | predict_on_test | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
424 | pred | No | 5 | 53 | Other | something_strange | null | 1 | A | 0 | 0 | 0 | 1 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
425 | pred2 = []
for i in range(len(pred)):
if pred[i] != float('Inf'):
pred2.append(pred[i])
m = sum(pred2) / float(len(pred2))
for i in range(len(pred)):
if pred[i] == float('Inf'):
print("haha")
pred[i] = m' | 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 |
426 | # RANDOMFORESTREGRESSOR FOR CONFIRMEDCASUALTIES
rfr1 = RandomForestRegressor(
max_features=3,
min_samples_leaf=26,
min_samples_split=31,
n_estimators=200,
random_state=96,
n_jobs=-1,
) | No | 5 | 4 | Model_Train | choose_model_class | 8,708,118 | 1 | A | 0 | 0 | 0 | 0 | 0 | 8 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Verbose Mode Checker", "fix": "Enable verbose mode for long training processes.", "benefits": "Provides better insights into model training progress.", "location": "Line 33"}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": ... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Verbose Mode Checker"] | 31 | A |
427 | # RANDOMFORESTREGRESSOR FOR FATALITIES
rfr2 = RandomForestRegressor(
max_features=3,
min_samples_leaf=17,
min_samples_split=17,
n_estimators=100,
random_state=96,
n_jobs=-1,
) | No | 5 | 4 | Model_Train | choose_model_class | 8,708,118 | 1 | A | 0 | 0 | 0 | 0 | 0 | 8 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Verbose Mode Checker", "fix": "Enable verbose mode for long training processes.", "benefits": "Provides better insights into model training progress.", "location": "Line 33"}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": ... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Verbose Mode Checker"] | 31 | A |
428 | # FITTING RANDOMFORESTREGRESSOR FOR CONFIRMEDCASUALTIES
rfr1.fit(X1, y1) | No | 5 | 7 | Model_Train | train_model | 8,708,118 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 5 | 5 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Dependent Threshold Checker", "Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 31 | B |
429 | # PREDICTING CONFIRMEDCASUALTIES using RANDOM FOREST REGRESSOR
y_n_1 = rfr1.predict(test_1) | No | 5 | 48 | Model_Evaluation | predict_on_test | 8,708,118 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Threshold Checker", "fix": "Use threshold-independent metrics alongside threshold-dependent ones.", "benefits": "Provides a comprehensive evaluation of model performance.", "location": ""}, {"detector": "framework_specific", "framework":... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Exception Handling Checker", "Unit Testing Checker"] | 31 | A |
430 | # Fit CONFIRMEDCASUALTIES using K neareat neighbour algorithm Classifier
from sklearn.neighbors import KNeighborsClassifier
classifier = KNeighborsClassifier(n_neighbors = 4, metric = 'braycurtis', p = 1)
classifier.fit(X1, y1) | No | 4 | 7 | Model_Train | train_model | 8,708,118 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 5 | 5 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Dependent Threshold Checker", "Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 31 | B |
431 | ### Predict CONFIRMEDCASUALTIES using K neareat neighbour algorithm Classifier
y_pred1 = classifier.predict(X1)
# Making the Confusion Matrix
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y1, y_pred1)
from sklearn.metrics import accuracy_score
print( 'Accuracy Score confirmed cases :',accuracy_sc... | No | 4 | 27 | Model_Train | predict_on_train | 8,708,118 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Threshold Checker", "fix": "Use threshold-independent metrics alongside threshold-dependent ones.", "benefits": "Provides a comprehensive evaluation of model performance.", "location": ""}, {"detector": "framework_specific", "framework":... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Exception Handling Checker", "Unit Testing Checker"] | 31 | A |
432 | # FITTING RANDOMFORESTREGRESSOR FOR FATALITIES
rfr2.fit(X2, y2) | No | 5 | 7 | Model_Train | train_model | 8,708,118 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 5 | 5 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Dependent Threshold Checker", "Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 31 | B |
433 | # PREDICTING FATALITIES
y_n_2 = rfr2.predict(test_2) | No | 5 | 48 | Model_Evaluation | predict_on_test | 8,708,118 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Threshold Checker", "fix": "Use threshold-independent metrics alongside threshold-dependent ones.", "benefits": "Provides a comprehensive evaluation of model performance.", "location": ""}, {"detector": "framework_specific", "framework":... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Exception Handling Checker", "Unit Testing Checker"] | 31 | A |
434 | # ### Fit Fatalities using K neareat neighbour algorithm Classifier
from sklearn.neighbors import KNeighborsClassifier
classifier = KNeighborsClassifier(n_neighbors = 4, metric = 'braycurtis', p = 1)
classifier.fit(X2, y2) | No | 5 | 7 | Model_Train | train_model | 8,708,118 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 5 | 5 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Dependent Threshold Checker", "Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 31 | B |
435 | ### Predict Fatalities using K neareat neighbour algorithm Classifier
y_pred2 = classifier.predict(X2)
# Making the Confusion Matrix
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y2, y_pred2)
from sklearn.metrics import accuracy_score
print( 'Accuracy Score confirmed cases :',accuracy_score(y2,y_... | No | 3 | 27 | Model_Train | predict_on_train | 8,708,118 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Threshold Checker", "fix": "Use threshold-independent metrics alongside threshold-dependent ones.", "benefits": "Provides a comprehensive evaluation of model performance.", "location": ""}, {"detector": "framework_specific", "framework":... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Exception Handling Checker", "Unit Testing Checker"] | 31 | A |
436 | # ADDING CONFIRMEDCASES
xsubmission.ConfirmedCases = round(pd.DataFrame(y_n_1)) | No | 4 | 8 | Data_Transform | feature_engineering | 8,708,118 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Threshold Checker", "fix": "Use threshold-independent metrics alongside threshold-dependent ones.", "benefits": "Provides a comprehensive evaluation of model performance.", "location": ""}] | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker"] | 31 | A |
437 |
# ADDING FATALITIES
xsubmission.Fatalities = round(pd.DataFrame(y_n_2)) | No | 4 | 8 | Data_Transform | feature_engineering | 8,708,118 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Threshold Checker", "fix": "Use threshold-independent metrics alongside threshold-dependent ones.", "benefits": "Provides a comprehensive evaluation of model performance.", "location": ""}] | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker"] | 31 | A |
438 | # View submission data
xsubmission | No | 5 | 41 | Debug | show_table | 8,708,118 | 1 | A | 0 | 0 | 0 | 1 | 0 | 1 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Threshold Checker", "fix": "Use threshold-independent metrics alongside threshold-dependent ones.", "benefits": "Provides a comprehensive evaluation of model performance.", "location": ""}] | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker"] | 31 | A |
439 | # Save Date to submission file
xsubmission.to_csv("submission.csv", index=False)
print("Submission file create sucessfully") | No | 5 | 25 | Data_Export | save_to_csv | 8,708,118 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Threshold Checker", "fix": "Use threshold-independent metrics alongside threshold-dependent ones.", "benefits": "Provides a comprehensive evaluation of model performance.", "location": ""}] | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker"] | 31 | A |
440 | # This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load in
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O... | No | 5 | 88 | Debug | list_files | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 1 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path detected: ../input. Consider using configuration files or environment variables.", "fix": "Not specified", "benefits": "Not specified", "location": "Line 12"}] | A | no applicable ML-specific findings | [] | ["Hardcoded file path"] | 0 | A |
441 | from numpy import loadtxt
from xgboost import XGBClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score | No | 5 | 22 | Environment | import_modules | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 1"}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Thr... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Import Checker"] | 0 | A |
442 | Train_data = pd.read_csv("../input/train.csv")
Test_data = pd.read_csv("../input/test.csv")
ID = Test_data['Id']' | No | 5 | 45 | Data_Extraction | load_from_csv | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
443 | Train_data.head() | No | 5 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
444 | Test_data.head() | No | 5 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
445 | train_levels = Train_data.loc[(Train_data['City'].notnull())]
City_counts = train_levels['City'].value_counts().sort_index().to_frame()
City_counts | No | 5 | 72 | EDA | count_values | 2,637,869 | 1 | A | 0 | 0 | 0 | 1 | 0 | 3 | ok | 7 | 6 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 3"}, {"detector": "framework_specific", "framework": "General", "name": "Import Checker", ... | B | Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}] | ["Column Selection Checker", "Dependent Threshold Checker", "Import Checker"] | 8 | B |
446 | train_levels = Train_data.loc[(Train_data['Type'].notnull())]
label_counts = train_levels['Type'].value_counts().sort_index().to_frame()
label_counts | No | 5 | 72 | EDA | count_values | 2,637,869 | 1 | A | 0 | 0 | 0 | 1 | 0 | 3 | ok | 7 | 6 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 3"}, {"detector": "framework_specific", "framework": "General", "name": "Import Checker", ... | B | Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}] | ["Column Selection Checker", "Dependent Threshold Checker", "Import Checker"] | 8 | B |
447 | # lie
del Train_data["Open Date"]
del Train_data["City"]
del Train_data["City Group"]
del Train_data["Type"]
del Train_data["Id"]
del Test_data["Open Date"]
del Test_data["City"]
del Test_data["City Group"]
del Test_data["Type"]
del Test_data["Id"]' | No | 5 | 10 | Data_Transform | drop_column | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
448 | # 0
Train_data = Train_data.fillna(0)
Test_data = Test_data.fillna(0)
Test_data.head(10)' | No | 4 | 17 | Data_Transform | correct_missing_values | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
449 | #Regression on everything
from sklearn.ensemble import RandomForestRegressor
import seaborn as sns
import numpy
sns.set_context("notebook", font_scale=1.11)
sns.set_style("ticks")
yTrain = Train_data['revenue'].apply(numpy.log)
Train_data = Train_data.drop(["revenue"],1)
xTrain = pd.DataFrame(Train_data)
xTest = pd.D... | No | 3 | 22 | Environment | import_modules | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
450 | from sklearn import linear_model
from sklearn.ensemble import RandomForestRegressor
cls = RandomForestRegressor(n_estimators=170)
cls.fit(xTrain, yTrain)
pred = cls.predict(xTest)
pred = numpy.exp(pred)
closs = cls.score(xTrain, yTrain)
closs | No | 4 | 7 | Model_Train | train_model | 2,637,869 | 1 | A | 2 | 0 | 0 | 1 | 10 | 8 | ok | 13 | 10 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 3"}, {"detector": "framework_specific", "framework": "General", "name": "Import Checker", ... | B | Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low, Randomness Control Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}, {"type": "Randomness Control Checker", "severity": "low"}] | ["Dependent Threshold Checker", "Exception Handling Checker", "Import Checker", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker", "Verbose Mode Checker"] | 8 | B |
451 | pred = cls.predict(xTest)
pred = numpy.exp(pred)
pred | No | 4 | 27 | Model_Train | predict_on_train | 2,637,869 | 1 | A | 0 | 0 | 0 | 1 | 0 | 3 | ok | 5 | 4 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 3"}, {"detector": "framework_specific", "framework": "General", "name": "Import Checker", ... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Exception Handling Checker", "Import Checker", "Unit Testing Checker"] | 8 | A |
452 | read_test = {
"Id":ID,
"Prediction":pred
}
read_ = pd.DataFrame(read_test)
read_.to_csv("sample_submission.csv",index=False)
| No | 4 | 25 | Data_Export | save_to_csv | 2,637,869 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | 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 3"}, {"detector": "framework_specific", "framework": "General", "name": "Import Checker", ... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Import Checker"] | 8 | A |
453 | import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import random as rnd
# visualization
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
from nltk.classify import SklearnClassifier
from sklearn.ensemble import RandomForestClassifier, AdaBo... | No | 4 | 45 | Data_Extraction | load_from_csv | 5,466,844 | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 3 | null |
454 | print(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 |
455 | train['P29'] = train['P29'].astype(int)
test['P29'] = test['P29'].astype(int)
test["P29"].fillna(test["P29"].median(), inplace=True)
train['P26'] = train['P26'].astype(int)
test['P26'] = test['P26'].astype(int)
train['P27'] = train['P27'].astype(int)
test['P27'] = test['P27'].astype(int)
train['P28'] = train['... | No | 4 | 16 | Data_Transform | data_type_conversions | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
456 | train.describe(include=['object']) | 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 |
457 | train['City'].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 |
458 | train['City Group'].value_counts() | No | 5 | 72 | EDA | count_values | 5,466,844 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 1"}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validat... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Import Checker"] | 3 | B |
459 | train['Type'].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 |
460 | corrmat = train.corr()
f, ax = plt.subplots(figsize=(12, 9))
sns.heatmap(corrmat, vmax=.8, square=True); | No | 5 | 80 | Visualization | heatmap | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
461 | train["City Group"] = train["City Group"].map({"Big Cities": 0, "Other":1})
test["City Group"] = test["City Group"].map({"Big Cities": 0, "Other":1})
train["Type"] = train["Type"].map({"FC": 0, "IL":1,"DT":2})
test["Type"] = test["Type"].map({"FC": 0, "IL":1,"DT":2})
# Is city important or not
#How can we get groups of... | No | 5 | 20 | Data_Transform | categorify | 5,466,844 | 2 | B | 1 | 0 | 0 | 0 | 8 | 4 | ok | 4 | 4 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 1"}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validat... | 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"}] | ["Import Checker"] | 3 | B |
462 | test["Type"].fillna(test["Type"].median(), inplace=True)
train["revenue"].fillna(train["revenue"].median(), inplace=True)
train['revenue'] = train['revenue'].astype(int)
import numpy
Y_train=train["revenue"].apply(numpy.log)
' | 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 |
463 | X_train = train.drop(['City','Open Date','revenue','Id','City Group'], axis=1)
#X_test = test.drop("Id",axis=1).copy()
X_test = test.drop(['City','Open Date','Id','City Group'], axis=1)
X_train.head()
#X_test.head()' | No | 4 | 10 | Data_Transform | drop_column | null | 2 | B | 1 | 0 | 0 | 0 | 5 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
464 | #from sklearn.impute import SimpleImputer
#my_imputer = SimpleImputer()
#imputed_X_train = my_imputer.fit_transform(X_train)
#imputed_X_test = my_imputer.transform(X_test) | No | 3 | 12 | Data_Transform | create_dataframe | 5,466,844 | 1 | A | 1 | 0 | 0 | 0 | 5 | 0 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 1"}] | A | no applicable ML-specific findings | [] | ["Import Checker"] | 3 | A |
466 | test.head()
test=test.drop(['City','Open Date','City Group'], axis=1) | No | 5 | 10 | Data_Transform | drop_column | 5,466,844 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 1 | 1 | [{"detector": "framework_specific", "framework": "General", "name": "Import Checker", "fix": "Use standard naming conventions for imported modules.", "benefits": "Improves code readability and maintainability.", "location": "Line 1"}] | A | no applicable ML-specific findings | [] | ["Import Checker"] | 3 | A |
467 | submission | No | 5 | 41 | Debug | show_table | null | 1 | A | 0 | 0 | 0 | 1 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
468 | submission.to_csv('submission.csv', index=False) | No | 5 | 25 | Data_Export | save_to_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
469 | # This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load in
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O... | No | 4 | 22 | Environment | import_modules | 6,470,191 | 1 | A | 0 | 2 | 3 | 0 | 0 | 9 | ok | 1 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path detected: /kaggle/input. Consider using configuration files or environment variables.", "fix": "Not specified", "benefits": "Not specified", "location": "Line 18"}] | A | no applicable ML-specific findings | [] | ["Hardcoded file path"] | 3 | A |
471 | print('Start model training')
start_time = time.time()
history_cc = model_cc.fit(X_train_cc, y_train_cc, epochs = 100,validation_data = (X_val_cc, y_val_cc), verbose = 2, callbacks=[early_stop])
model_cc.save("model_cc.h5")
print('Time spent for model training is {} minutes'.format(round((time.time()-start_time)/60,1))... | No | 4 | 7 | Model_Train | train_model | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
472 | # Plot training & validation loss values
plt.figure(figsize=(8,5))
plt.plot(history_cc.history['loss'])
plt.plot(history_cc.history['val_loss'])
plt.title('CC Model loss')
plt.ylabel('Loss')
plt.xlabel('Epoch')
plt.legend(['Train', 'Test'], loc='upper left')
plt.show() | No | 5 | 35 | Visualization | learning_history | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 8 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
473 | print('Start model training')
start_time = time.time()
history_ft = model_ft.fit(X_train_ft, y_train_ft, epochs = 100,validation_data = (X_val_ft, y_val_ft), verbose = 2, callbacks=[early_stop])
model_ft.save("model_ft.h5")
print('Time spent for model training is {} minutes'.format(round((time.time()-start_time)/60,1))... | No | 4 | 7 | Model_Train | train_model | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
474 | # Plot training & validation loss values
plt.figure(figsize=(8,5))
plt.plot(history_ft.history['loss'])
plt.plot(history_ft.history['val_loss'])
plt.title('FT Model loss')
plt.ylabel('Loss')
plt.xlabel('Epoch')
plt.legend(['Train', 'Test'], loc='upper left')
plt.show() | No | 5 | 35 | Visualization | learning_history | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 8 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
475 | # Validate if output makes sense
yhat_val_cc = model_cc.predict(X_val_cc)
print(yhat_val_cc) | No | 5 | 48 | Model_Evaluation | predict_on_test | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
476 | print(val_y_cc) | No | 5 | 53 | Other | something_strange | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
477 | # Validate if output makes sense
yhat_val_ft = model_cc.predict(X_val_ft)
print(yhat_val_ft) | No | 5 | 48 | Model_Evaluation | predict_on_test | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
478 | print(val_y_ft) | No | 5 | 53 | Other | something_strange | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
479 | #TODO: takes 14m ish, consider multi-processing, multi-cores, run in GPU
#TODO: create data_generate func
start_time = time.time()
test['Country_Region'] = test['Country_Region'].astype(str)
test['Province_State'] = test['Province_State'].astype(str)
country = test['Country_Region'].drop_duplicates()
adj_input_cols = [... | No | 2 | 8 | Data_Transform | feature_engineering | null | 1 | A | 8 | 5 | 20 | 0 | 30 | 43 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
480 | submission = pd.DataFrame()
submission['ForecastId'] = test_df['ForecastId']
submission['ConfirmedCases'] = test_df['cc_cases']
submission['Fatalities'] = test_df['ft_cases'] | No | 5 | 12 | Data_Transform | create_dataframe | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
481 | submission.to_csv("submission.csv",index=False) | No | 5 | 25 | Data_Export | save_to_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
482 | submission[:20] | 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 |
483 | import warnings
warnings.filterwarnings('ignore') | No | 5 | 23 | Environment | set_options | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
484 | import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns | No | 5 | 22 | Environment | import_modules | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 0 | A |
485 | df_train = pd.read_csv('/kaggle/input/restaurant-revenue-prediction/train.csv.zip')
df_test = pd.read_csv('/kaggle/input/restaurant-revenue-prediction/test.csv.zip')
df_train.shape, df_test.shape | No | 4 | 45 | Data_Extraction | load_from_csv | 8,382,140 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 3 | 2 | [{"detector": "general_ml", "framework": "General ML", "name": "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "fix": "Not specified", "benefits": "Not specified", "location": ""}, {"detector": "general_ml", "framework": "General ML", "name": "Har... | A | no applicable ML-specific findings | [] | ["Hardcoded file path", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness."] | 6 | A |
486 | train_revenue = df_train.pop('revenue') | No | 5 | 10 | Data_Transform | drop_column | 8,382,140 | 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"}] | [] | 6 | B |
487 | df_train.isnull().sum().sort_values(ascending=False) | 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 |
488 | df_test.isnull().sum().sort_values(ascending=False) | 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 |
489 | df_train['Open Date'] = df_train['Open Date'].str.split('/').apply(lambda x : x[2]) | No | 5 | 8 | Data_Transform | feature_engineering | 8,382,140 | 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, 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"] | 6 | B |
490 | df_test['Open Date'] = df_test['Open Date'].str.split('/').apply(lambda x : x[2]) | No | 5 | 8 | Data_Transform | feature_engineering | 8,382,140 | 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": "general_ml", "framework": "General ML", "name": "Hardcoded file path d... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Hardcoded file path"] | 6 | A |
491 | df_train.shape, df_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 |
492 | df_train.drop(columns=["Id"],inplace=True)
df_test_index = df_test.pop('Id')' | No | 5 | 10 | Data_Transform | drop_column | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
493 | from sklearn.preprocessing import OneHotEncoder
ohe = OneHotEncoder(handle_unknown='ignore') | No | 3 | 20 | Data_Transform | categorify | 8,382,140 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 6 | A |
494 | df_train_ohe = ohe.fit_transform(df_train)
df_train_ohe = df_train_ohe.todense() | No | 5 | 20 | Data_Transform | categorify | 8,382,140 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 7 | 7 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | D | Cross Validation Checker=low, Cross-validation not detected=low, Data Leakage Checker=high, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "Data Leakage Checker", "severity": "high"}, {"type": "No random seed setting detected", "severity": "low"}] | ["Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 6 | D |
495 | df_test_ohe = ohe.transform(df_test)
df_test_ohe = df_test_ohe.toarray() | No | 5 | 20 | Data_Transform | categorify | 8,382,140 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Unit Testing Checker", "fix": "Write unit tests for data processing and model components.", "benefits": "Ensures code reliability and prevents bugs.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Excepti... | A | no applicable ML-specific findings | [] | ["Exception Handling Checker", "Unit Testing Checker"] | 6 | A |
496 | df_train_ohe.shape | No | 5 | 58 | Debug | show_shape | 8,382,140 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 6 | A |
497 | df_test_ohe.shape | No | 5 | 58 | Debug | show_shape | 8,382,140 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 6 | A |
498 | from sklearn.ensemble import GradientBoostingRegressor
from sklearn.model_selection import GridSearchCV | 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 |
499 | param = {
"n_estimators": range(10,20,2),
"learning_rate": [0.0001,0.001,0.01,0.1],
"loss" : ['ls', 'lad', 'huber', 'quantile'],
"min_samples_split": range(10,15,2),
"min_samples_leaf": range(10,15,2),
"max_depth": range(10,20,2),
"alpha": [0,0.1,0.3,0.5,0.7,0.9]
}' | No | 5 | 5 | Hyperparam_Tuning | define_search_space | null | 1 | A | 0 | null | 0 | 0 | 0 | null | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
501 | gbr = GradientBoostingRegressor(alpha=0.1, ccp_alpha=0.0, criterion='friedman_mse',
init=None, learning_rate=0.1, loss='ls', max_depth=10,
max_features=None, max_leaf_nodes=None,
min_impurity_decrease=0.0, min_impurity_split=None,
... | No | 5 | 4 | Model_Train | choose_model_class | 8,382,140 | 1 | A | 0 | 0 | 0 | 0 | 0 | 9 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 6 | A |
502 | gbr.fit(df_train_ohe,train_revenue) | No | 5 | 7 | Model_Train | train_model | 8,382,140 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 4 | 4 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 6 | B |
503 | train_revenue_predict = gbr.predict(df_train_ohe)
test_revenue = gbr.predict(df_test_ohe) | No | 4 | 27 | Model_Train | predict_on_train | 8,382,140 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 5 | 4 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Unit Testing Checker", "fix": "Write unit tests for data processing and model components.", "benefits": "Ensures code reliability and prevents bugs.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Excepti... | B | No random seed setting detected=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"] | 6 | B |
504 | from sklearn.metrics import mean_squared_error
mse = mean_squared_error(train_revenue_predict,train_revenue)
rmse = np.sqrt(mse)
print(rmse) | No | 5 | 28 | Model_Train | compute_train_metric | 8,382,140 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 6 | A |
505 | df_submit = pd.DataFrame({'Id': df_test_index, 'Prediction': test_revenue}) | No | 5 | 12 | Data_Transform | create_dataframe | 8,382,140 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 6 | A |
506 | df_submit.to_csv('submit.csv',index=False)
df_submit.head() | No | 5 | 25 | Data_Export | save_to_csv | 8,382,140 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 6 | A |
507 | # This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.... | No | 5 | 88 | Debug | list_files | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.