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 :: python datediff days 
Python :: sorting list of strings by length python 
Python :: Extract the best model from gridsearch cv 
Python :: pandas to_csv adds unnamed column 
Python :: how can i get the n values by space separated with condition in python 
Python :: auto clicker 
Python :: if you have a list and the user input one of the keys then output its value 
Python :: Extract columns of dataframe to make new dataframe 
Python :: graph node structure 
Python :: change legend facecolor 
Python :: django admin difference between superuser and staff 
Python :: Understand the most appropriate graph to use for your dataset visualization 
Python :: add all columns in django 
Python :: frame work in turtle module 
Python :: Matplotlib scatter plot custom point annotation 
Python :: Donut chart graphing funciton 
Python :: how to read file from terminal in python inside code 
Python :: some problem occurred shows payubiz 
Python :: expecting property name enclosed in double quotes json 
Python :: python 5 minimal values from array 
Python :: shutil cut poython 
Python :: adding attributes and metadata to a dataset using xarray 
Python :: shorten all floats in a list 
Python :: print less than specific number in one row python 
Python :: pandas plot hide object type 
Python :: how to take long input in python 
Python :: how to upload to PyPi with same name 
Python :: python compressed for concatenate string 
Python :: tensorflow loop csdn 
Python :: tkinter app example code 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =