Skip to content

Instantly share code, notes, and snippets.

@lazuxd
Last active February 7, 2020 18:15
Show Gist options
  • Save lazuxd/5f2cd996f9895f9ca24cffbe52e335a2 to your computer and use it in GitHub Desktop.
Save lazuxd/5f2cd996f9895f9ca24cffbe52e335a2 to your computer and use it in GitHub Desktop.
Building a Sentiment Classifier using Scikit-Learn
# Phase 2: penalty and alpha
clf = SGDClassifier()
distributions = dict(
penalty=['l1', 'l2', 'elasticnet'],
alpha=uniform(loc=1e-6, scale=1e-4)
)
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