Guest User

Untitled

a guest
Oct 20th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. pipelines = {
  2. 'lasso' : make_pipeline(StandardScaler(), Lasso(random_state=123))
  3. }
  4.  
  5. for key, value in pipelines.items():
  6. print( key, type(value) )
  7.  
  8. # Lasso hyperparameters
  9. lasso_hyperparameters = {
  10. 'lasso__alpha' : [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5, 10]
  11. }
  12.  
  13. hyperparameters = {
  14. 'lasso' : lasso_hyperparameters
  15. }
  16.  
  17. # Create empty dictionary called fitted_models
  18. fitted_models = {}
  19.  
  20. # Create cross-validation object from pipeline and hyperparameters
  21. model = GridSearchCV(pipeline, hyperparameters[name], cv=10, n_jobs=-1)
  22.  
  23. def train(X_train, y_train):
  24. # Fit model on X_train, y_train
  25. model.fit(X_train, y_train)
  26.  
  27. # Store model in fitted_models[name]
  28. fitted_models[name] = model
  29.  
  30. # Print '{name} has been fitted'
  31. print(name, 'has been fitted.')
  32. print ("__________________________________")
  33. print (model.cv_results_)
  34.  
  35.  
  36. for df in pd.read_csv('train_V2.csv', chunksize=100000):
  37. df = df.dropna()
  38. df = pd.get_dummies(df, columns=['matchType'])
  39. df_train = df.drop(['Id', 'groupId', 'matchId'], axis = 1)
  40. y = df_train.winPlacePerc
  41. X = df_train.drop('winPlacePerc', axis=1)
  42. X_train, X_test, y_train, y_test = train_test_split(X, y,
  43. test_size=0.2,
  44. random_state=1234)
  45. X_train = np.asarray(X_train)
  46. X_test = np.asarray(X_test)
  47. y_train = np.asarray(y_train)
  48. y_test = np.asarray(y_test)
  49.  
  50. train(X_train, y_train)
Add Comment
Please, Sign In to add comment