Skip to content

Instantly share code, notes, and snippets.

@lazuxd
Created February 7, 2020 17:57
Show Gist options
  • Save lazuxd/898ffa92a1a8c16d76a1ac9327900c96 to your computer and use it in GitHub Desktop.
Save lazuxd/898ffa92a1a8c16d76a1ac9327900c96 to your computer and use it in GitHub Desktop.
Building a Sentiment Classifier using Scikit-Learn
from sklearn.model_selection import RandomizedSearchCV
from scipy.stats import uniform
X_train = X_train_bigram_tf_idf
# Phase 1: loss, learning rate and initial learning rate
clf = SGDClassifier()
distributions = dict(
loss=['hinge', 'log', 'modified_huber', 'squared_hinge', 'perceptron'],
learning_rate=['optimal', 'invscaling', 'adaptive'],
eta0=uniform(loc=1e-7, scale=1e-2)
)
random_search_cv = RandomizedSearchCV(
estimator=clf,
param_distributions=distributions,
cv=5,
n_iter=50
)
random_search_cv.fit(X_train, y_train)
print(f'Best params: {random_search_cv.best_params_}')
print(f'Best score: {random_search_cv.best_score_}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment