Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

model evaluate function

### got this awsome function from this guy ###
### https://www.kaggle.com/stoicstatic/twitter-sentiment-analysis-for-beginners ###

def model_Evaluate(model):
    
    # Predict values for Test dataset
    y_pred = model.predict(X_test)

    # Print the evaluation metrics for the dataset.
    print(classification_report(y_test, y_pred))
    
    # Compute and plot the Confusion matrix
    cf_matrix = confusion_matrix(y_test, y_pred)

    categories  = ['Negative','Positive']
    group_names = ['True Neg','False Pos', 'False Neg','True Pos']
    group_percentages = ['{0:.2%}'.format(value) for value in cf_matrix.flatten() / np.sum(cf_matrix)]

    labels = [f'{v1}
{v2}' for v1, v2 in zip(group_names,group_percentages)]
    labels = np.asarray(labels).reshape(2,2)

    sns.heatmap(cf_matrix, annot = labels, cmap = 'Blues',fmt = '',
                xticklabels = categories, yticklabels = categories)

    plt.xlabel("Predicted values", fontdict = {'size':14}, labelpad = 10)
    plt.ylabel("Actual values"   , fontdict = {'size':14}, labelpad = 10)
    plt.title ("Confusion Matrix", fontdict = {'size':18}, pad = 20)
Comment

PREVIOUS NEXT
Code Example
Python :: string slices 
Python :: selenium element_to_be_clickable PYTHON 
Python :: how to use drf pagination directly 
Python :: drop-trailing-zeros-from-decimal python 
Python :: convert to datetime object 
Python :: numpy divide except 
Python :: bar plot bokeh 
Python :: strip in python 
Python :: pandas replace nan with none 
Python :: Python from...import statement 
Python :: python replace 
Python :: sum of 1 to even numbers in python 
Python :: python if string contains substring 
Python :: pandas drop duplicate keep last 
Python :: print random integers py 
Python :: for python 
Python :: pd dataframe single column rename 
Python :: mode with group by in python 
Python :: python module install a whl 
Python :: can only concatenate str (not "int") to str 
Python :: Python check if all elements exist in another list 
Python :: how to make variable global in python 
Python :: How To Get Redirection URL In Python 
Python :: remove duplicates from tuple python 
Python :: get list with random numbers python 
Python :: confusion matrix for classification 
Python :: python scope 
Python :: heroku requirements.txt python 
Python :: integral python 
Python :: split list in pd dataframe into rows 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =