Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

sample classification pipeline with hyperparameter tuning

# Setup the pipeline
steps = [('scaler', StandardScaler()),
         ('SVM', SVC())]

pipeline = Pipeline(steps)

# Specify the hyperparameter space
parameters = {'SVM__C':[1, 10, 100],
              'SVM__gamma':[0.1, 0.01]}

…# Predict the labels of the test set: y_pred
y_pred = cv.predict(X_test)

# Compute and print metrics
print("Accuracy: {}".format(cv.score(X_test, y_test)))
print(classification_report(y_test, y_pred))
print("Tuned Model Parameters: {}".format(cv.best_params_))
Comment

sample regression algorithm using pipeline with hyperparameter tuning

# Setup the pipeline steps: steps
steps = [('imputation', Imputer(missing_values='NaN', strategy='mean', axis=0)),
         ('scaler', StandardScaler()),
         ('elasticnet', ElasticNet())]
         
# Create the pipeline: pipeline
pipeline = Pipeline(steps)

# Specify the hyperparameter space
parameters = {'elasticnet__l1_ratio':np.linspace(0,1,30)}
…
# Compute and print the metrics
r2 = gm_cv.score(X_test, y_test)
print("Tuned ElasticNet Alpha: {}".format(gm_cv.best_params_))
print("Tuned ElasticNet R squared: {}".format(r2))
Comment

PREVIOUS NEXT
Code Example
Python :: scan wifi networke micropython 
Python :: how to remove groups/user_permissions from user admin panel in django,how to edit fields shown on user admin panel 
Python :: symbolic variables python 
Python :: CMake Error at pybind11/tools/FindPythonLibsNew.cmake:131 (message): Python config failure: 
Python :: cmap perlin noise python 
Python :: install python modules without pip 
Python :: sns prevent legend 
Python :: debugging python 
Python :: how to make a window with tkinter 
Python :: python get colorscale 
Python :: Python3 boto3 put object to s3 
Python :: pandas recognize type from strings 
Python :: Python __floordiv__ magic method 
Python :: how to iterate through a pandas dataframe 
Python :: triplets in python 
Python :: pip ne marche pas 
Python :: python selenium element not interactable while headless 
Python :: format binary string python 
Python :: hiw ti count the number of a certain value in python 
Python :: python display text in label on new line 
Python :: print f python 
Python :: menor valor lista python 
Python :: python how to locate and fill a specific column null values 
Python :: how to stop python for some time in python 
Python :: how to set a hyperlink in python 
Python :: array slicing python 
Python :: sort decreasing python 
Python :: cursor python 
Python :: no exception message supplied django template 
Python :: re.search 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =