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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
4,029 | train_set = pd.get_dummies(train_set, columns=['season', 'weather', 'weekday', 'holiday'])
# train_set = pd.get_dummies(train_set, columns=['season', 'weather', 'weekday', 'year', 'month', 'time']) | No | 5 | 20 | Data_Transform | categorify | 3,930,917 | 3 | C | 1 | 0 | 0 | 0 | 5 | 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"] | 6 | C |
4,030 | train_set['temp_weather_1'] = train_set['temp'] * train_set['weather_1']
train_set['temp_weather_2'] = train_set['temp'] * train_set['weather_2']
train_set['temp_weather_3'] = train_set['temp'] * train_set['weather_3']
train_set['temp_weather_4'] = train_set['temp'] * train_set['weather_4'] | No | 5 | 8 | Data_Transform | feature_engineering | 3,930,917 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | 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": "Dependent Th... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Dependent Threshold Checker"] | 6 | A |
4,031 | y = train_set.loc[:, 'count']
X = train_set.drop(['count', 'count_bin', 'casual', 'registered'], axis=1) | No | 5 | 21 | Data_Transform | prepare_x_and_y | 3,930,917 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Dependent Threshold Checker"] | 6 | B |
4,032 | rf = RandomForestRegressor(random_state=42, n_jobs=-1, n_estimators=200, oob_score=True, min_samples_split=4, max_features=0.9, max_depth=17)
rf.fit(X, y) | No | 5 | 7 | Model_Train | train_model | 3,930,917 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 6 | 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"] | 6 | B |
4,033 | scores = cross_val_score(rf, X, y, cv=5, scoring='neg_mean_squared_log_error')
print("score, root score: ", scores, np.sqrt(np.abs(scores)))' | No | 5 | 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 |
4,034 | d_importance = pd.DataFrame(columns=['features'], data=X.columns)
d_importance['importance'] = rf.feature_importances_
d_importance.sort_values(by='importance',ascending=False).head(20) | No | 5 | 79 | Visualization | model_coefficients | 3,930,917 | 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": "Dependent Th... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Dependent Threshold Checker"] | 6 | A |
4,044 | test_set = pd.read_csv(HOME_PATH+'/test.csv')
y_test = test_set['datetime']
test_set = process_df(test_set)
test_set = pd.get_dummies(test_set, columns=['season', 'weather', 'weekday', 'holiday']) | Yes | 2 | 45 | Data_Extraction | load_from_csv | 3,930,917 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Th... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Dependent Threshold Checker", "Hardcoded file path"] | 6 | A |
4,045 | test_set['temp_weather_1'] = test_set['temp'] * test_set['weather_1']
test_set['temp_weather_2'] = test_set['temp'] * test_set['weather_2']
test_set['temp_weather_3'] = test_set['temp'] * test_set['weather_3']
test_set['temp_weather_4'] = test_set['temp'] * test_set['weather_4']
test_set['temp_bin'] = np.floor(test_se... | No | 5 | 8 | Data_Transform | feature_engineering | 3,930,917 | 1 | A | 1 | 0 | 0 | 0 | 5 | 5 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Th... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Dependent Threshold Checker"] | 6 | A |
4,046 | test_set.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 |
4,047 | predictions = np.zeros_like(y_test)
predictions = (rf.predict(test_set)).round().astype(int)
predictions[predictions < 0] = 0
submission = pd.concat([y_test, pd.Series(predictions, name="count")], axis=1)
print(submission.head(30))
submission.to_csv("submission.csv", index=False) | Yes | 3 | 25 | Data_Export | save_to_csv | 3,930,917 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | ok | 9 | 7 | [{"detector": "framework_specific", "framework": "NumPy", "name": "Array Creation Efficiency", "fix": "Specify dtype when creating arrays.", "benefits": "Improves memory efficiency and avoids unnecessary conversions.", "location": "Line 7"}, {"detector": "framework_specific", "framework": "Pandas", "name": "Column Sele... | B | No random seed setting detected=low | [{"type": "No random seed setting detected", "severity": "low"}] | ["Array Creation Efficiency", "Column Selection Checker", "Dependent Threshold Checker", "Exception Handling Checker", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker"] | 6 | B |
4,048 | import numpy as np
import pandas as pd
train = pd.read_csv("../input/train.csv", parse_dates = ["datetime"])
test = pd.read_csv("../input/test.csv", parse_dates = ["datetime"])
train["year"] = train["datetime"].dt.year
train["hour"] = train["datetime"].dt.hour
train["dayofweek"] = train["datetime"].dt.dayofweek
test[... | Yes | 1 | 22 | Environment | import_modules | null | 1 | A | 3 | 0 | 0 | 0 | 15 | 29 | ok | 6 | 3 | [{"detector": "framework_specific", "framework": "Pandas", "name": "InPlace Checker", "fix": "Assign operations to a new DataFrame variable.", "benefits": "Prevents data loss and improves code clarity.", "location": "Line 18"}, {"detector": "framework_specific", "framework": "Pandas", "name": "InPlace Checker", "fix": ... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Hardcoded file path", "InPlace Checker"] | 0 | A |
4,049 | pd.options.display.max_rows = 200
submission["holiday"] = test["holiday"]
submission.loc[(submission["holiday"]==1)] | No | 4 | 55 | Data_Export | prepare_output | 4,080,034 | 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": "general_ml", "framework": "General ML", "name": "Magic number detected... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Magic number"] | 2 | A |
4,050 | # Filter cover type and then barplot of wilderness area to see if any trees grow exclusively in a region.
#data.describe()
data = dtrain.groupby(['Cover_Type'])[['Wilderness_Area1', 'Wilderness_Area2', 'Wilderness_Area3', 'Wilderness_Area4']].sum()
# Transpose to get numbers by wilderness type.
data.T.plot(kind = 'bar'... | Yes | 3 | 8 | Data_Transform | feature_engineering | 9,278,535 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 4 | 4 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}] | ["Dependent Threshold Checker"] | 6 | B |
4,051 | # Drop Soil type 15,7 - They have no variation.
dtrain.drop(['Soil_Type7', 'Soil_Type15'], axis = 1, inplace = True)
# filtering all columns that contain the str Soil
soil_columns = dtrain.columns[dtrain.columns.str.contains('Soil')].to_list() | Yes | 3 | 10 | Data_Transform | drop_column | 9,278,535 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 5 | 5 | [{"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 8"}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Chec... | B | Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}] | ["Dependent Threshold Checker", "InPlace Checker"] | 6 | B |
4,052 | data_soil = dtrain.groupby(['Cover_Type'])[soil_columns[:10]].sum()
data_soil.T.plot(kind = 'bar', figsize = (18,8))
plt.show() | Yes | 4 | 8 | Data_Transform | feature_engineering | 9,278,535 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | 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", "Dependent Threshold Checker"] | 6 | B |
4,053 | data_soil = dtrain.groupby(['Cover_Type'])[soil_columns[10:20]].sum()
data_soil.T.plot(kind = 'bar', figsize = (18,8))
plt.show() | Yes | 4 | 8 | Data_Transform | feature_engineering | 9,278,535 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | 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", "Dependent Threshold Checker"] | 6 | B |
4,054 | data_soil = dtrain.groupby(['Cover_Type'])[soil_columns[20:30]].sum()
data_soil.T.plot(kind = 'bar', figsize = (18,8))
plt.show() | Yes | 4 | 8 | Data_Transform | feature_engineering | 9,278,535 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | 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", "Dependent Threshold Checker"] | 6 | B |
4,055 | data_soil = dtrain.groupby(['Cover_Type'])[soil_columns[30:]].sum()
data_soil.T.plot(kind = 'bar', figsize = (18,8))
plt.show() | Yes | 4 | 8 | Data_Transform | feature_engineering | 9,278,535 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | 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", "Dependent Threshold Checker"] | 6 | B |
4,056 | label = dtrain['Cover_Type']
dtrain.drop(['Cover_Type'], axis = 1, inplace=True) | No | 5 | 10 | Data_Transform | drop_column | 9,278,535 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 4 | 4 | [{"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 8"}, {"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker",... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Column Selection Checker", "Dependent Threshold Checker", "InPlace Checker"] | 6 | B |
4,057 | from sklearn.model_selection import train_test_split, cross_val_score, GridSearchCV
from sklearn.metrics import accuracy_score, f1_score, classification_report,confusion_matrix
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
from xgboost import XGBClassifier | No | 5 | 22 | Environment | import_modules | 9,278,535 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | 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"] | 6 | A |
4,058 | x_train, x_test, y_train, y_test = train_test_split(dtrain, label, test_size = .3)
dirty_clf = RandomForestClassifier()
dirty_clf.fit(x_train, y_train)
print(dirty_clf.score(x_test, y_test))
imp_feat = pd.DataFrame(index= dtrain.columns.to_list() , data= dirty_clf.feature_importances_)
imp_feat.rename(columns={0 : 'Imp... | Yes | 2 | 4 | Model_Train | choose_model_class | 9,278,535 | 1 | A | 0 | 0 | 0 | 0 | 0 | 7 | ok | 11 | 9 | [{"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": "ScikitLearn", "name": "Cross Validation Che... | 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", "InPlace Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 6 | B |
4,059 | baseline_features = ['Elevation', 'Horizontal_Distance_To_Roadways']
features = ['Elevation', 'Horizontal_Distance_To_Roadways', 'Horizontal_Distance_To_Hydrology',
'Horizontal_Distance_To_Fire_Points', 'Aspect','Wilderness_Area1', 'Wilderness_Area4', 'Soil_Type3',
'Soil_Type4','Soil_Type10', 'S... | Yes | 3 | 21 | Data_Transform | prepare_x_and_y | 9,278,535 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | 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, Randomness Control Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Randomness Control Checker", "severity": "low"}] | ["Column Selection Checker", "Dependent Threshold Checker"] | 6 | B |
4,060 | clf = DecisionTreeClassifier(criterion='gini', max_depth=8, min_samples_split=2, class_weight= None, max_features=None,
max_leaf_nodes=None,
min_impurity_decrease=0.0,
min_impurity_s... | No | 5 | 4 | Model_Train | choose_model_class | 9,278,535 | 1 | A | 0 | 0 | 0 | 0 | 0 | 8 | 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"] | 6 | A |
4,061 | grid_params = {'criterion' : ["gini", "entropy"]}
grid = GridSearchCV(estimator=clf, param_grid=grid_params, n_jobs=-1, cv = 5)
grid.fit(x_train, y_train)
grid.score(x_test, y_test)' | Yes | 2 | 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 |
4,062 | grid.best_estimator_
y_pred = grid.predict(x_test) | No | 5 | 48 | Model_Evaluation | predict_on_test | 9,278,535 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Threshold Checker", "fix": "Use threshold-independent metrics alongside threshold-dependent ones.", "benefits": "Provides a comprehensive evaluation of model performance.", "location": ""}, {"detector": "framework_specific", "framework":... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "Exception Handling Checker", "Unit Testing Checker"] | 6 | A |
4,063 | clf.fit(x_train, y_train)
print(f'No of Leaves : {clf.get_n_leaves()}')
clf.feature_importances_ | Yes | 2 | 7 | Model_Train | train_model | 9,278,535 | 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"] | 6 | B |
4,064 | rnd_clf = RandomForestClassifier()
grid_params_1 = {'max_depth' : [18], 'n_estimators' : [127], 'criterion':['entropy']}
grid = GridSearchCV(estimator=rnd_clf, param_grid=grid_params_1, n_jobs=-1, cv = 5)
grid.fit(x_train, y_train) | Yes | 4 | 4 | Model_Train | choose_model_class | 9,278,535 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | ok | 8 | 5 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Randomness Control Checker", "fix": "Set random_state in estimators for reproducibility.", "benefits": "Ensures reproducible results and consistent model behaviour.", "location": "Line 7"}, {"detector": "framework_specific", "framework": "ScikitLe... | B | Randomness Control Checker=low | [{"type": "Randomness Control Checker", "severity": "low"}] | ["Dependent Threshold Checker", "Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 6 | B |
4,065 | final_clf = RandomForestClassifier(max_depth=18, n_estimators=127, criterion='entropy')
final_clf.fit(x_train, y_train)
print(final_clf.score(x_train, y_train))
print(final_clf.score(x_test, y_test))
y_hat = final_clf.predict(x_test) | Yes | 2 | 4 | Model_Train | choose_model_class | 9,278,535 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 11 | 9 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLear... | B | Cross Validation Checker=low, Cross-validation not detected=low, No random seed setting detected=low, Randomness Control Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "No random seed setting detected", "severity": "low"}, {"type": "Randomness Control Checker", "severity": "low"}] | ["Dependent Threshold Checker", "Exception Handling Checker", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker", "Verbose Mode Checker"] | 6 | B |
4,066 | plt.figure(figsize=(8,8))
sns.heatmap(pd.DataFrame(confusion_matrix(y_test, y_pred),
index = label_dict.values(), columns= label_dict.values()), annot=True, cbar = False)
plt.show() | No | 5 | 80 | Visualization | heatmap | 9,278,535 | 1 | A | 0 | 0 | 0 | 0 | 0 | 4 | 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"] | 6 | A |
4,067 | imp_feat = pd.DataFrame(index= features , data= final_clf.feature_importances_)
imp_feat.rename(columns={0 : 'Importance'}, inplace=True)
imp_feat.sort_values(by='Importance', axis =0, ascending=False) | Yes | 2 | 12 | Data_Transform | create_dataframe | 9,278,535 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 2 | 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 8"}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Threshold C... | A | no applicable ML-specific findings | [] | ["Dependent Threshold Checker", "InPlace Checker"] | 6 | A |
4,068 | xgb_clf = XGBClassifier(n_estimators=100, max_depth = 12) | No | 5 | 4 | Model_Train | choose_model_class | 9,278,535 | 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"] | 6 | A |
4,070 | xgb_clf.fit(x_train, y_train)
xgb_clf.score(x_test, y_test) | Yes | 3 | 7 | Model_Train | train_model | 9,278,535 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 6 | 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, Cross-validation not detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}] | ["Dependent Threshold Checker", "Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 6 | B |
4,071 | y_pred = xgb_clf.predict(x_test) | No | 5 | 48 | Model_Evaluation | predict_on_test | 9,278,535 | 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"] | 6 | A |
4,072 | # Final Fit
xgb_clf.fit(dtrain[features], label) | No | 5 | 7 | Model_Train | train_model | 9,278,535 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 6 | 6 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Valida... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Column Selection Checker", "Dependent Threshold Checker", "Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 6 | B |
4,073 | y_test_hat = xgb_clf.predict(dtest[features]) | No | 5 | 48 | Model_Evaluation | predict_on_test | 9,278,535 | 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": "Dependent Th... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Dependent Threshold Checker", "Exception Handling Checker", "Unit Testing Checker"] | 6 | A |
4,074 | sns.distplot(dtest.Elevation) | No | 5 | 33 | Visualization | distribution | 9,278,535 | 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"] | 6 | A |
4,075 | df_submit = pd.read_csv(submit_path, index_col=0)
df_submit['Cover_Type'] =y_test_hat
df_submit.to_csv('submit_kaggle.csv') | Yes | 4 | 25 | Data_Export | save_to_csv | 9,278,535 | 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": "Dependent Th... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Dependent Threshold Checker"] | 6 | A |
4,076 |
import os
#donnes
print(os.listdir("../input"))
# Any results you write to the current directory are saved as output.
import pandas as pd
import numpy as np
#random forest pour regressor
from sklearn.ensemble import RandomForestRegressor
#Pour le split feature et target
from sklearn.model_selection import train_test_... | Yes | 4 | 22 | Environment | import_modules | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
4,077 | # Fichier de train
X_train = pd.read_csv("../input/train.csv")
#Fichier de test
X_test = pd.read_csv("../input/test.csv") | No | 5 | 45 | Data_Extraction | load_from_csv | 4,159,668 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | 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 |
4,078 | submission = pd.read_csv("../input/sampleSubmission.csv")
submission["count"] = 195 | Yes | 3 | 25 | Data_Export | save_to_csv | 4,159,668 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "general_ml", "framework": "General ML", "name": "Magic number detected... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Hardcoded file path", "Magic number"] | 6 | A |
4,079 | #Convertir notre fichier en csv
submission.to_csv('submission.csv', index=False) | No | 5 | 25 | Data_Export | save_to_csv | 4,159,668 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 6 | A |
4,080 | X_test.columns | No | 5 | 71 | Debug | show_columns | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
4,081 | ## Definition foncyion features et target
def split_dataset(df, features, target='count'):
X = df[features]
y = df[target]
return X, y
| No | 5 | 21 | Data_Transform | prepare_x_and_y | 4,159,668 | 1 | A | 0 | 1 | 0 | 0 | 0 | 4 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "general_ml", "framework": "General ML", "name": "Missing docstring for... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Missing function docstring"] | 6 | A |
4,082 | ## Fonction split date
def date_split(df_train, df_test, date='datetime'):
##Traitement_df_train
cols=df_train[date]
date_cols=pd.to_datetime(cols)
df_train['year'] = date_cols.dt.year
df_train['month'] = date_cols.dt.month
df_train['day'] = date_cols.dt.day
df_train['hour'] = date_cols.dt.h... | Yes | 4 | 21 | Data_Transform | prepare_x_and_y | 4,159,668 | 1 | A | 0 | 1 | 0 | 0 | 0 | 20 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Valida... | B | Cross Validation Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}] | ["Column Selection Checker", "Missing function docstring"] | 6 | B |
4,083 | #Definition de X_train et X_test avec les memes columns
X_train, X_test = date_split(X_train, X_test) | No | 5 | 13 | Data_Transform | split | 4,159,668 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 6 | A |
4,084 | #Appel de la fonction pour avoir le meme nombre de columns:
X_trainGet_cols = Get_cols(X_test)
numbers = X_trainGet_cols.select_dtypes(np.number)
numbers.head() | Yes | 2 | 41 | Debug | show_table | 4,159,668 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | 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 |
4,085 | ##Definition features and target
X_train_features, y_train_target = split_dataset(X_train, features=numbers.columns)
X_train_features, y_train_target | No | 5 | 13 | Data_Transform | split | 4,159,668 | 1 | A | 0 | 0 | 0 | 2 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 6 | A |
4,086 | ##################Cross Validation
## random forest regressor
#Import Random Forest pour regressor
from sklearn.ensemble import RandomForestRegressor
rf = RandomForestRegressor()
##Cross Validation
score = -cross_val_score(rf, X_train_features, y_train_target, cv=5, scoring='neg_mean_squared_error') | No | 3 | 22 | Environment | import_modules | 4,159,668 | 3 | C | 2 | 0 | 0 | 0 | 10 | 3 | ok | 4 | 4 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Randomness Control Checker", "fix": "Set random_state in estimators for reproducibility.", "benefits": "Ensures reproducible results and consistent model behaviour.", "location": "Line 11"}, {"detector": "framework_specific", "framework": "ScikitL... | B | Randomness Control Checker=low | [{"type": "Randomness Control Checker", "severity": "low"}] | ["Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 6 | C |
4,087 | ############### FIT entrainer tout le set d'entrainement
rf.fit(X_train_features, y_train_target) | No | 5 | 7 | Model_Train | train_model | 4,159,668 | 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 |
4,088 | ## Predict sur le train
y_train_pred = rf.predict(X_train_features) | No | 5 | 27 | Model_Train | predict_on_train | 4,159,668 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | 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 |
4,089 | ###### Predict sur le test
## Voir si on a le meme nombre de columns dans test et dans train
y_test_pred = rf.predict(X_test)
| No | 5 | 48 | Model_Evaluation | predict_on_test | 4,159,668 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | 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 |
4,090 | mean_train = mean_squared_error( y_train_target, y_train_pred)
#mean_test = mean_squared_error(y_test, y_test_pred)
mean_train
#, mean_test | No | 5 | 28 | Model_Train | compute_train_metric | 4,159,668 | 2 | B | 1 | 0 | 0 | 1 | 5 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 6 | B |
4,091 | submission = pd.read_csv("../input/sampleSubmission.csv")
submission["count"] = y_test_pred
#Convertir notre fichier en csv
submission.to_csv('submission.csv', index=False)' | Yes | 3 | 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 |
4,093 | submission.head(3) | 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 |
4,094 | import numpy as np
import pandas as pd
import seaborn as sns
from scipy import stats
import calendar
from datetime import datetime
import matplotlib.pyplot as plt
%matplotlib inline | Yes | 4 | 22 | Environment | import_modules | 4,205,919 | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 3 | null |
4,095 | fig,axes = plt.subplots(2,2)
fig.set_size_inches(12,10)
sns.distplot(train['temp'],ax=axes[0,0])
sns.distplot(train['atemp'],ax=axes[0,1])
sns.distplot(train['humidity'],ax=axes[1,0])
sns.distplot(train['windspeed'],ax=axes[1,1])
axes[0,0].set(xlabel='temp',title='Distribtion of temp')
axes[0,1].set(xlabel='atemp',ti... | Yes | 3 | 33 | Visualization | distribution | 4,205,919 | 1 | A | 0 | 0 | 0 | 0 | 0 | 10 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
4,096 | train['datetime'] = pd.to_datetime(train['datetime'],errors='coerce')
train['date'] = train['datetime'].apply(lambda x: x.date())
train['year'] = train['datetime'].apply(lambda x: x.year)
train['month'] = train['datetime'].apply(lambda x: x.month)
train['weekday'] = train['datetime'].apply(lambda x: x.weekday())
train[... | Yes | 2 | 16 | Data_Transform | data_type_conversions | 4,205,919 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | 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"}] | [] | 3 | B |
4,097 | dummies_month = pd.get_dummies(train['month'], prefix= 'month')
dummies_season = pd.get_dummies(train['season'], prefix= 'season')
dummies_weather = pd.get_dummies(train['weather'], prefix= 'weather')
dummies_year = pd.get_dummies(train['year'], prefix= 'year')
data=pd.concat([train,dummies_month,dummies_season,dummie... | Yes | 2 | 20 | Data_Transform | categorify | 4,205,919 | 1 | A | 0 | 0 | 0 | 0 | 0 | 10 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
4,098 | from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_log_error
from math import sqrt
import statsmodels.api as sm | No | 5 | 22 | Environment | import_modules | 4,205,919 | 1 | A | 0 | 0 | 0 | 0 | 0 | 5 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
4,099 | X_train_ca, X_valid_ca, y_train_ca, y_valid_ca = train_test_split(dataTrain,
train['casual'], test_size=0.3, random_state=42)
X_train_re, X_valid_re, y_train_re, y_valid_re = train_test_split(dataTrain,
train['registered'], test_size=0.3, random_... | No | 5 | 13 | Data_Transform | split | 4,205,919 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | ok | 2 | 2 | [{"detector": "framework_specific", "framework": "ScikitLearn", "name": "Cross Validation Checker", "fix": "Implement cross-validation techniques for robust model evaluation.", "benefits": "Enhances model performance and reduces overfitting.", "location": ""}, {"detector": "general_ml", "framework": "General ML", "name... | B | Cross Validation Checker=low, Cross-validation not detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}] | [] | 3 | B |
4,100 | rfModel_ca = RandomForestRegressor(n_estimators=1000 ,
oob_score=True, random_state = 42)
rfModel_ca.fit(X_train_ca , y_train_ca)
rfModel_re = RandomForestRegressor(n_estimators=1000 ,
oob_score=True, random_state = 42)
rfModel_re.fit(X_train_re ,... | Yes | 2 | 4 | Model_Train | choose_model_class | 4,205,919 | 1 | A | 0 | 0 | 0 | 0 | 0 | 9 | ok | 13 | 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, Cross-validation not detected=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not 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"] | 3 | B |
4,101 | preds_train_ca = rfModel_ca.predict( X = X_train_ca)
rmsle_casual_train = sqrt(mean_squared_log_error(y_train_ca, preds_train_ca))
preds_valid_ca = rfModel_ca.predict( X = X_valid_ca)
rmsle_casual_valid = sqrt(mean_squared_log_error(y_valid_ca, preds_valid_ca))
print('Casual train rmsle : %.5f, valid rmsle : %.5f' %(r... | Yes | 3 | 27 | Model_Train | predict_on_train | 4,205,919 | 1 | A | 0 | 0 | 0 | 0 | 0 | 12 | ok | 7 | 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"] | 3 | B |
4,102 | preds_train = rfModel.predict( X = X_train)
rmsle_count_train = sqrt(mean_squared_log_error(y_train, preds_train))
preds_valid = rfModel.predict( X = X_valid)
rmsle_count_valid = sqrt(mean_squared_log_error(y_valid, preds_valid))
print('Count train rmsle : %.5f, valid rmsle : %.5f' %(rmsle_count_train,
... | Yes | 3 | 27 | Model_Train | predict_on_train | 4,205,919 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | 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"] | 3 | B |
4,103 | preds_train_merge_count = preds_train_re + preds_train_ca
preds_valid_merge_count = preds_valid_re + preds_valid_ca
rmsle_merge_train = sqrt(mean_squared_log_error(y_train,preds_train_merge_count))
rmsle_merge_valid = sqrt(mean_squared_log_error(y_valid,preds_valid_merge_count))
print('(merge) Count train rmsle : %.5f... | Yes | 2 | 11 | Data_Transform | concatenate | 4,205,919 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
4,104 | test['datetime'] = pd.to_datetime(test['datetime'],errors='coerce')
test['date'] = test['datetime'].apply(lambda x: x.date())
test['year'] = test['datetime'].apply(lambda x: x.year)
test['month'] = test['datetime'].apply(lambda x: x.month)
test['weekday'] = test['datetime'].apply(lambda x: x.weekday())
test['hour'] = t... | Yes | 2 | 16 | Data_Transform | data_type_conversions | 4,205,919 | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
4,105 | dummies_month = pd.get_dummies(test['month'], prefix= 'month')
dummies_season = pd.get_dummies(test['season'], prefix= 'season')
dummies_weather = pd.get_dummies(test['weather'], prefix= 'weather')
dummies_year = pd.get_dummies(test['year'], prefix= 'year')
data_test=pd.concat([test,dummies_month,dummies_season,dummie... | Yes | 2 | 20 | Data_Transform | categorify | 4,205,919 | 1 | A | 0 | 0 | 0 | 0 | 0 | 10 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 3 | A |
4,106 | predsTest= rfModel_re.predict(X = dataTest) + rfModel_ca.predict(X = dataTest)
submission=pd.DataFrame({'datetime':datetimecol , 'count':[max(0,x) for x in predsTest]}) | Yes | 2 | 48 | Model_Evaluation | predict_on_test | 4,205,919 | 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"] | 3 | B |
4,107 | submission.to_csv('sampleSubmission.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 |
4,108 | import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
import warnings
warnings.filterwarnings('ignore', category=RuntimeWarning)
import os
print(os.listdir("../input"))' | Yes | 4 | 22 | Environment | import_modules | null | 1 | A | 0 | null | 0 | 0 | 0 | null | invalid_python | 0 | 0 | [] | null | invalid_python | [] | [] | 0 | null |
4,109 | bike_df = pd.read_csv('../input/train.csv')
bike_df.shape | Yes | 2 | 45 | Data_Extraction | load_from_csv | 4,239,857 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 1 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path detected: ../input/train.csv. Consider using configuration files or environment variables.", "fix": "Not specified", "benefits": "Not specified", "location": "Line 5"}] | A | no applicable ML-specific findings | [] | ["Hardcoded file path"] | 4 | A |
4,110 | bike_df.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 |
4,111 | bike_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 |
4,112 | bike_df.drop(['datetime', 'casual', 'registered'], axis=1, inplace=True) | No | 5 | 10 | Data_Transform | drop_column | 4,239,857 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 4 | A |
4,113 | y_target.hist() | No | 5 | 33 | Visualization | distribution | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
4,114 | y_log_transform = np.log1p(y_target)
y_log_transform.hist() | Yes | 3 | 33 | Visualization | distribution | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
4,115 | coef = pd.Series(lr_reg.coef_, index=X_features.columns)
coef_sort = coef.sort_values(ascending=False)
sns.barplot(x=coef_sort.values, y=coef_sort.index) | Yes | 3 | 9 | Data_Transform | sort_values | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
4,116 | X_features_ohe = pd.get_dummies(X_features, columns=['year', 'month', 'hour', 'holiday', 'workingday', 'season', 'weather']) | No | 5 | 20 | Data_Transform | categorify | 4,239,857 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 4 | A |
4,117 | X_features_ohe.head() | No | 5 | 41 | Debug | show_table | 4,239,857 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 4 | A |
4,118 | coef = pd.Series(lr_reg.coef_, index=X_features_ohe.columns)
coef_sort = coef.sort_values(ascending=False)[:15]
sns.barplot(x=coef_sort.values, y=coef_sort.index) | No | 5 | 79 | Visualization | model_coefficients | 4,239,857 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 4 | A |
4,119 | X_train, X_test, y_train, y_test = train_test_split(X_features_ohe, y_target_log, test_size=0.3, random_state=2019)
from sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor
from xgboost import XGBRegressor
from lightgbm import LGBMRegressor
rf_reg = RandomForestRegressor(n_estimators=500)
gbm_reg... | No | 3 | 4 | Model_Train | choose_model_class | 4,239,857 | 2 | B | 4 | 1 | 1 | 0 | 20 | 10 | ok | 7 | 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, Cross-validation not detected=low, Randomness Control Checker=low | [{"type": "Cross Validation Checker", "severity": "low"}, {"type": "Cross-validation not detected", "severity": "low"}, {"type": "Randomness Control Checker", "severity": "low"}] | ["Exception Handling Checker", "Unit Testing Checker", "Verbose Mode Checker"] | 4 | B |
4,120 | submission = pd.read_csv('../input/sampleSubmission.csv') | No | 5 | 45 | Data_Extraction | load_from_csv | 4,239,857 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 1 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path detected: ../input/sampleSubmission.csv. Consider using configuration files or environment variables.", "fix": "Not specified", "benefits": "Not specified", "location": "Line 5"}] | A | no applicable ML-specific findings | [] | ["Hardcoded file path"] | 4 | A |
4,121 | X_test = pd.read_csv('../input/test.csv')
X_test.head() | Yes | 3 | 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 |
4,122 | X_test.drop(['datetime'], axis=1, inplace=True)
X_test.head() | Yes | 2 | 10 | Data_Transform | drop_column | 4,239,857 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 4 | A |
4,123 | X_test_ohe = pd.get_dummies(X_test, columns=['year', 'month', 'hour', 'holiday', 'workingday', 'season', 'weather'])
X_test_ohe.head() | Yes | 2 | 20 | Data_Transform | categorify | 4,239,857 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 4 | A |
4,124 | prediction = lgbm_reg.predict(X_test_ohe) | No | 5 | 48 | Model_Evaluation | predict_on_test | 4,239,857 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | 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"] | 4 | A |
4,125 | submission.to_csv('./My_submission.csv', index=False) | No | 5 | 25 | Data_Export | save_to_csv | 4,239,857 | 1 | A | 0 | 0 | 0 | 0 | 0 | 1 | ok | 1 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Hardcoded file path detected: ./My_submission.csv. Consider using configuration files or environment variables.", "fix": "Not specified", "benefits": "Not specified", "location": "Line 5"}] | A | no applicable ML-specific findings | [] | ["Hardcoded file path"] | 4 | A |
4,126 | import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import os
import datetime
import calendar | Yes | 4 | 22 | Environment | import_modules | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 7 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 0 | A |
4,127 | from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
from sklearn.metrics import mean_squared_error
| 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 |
4,128 | from xgboost import XGBRegressor
from sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor | No | 5 | 22 | Environment | import_modules | 4,702,749 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 6 | A |
4,129 | import warnings
warnings.filterwarnings("ignore") | Yes | 4 | 22 | Environment | import_modules | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
4,130 | train_data = pd.read_csv(path_in + 'train.csv', parse_dates = ['datetime'],
index_col='datetime', infer_datetime_format=True)
test_data = pd.read_csv(path_in + 'test.csv', parse_dates = ['datetime'],
index_col='datetime', infer_datetime_format=True)
samp_subm = pd.read_c... | No | 5 | 45 | Data_Extraction | load_from_csv | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 6 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
4,131 | # Parameters
num_months_per_year = 12
year_list = [2011, 2012] | No | 5 | 77 | Other | define_variables | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
4,132 | month = 5
year = 2011
start_date = datetime.datetime(year, month, 1, 0, 0, 0)
end_date = datetime.datetime(year, month, 19, 23, 0, 0)
# train_data['count_log'] = np.log1p(train_data['count'])
# train_data['rolling_mean'] = train_data['count'].rolling(window = 24).mean()
# train_data['rolling_std'] = train_data['count']... | Yes | 2 | 77 | Other | define_variables | 4,702,749 | 1 | A | 1 | 0 | 0 | 0 | 5 | 4 | ok | 2 | 1 | [{"detector": "general_ml", "framework": "General ML", "name": "Magic number detected: 5", "fix": "Not specified", "benefits": "Not specified", "location": "Line 7"}, {"detector": "general_ml", "framework": "General ML", "name": "Magic number detected: 2011", "fix": "Not specified", "benefits": "Not specified", "locati... | A | no applicable ML-specific findings | [] | ["Magic number"] | 6 | A |
4,134 | train_data = pd.get_dummies(train_data)
test_data = pd.get_dummies(test_data) | No | 5 | 20 | Data_Transform | categorify | 4,702,749 | 1 | A | 0 | 0 | 0 | 0 | 0 | 2 | ok | 0 | 0 | [] | A | no applicable ML-specific findings | [] | [] | 6 | A |
4,135 | scaler = MinMaxScaler()
train_data[scale_features] = scaler.fit_transform(train_data[scale_features])
test_data[scale_features] = scaler.transform(test_data[scale_features]) | Yes | 2 | 4 | Model_Train | choose_model_class | 4,702,749 | 1 | A | 0 | 0 | 0 | 0 | 0 | 3 | ok | 10 | 9 | [{"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": "Pipeline Che... | 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"}] | ["Column Selection Checker", "Exception Handling Checker", "No error handling detected in data processing. Consider adding try-except blocks or validation checks for robustness.", "Unit Testing Checker", "Verbose Mode Checker"] | 6 | D |
4,136 | import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
# Input data files are available in the "../input/" directory.
# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory
import os
print(os.listdir("../inpu... | Yes | 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 8"}] | A | no applicable ML-specific findings | [] | ["Hardcoded file path"] | 0 | A |
4,137 | # Additional Libraries
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.preprocessing import MinMaxScaler
from sklearn.model_selection import train_test_split
from xgboost.sklearn import XGBRegressor
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import accuracy_score
from ker... | No | 5 | 22 | Environment | import_modules | 4,823,309 | 1 | A | 0 | 0 | 0 | 0 | 0 | 14 | 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"] | 7 | A |
4,138 | b"def define_data(data , info=True ,shape = True, percentage =True,describe = True , sample=True , columns = False):\n if columns == True:\n print('\\nColumns of Data...')\n print(data.columns)\n return \n if shape ==True:\n print('Shape of Data is...')\n print(data.shape)\n ... | No | 4 | 40 | Debug | show_table_attributes | null | 1 | A | 0 | 0 | 0 | 0 | 0 | 0 | no_ml_import | 0 | 0 | [] | null | no_ml_import | [] | [] | 0 | null |
4,139 | define_data(train , columns = True)
define_data(test , columns = True) | No | 4 | 40 | Debug | show_table_attributes | 4,823,309 | 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"] | 7 | A |
4,140 | # Divide DateTime Column to various Columns
def add_dates(data , column , suffix='time_' , year = True , month = True , day = False ,dayofweek = True, hour = True , minute = False , second = False , date = False , time = False):
data['add_date_date_time'] = pd.to_datetime(data[column])
if year == True:
... | No | 5 | 16 | Data_Transform | data_type_conversions | 4,823,309 | 1 | A | 0 | 10 | 9 | 0 | 0 | 24 | ok | 3 | 3 | [{"detector": "framework_specific", "framework": "Pandas", "name": "Column Selection Checker", "fix": "Select necessary columns after importing DataFrame.", "benefits": "Clarifies data usage and improves performance.", "location": ""}, {"detector": "framework_specific", "framework": "ScikitLearn", "name": "Dependent Th... | A | no applicable ML-specific findings | [] | ["Column Selection Checker", "Dependent Threshold Checker", "Missing function docstring"] | 7 | A |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.