Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

ridge regression alpha values with cross validation score plot

# Import necessary modules
from sklearn.linear_model import Ridge
from sklearn.model_selection import cross_val_score

# Setup the array of alphas and lists to store scores
alpha_space = np.logspace(-4, 0, 50)
ridge_scores = []
ridge_scores_std = []

# Create a ridge regressor: ridge
…    
    # Append the mean of ridge_cv_scores to ridge_scores
    ridge_scores.append(np.mean(ridge_cv_scores))
    
    # Append the std of ridge_cv_scores to ridge_scores_std
    ridge_scores_std.append(np.std(ridge_cv_scores))
def display_plot(cv_scores, cv_scores_std):
    fig = plt.figure()
    ax = fig.add_subplot(1,1,1)
    ax.plot(alpha_space, cv_scores)

    std_error = cv_scores_std / np.sqrt(10)

    ax.fill_between(alpha_space, cv_scores + std_error, cv_scores - std_error, alpha=0.2)
    ax.set_ylabel('CV Score +/- Std Error')
    ax.set_xlabel('Alpha')
    ax.axhline(np.max(cv_scores), linestyle='--', color='.5')
    ax.set_xlim([alpha_space[0], alpha_space[-1]])
    ax.set_xscale('log')
    plt.show()
# Display the plot
display_plot(ridge_scores, ridge_scores_std)
Comment

PREVIOUS NEXT
Code Example
Python :: series multiindex values 
Python :: dynamic id python 
Python :: dict get keys tcl 
Python :: python gambling machine 
Python :: get list values in b/w indexes python 
Python :: rest api save file python 
Python :: web3.eth.personal.newAccount(password, [callback]) 
Python :: visualising data with tsne 
Python :: regular expression for allowing specific numbers of characters python 
Python :: how to update only some fields in django serielizer update method 
Python :: HIDING AND ENCRYPTING PASSWORDS IN PYTHON USING ADVPASS 
Python :: Customizing multiple plots in the same figure 
Python :: Read a string with digits from the input and convert each number to an integer. Create a list in which you should include only odd digits. 
Python :: mystring = "hello" myfloat=float 10 myint=20 
Python :: read the entire images in the dataset 
Python :: Basic 13 Algorithm 
Python :: Combine first and last 3 columns into new dataframe 
Python :: How to assign a value to a dictionary if I need to reference it in the right hand side? 
Python :: python join multiple strings ignore none and empty string 
Python :: fichier python pour brython 
Python :: i type nano in python and o get error 
Python :: spacy vietnamese 
Python :: numpy documentation realpython 
Python :: returns the dataframe with the modified Title column in which the updated groupings are reflected. 
Python :: raspberry pi run a python script using ssh 
Python :: get last item in array python 
Python :: requests-html 
Python :: how to find mean media and mode python 
Python :: numpy annotate with three arrows 
Python :: oscillating fan 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =