SHARE
TWEET

Untitled

a guest Jun 18th, 2019 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def perform_randomized_search(features, target):
  2.   '''Performs a randomized search on Logistic regression'''
  3.   import numpy as np
  4.   from sklearn.linear_model import LogisticRegression
  5.   from sklearn.model_selection import RandomizedSearchCV
  6.   from scipy.stats import uniform
  7.   # Create logistic regression
  8.   model = LogisticRegression()
  9.   # Create range of candidate penalty values
  10.   penalty = ['l1', 'l2']
  11.   # Create distribution of candidate regularization values
  12.   C = uniform(loc=0, scale=4)
  13.   # Create hyperparameter options
  14.   hyperparameters = dict(C=C, penalty=penalty)
  15.  
  16.   # Create randomized search
  17.   randomizedsearch = RandomizedSearchCV(model, hyperparameters, random_state=1, n_iter=100, cv=5, verbose=1)
  18.   # Fit randomized search
  19.   best_model = randomizedsearch.fit(features, target)
  20.   return best_model
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top