Created
March 30, 2016 18:03
-
-
Save pvalienteverde/f54dc3841248f310a38dad7fe42a9279 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def wrapper_logistic_regression_with_L2(l2_penalty, | |
feature_matrix=feature_matrix_train, | |
sentiment=sentiment_train, | |
initial_coefficients=np.zeros(194), | |
step_size=5e-6, max_iter=501): | |
coef=logistic_regression_with_L2(feature_matrix, sentiment, initial_coefficients, step_size, l2_penalty, max_iter) | |
return (l2_penalty,coef) | |
from multiprocessing import Pool | |
# Run | |
n_cores=4 | |
pool = Pool(processes=n_cores) | |
resultados=[pool.map(wrapper_logistic_regression_with_L2, [0,4,10,1e2,1e3,1e5])] | |
# create dataframe with relation l2 - coefficients | |
for l2,coef in resultados[0]: | |
add_coefficients_to_table(coef, 'coefficients [L2={:0.0f}]'.format(l2)) | |
# show result | |
for l2,coef in resultados[0]: | |
train_accurancy=get_classification_accuracy(feature_matrix_train, sentiment_train, coef) | |
validation_accurancy=get_classification_accuracy(feature_matrix_valid, sentiment_valid, coef) | |
print ("L2 penalty = {}".format(l2) ) | |
print ("train accuracy = {}, validation_accuracy = {}".format(train_accurancy, validation_accurancy)) | |
print ("--------------------------------------------------------------------------------") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment