ax.tick_params(labelsize=14) plt.savefig(f'../model/tuning/{NAME}-NB.png', dpi=300) if __name__ == '__main__': base_params = {'alpha': 1.0, 'fit_prior': True, 'class_prior': None} params_NB = dict(base_params) param_grid_ = {'alpha': [0.001, 0.01, 0.1, 1, 10, 100]} features = ["bow", "n-gram", "tf-idf", "n-gram-tf-idf"] results = [] NAME = ":".join(features) for name in features: x = Runner.load_x_train(name) y = Runner.load_y_train() model = ModelMultinomialNB(name, **dict(params_NB)) search = GridSearchCV(model, cv=6, param_grid=param_grid_, return_train_score=True, verbose=10, refit=True) search.fit(x, y) results.append((search, name)) logger.info( f'{name} - bestscore : {search.best_score_} - result :{search.cv_results_["mean_test_score"]}' ) res = pd.DataFrame.from_dict( {
scaler.fit(X) standard_X = scaler.transform(X) # 12次元 -> 6次元 へ落とす. dim = 6 params = { 'n_components': dim, 'random_state': 71, } # 主成分分析 clf = PCA(**params) clf.fit(standard_X) pca = clf.transform(standard_X) pca = pca[:100] labels = Runner.load_y_train() labels = labels[:100] happy = np.empty((0, dim)) angry = np.empty((0, dim)) sad = np.empty((0, dim)) #0=sad, 1=angry, 2=happy, 3=normal for label, x in zip(labels, pca): if label == 0: sad = np.vstack((sad, x)) elif label == 1: angry = np.vstack((angry, x)) elif label == 2: happy = np.vstack((happy, x))