Last active
July 17, 2017 04:01
-
-
Save Torenable/6850aa2d8a379ef6a72cf197e1017ff2 to your computer and use it in GitHub Desktop.
sklearn skeleton
This file contains 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
import sklearn | |
###################### | |
# Estimator | |
###################### | |
# (Analogue to Keras) Initialization all-in-one | |
# bind symbol | |
# define loss function + optimizer | |
# (optional) metrics for output evaluation | |
model = sklearn.svm.SVM() | |
model.fit() # learn | |
model.predict() # use | |
model.score # evaluate results | |
###################### | |
# Ensemble Estimator | |
###################### | |
assembler = sklearn.ensemble.BaggingClassifier( | |
base_estimator = sklearn.neighbors.KNeighborsClassifier() # define an estimator as a weak learner | |
) # Define the framework | |
assembler.fit() # learn the structure | |
assembler.predict() # use | |
assembler.score() # evaluate model performance | |
sklearn.ensemble.partial_dependence.partial_dependence(assembler, target_variables) # evaluate importance of target variables | |
###################### | |
# Transformer | |
###################### | |
processor = sklearn.preprocessing.OneHotEncoder() | |
processor.fit() # learn from samples | |
processor.transform() # use | |
###################### | |
# Pipeline | |
###################### | |
pipe = sklearn.pipeline.Pipeline([ | |
("trans_1", transformer_1), # call transformer_1.transform() | |
("trans_2", transformer_2), # call transformer_2.transform() | |
# ... | |
("estimator", estimator) # call estimator.predict() | |
]) | |
pipe.fit() | |
pipe.predict() | |
###################### | |
# Grid Search | |
###################### | |
candidate_params = {"key": value} | |
grid_search = sklearn.model_selection.GridSearchCV(param_grid = candidate_params) | |
grid_search.fit() # evaluate each combination |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment