<jupyter_start><jupyter_text>Import Basics and Read Data<jupyter_code>import pandas as pd
import numpy as np

data = pd.read_csv("bug_prediction_data.csv")<jupyter_output><empty_output><jupyter_text>Prepare Data<jupyter_code>list(data.columns.values)
training_set = data.sample(frac=0.8, random_state = 1)
test_set = data.loc[~data.index.isin(training_set.index)]

data_columns = ['linesAddedUntil.', 'maxLinesAddedUntil.', 'avgLinesAddedUntil.', 'linesRemovedUntil.', 'maxLinesRemovedUntil.',
                'avgLinesRemovedUntil.', 'codeChurnUntil.', 'maxCodeChurnUntil.', 'avgCodeChurnUntil.', 'ageWithRespectTo.',
                'weightedAgeWithRespectTo.', 'CvsEntropy', 'CvsWEntropy', 'CvsLinEntropy', 'CvsLogEntropy', 'CvsExpEntropy']


training_data = training_set.as_matrix(columns = data_columns)
nan_locs = np.isnan(training_data)
training_data[nan_locs] = 0

training_target = training_set['numberOfBugsFoundUntil.'].values
nan_locs = np.isnan(training_target)
training_target[nan_locs] = 0

test_data = test_set.as_matrix(columns = data_columns)
nan_locs = np.isnan(test_data)
test_data[nan_locs] = 0

test_target = test_set['numberOfBugsFoundUntil.'].values
nan_locs = np.isnan(test_target)
test_target[nan_locs] = 0<jupyter_output><empty_output><jupyter_text>Regression  Multi-layer Perceptron<jupyter_code>from sklearn.neural_network import MLPRegressor
reg = MLPRegressor()
reg.fit(training_data, training_target)

print('R squared: ' + str(reg.score(training_data, training_target)))<jupyter_output>R squared: 0.640988326203<jupyter_text>Support vector Regression<jupyter_code>from sklearn.svm import SVR
svr = SVR()
svr.fit(training_data, training_target)

print('R squared: ' + str(svr.score(training_data, training_target)))<jupyter_output>R squared: -0.0494088797154<jupyter_text>Kernel Ridge Regression<jupyter_code>from sklearn.kernel_ridge import KernelRidge
kr = KernelRidge()
kr.fit(training_data, training_target)

print('R squared: ' + str(kr.score(training_data, training_target)))<jupyter_output>R squared: 0.890861672907<jupyter_text>Decision Tree Regression<jupyter_code>from sklearn.tree import DecisionTreeRegressor
dt = DecisionTreeRegressor()
dt.fit(training_data, training_target)

print('R squared: ' + str(dt.score(training_data, training_target)))<jupyter_output>R squared: 1.0<jupyter_text>Random Forest Regression<jupyter_code>from sklearn.ensemble import RandomForestRegressor
rf = RandomForestRegressor(n_estimators = 100)
rf.fit(training_data, training_target)

print('R squared: ' + str(rf.score(training_data, training_target)))<jupyter_output>R squared: 0.979818694663<jupyter_text>Gradient Boosting Regression<jupyter_code>from sklearn.ensemble import GradientBoostingRegressor
gb = GradientBoostingRegressor()
gb.fit(training_data, training_target)

print('R squared: ' + str(gb.score(training_data, training_target)))<jupyter_output>R squared: 0.989124091456<jupyter_text>Polynomial Regression<jupyter_code>from sklearn.preprocessing import PolynomialFeatures
from sklearn.linear_model import LinearRegression
from sklearn.pipeline import Pipeline

pr = Pipeline([('poly', PolynomialFeatures(degree = 3)),
              ('linear', LinearRegression(fit_intercept = False))])

pr.fit(training_data, training_target)

print('R squared: ' + str(pr.score(training_data, training_target)))<jupyter_output>R squared: 0.997819140862<jupyter_text>Lasso Regression<jupyter_code>from sklearn.linear_model import Lasso
lm = Lasso()
lm.fit(training_data, training_target)

print('R squared: ' + str(lm.score(training_data, training_target)))<jupyter_output>R squared: 0.8874959113<jupyter_text>Elastic Net<jupyter_code>from sklearn.linear_model import ElasticNet
en = ElasticNet()
en.fit(training_data, training_target)

print('R squared: ' + str(en.score(training_data, training_target)))<jupyter_output>R squared: 0.887693033752<jupyter_text>Least Angle Regression<jupyter_code>from sklearn.linear_model import LassoLars
ll = LassoLars()
ll.fit(training_data, training_target)

print('R squared: ' + str(ll.score(training_data, training_target)))<jupyter_output>R squared: 0.0<jupyter_text>Bayesian Regression<jupyter_code>from sklearn.linear_model import BayesianRidge
br = BayesianRidge()
br.fit(training_data, training_target)

print('R squared: ' + str(br.score(training_data, training_target)))<jupyter_output>R squared: 0.887922796977<jupyter_text>Stochastic Gradient Descent<jupyter_code>from sklearn.linear_model import SGDRegressor
sgd = SGDRegressor()
sgd.fit(training_data, training_target)

print('R squared: ' + str(sgd.score(training_data, training_target)))<jupyter_output>R squared: -3.769246513e+29
{'fraction_non_alphanumeric': 0.11206526406182911, 'fraction_numerical': 0.030699871189351653, 'mean_word_length': 9.04094827586207, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '654235', 'license': 'MIT', 'n_tokens_mistral': 1783, 'n_tokens_neox': 1647, 'n_words': 254, 'path': 'Bug_Prediction_Regression.ipynb', 'repo_name': 'harishsiravuri/Bug_Prediction', 'size': '4658'}