I needed to save all parameter combinations and corresponding accuracies in a kind of pandas dataframe.
I hope, I am clear, Please point out , If I m doing any mistake.
Example code is:
from sklearn.grid_search import GridSearchCV
import sklearn
from sklearn.ensemble import RandomForestClassifier
X_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split(iris.data, iris.target, test_size=0.3, random_state=0)
rfc = RandomForestClassifier(n_jobs=-1,max_features= 'sqrt' ,n_estimators=50, oob_score = True)
param_grid = {
'n_estimators': [200, 700],
'max_features': ['auto', 'sqrt', 'log2'],
'criterion' : ['gini', 'entropy']
}
CV_rfc = GridSearchCV(estimator=rfc, param_grid=param_grid, cv= 5)
CV_rfc.fit(X_train, y_train)
CV_rfc.grid_scores_
I am using Grid Search CV in sklearn, to get the best parameters. But, my concern is, Is there any way, I can store all the different parametric combinations and the corresponding accuracies in a pandas dataframe that I can save in a CSV file for later on purposes.
[mean: 0.94286, std: 0.05344, params: {'criterion': 'gini', 'max_features': 'auto', 'n_estimators': 200},
mean: 0.94286, std: 0.05344, params: {'criterion': 'gini', 'max_features': 'auto', 'n_estimators': 700},
mean: 0.94286, std: 0.05344, params: {'criterion': 'gini', 'max_features': 'sqrt', 'n_estimators': 200},
mean: 0.94286, std: 0.05344, params: {'criterion': 'gini', 'max_features': 'sqrt', 'n_estimators': 700},
mean: 0.94286, std: 0.05344, params: {'criterion': 'gini', 'max_features': 'log2', 'n_estimators': 200},
mean: 0.94286, std: 0.05344, params: {'criterion': 'gini', 'max_features': 'log2', 'n_estimators': 700},
mean: 0.94286, std: 0.05344, params: {'criterion': 'entropy', 'max_features': 'auto', 'n_estimators': 200},
mean: 0.94286, std: 0.05344, params: {'criterion': 'entropy', 'max_features': 'auto', 'n_estimators': 700},
mean: 0.94286, std: 0.05344, params: {'criterion': 'entropy', 'max_features': 'sqrt', 'n_estimators': 200},
mean: 0.94286, std: 0.05344, params: {'criterion': 'entropy', 'max_features': 'sqrt', 'n_estimators': 700},
mean: 0.94286, std: 0.05344, params: {'criterion': 'entropy', 'max_features': 'log2', 'n_estimators': 200},
mean: 0.94286, std: 0.05344, params: {'criterion': 'entropy', 'max_features': 'log2', 'n_estimators': 700}]
So, I have a list of these values, I want a dataframe of it, to save in a csv file.
len(CV_rfc.grid_scores_)
12