Oct-20-2022, 11:44 AM
(This post was last modified: Oct-20-2022, 11:51 AM by Led_Zeppelin.)
The following function (method):
I have seen this done on many other programs. In his instance the method/function throws an error as shown:
I have many other functions (in the same place) in the program like this an got no errors. Since it has yet to be called why am I getting an error?
Any help appreciated.
Respectfully,
LZ
def get_cv_heatmap(validation): """ Function to plot heat map of cross validation results """ # refernce: https://stackoverflow.com/questions/48791/how to plot a heat map on pivot table after grid-search train = pd.pivot_table( pd.DataFrame(validation / cv_results_), values="mean_train_score", index="param_max_depth", columns="param_n_estimators", ) test = pd.pivot_table( pd.DataFrame(validation.cv_results_), values="mean_train_score", index="param_max_depth", columns="param_n_estimators", ) # plotting the results fig, (ax1, ax2) = plt.subplots(1, 2, Figsize(17, 5)) sns.heatmap(train, annot=True, cmap="Greens", fmt=" .3g", ax=ax1), set_title( "macro_f1-score (Trainig data)" ) sns.heatmap(test, annot=True, cmap="Greens", fmt=" .3g", ax=ax2), set_title( "macro_f1-score (CV data)" )I place all def's functions at the top of my program. They come right after the import statements at the beginning of the program.
I have seen this done on many other programs. In his instance the method/function throws an error as shown:
NameError Traceback (most recent call last) Input In [564], in <cell line: 9>() 2 """ 3 Function to plot heat map of cross validation results 4 """ 7 # refernce: https://stackoverflow.com/questions/48791/how to plot a heat map on pivot table after grid-search 9 train = pd.pivot_table( ---> 10 pd.DataFrame(validation / cv_results_), 11 values="mean_train_score", 12 index="param_max_depth", 13 columns="param_n_estimators", 14 ) 16 test = pd.pivot_table( 17 pd.DataFrame(validation.cv_results_), 18 values="mean_train_score", 19 index="param_max_depth", 20 columns="param_n_estimators", 21 ) 23 # plotting the results NameError: name 'validation' is not definedIt says that validation which is an argument to the function has not been defined. Well, of course, it is not defined it has not been called yet.
I have many other functions (in the same place) in the program like this an got no errors. Since it has yet to be called why am I getting an error?
Any help appreciated.
Respectfully,
LZ