This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
brainwave_df = pd.read_csv('../data/emotions.csv', index_col=False) | |
brainwave_df.head() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import seaborn as sns | |
import matplotlib.pyplot as plt | |
plt.figure(figsize=(12,5)) | |
sns.countplot(x=brainwave_df.label, color='mediumseagreen') | |
plt.title('Emotional sentiment class distribution', fontsize=16) | |
plt.ylabel('Class Counts', fontsize=16) | |
plt.xlabel('Class Label', fontsize=16) | |
plt.xticks(rotation='vertical'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%time | |
from sklearn.pipeline import Pipeline | |
from sklearn.ensemble import RandomForestClassifier | |
from sklearn.model_selection import cross_val_score, train_test_split | |
pl_random_forest = Pipeline(steps=[('random_forest', RandomForestClassifier())]) | |
scores = cross_val_score(pl_random_forest, brainwave_df, label_df, cv=10,scoring='accuracy') | |
print('Accuracy for RandomForest : ', scores.mean()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%time | |
from sklearn.pipeline import Pipeline | |
from sklearn.preprocessing import StandardScaler | |
from sklearn.linear_model import LogisticRegression | |
pl_log_reg = Pipeline(steps=[('scaler',StandardScaler()), | |
('log_reg', LogisticRegression(multi_class='multinomial', solver='saga', max_iter=200))]) | |
scores = cross_val_score(pl_log_reg, brainwave_df, label_df, cv=10,scoring='accuracy') | |
print('Accuracy for Logistic Regression: ', scores.mean()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.decomposition import PCA | |
from sklearn.preprocessing import StandardScaler | |
scaler = StandardScaler() | |
scaled_df = scaler.fit_transform(brainwave_df) | |
pca = PCA(n_components = 20) | |
pca_vectors = pca.fit_transform(scaled_df) | |
for index, var in enumerate(pca.explained_variance_ratio_): | |
print("Explained Variance ratio by Principal Component ", (index+1), " : ", var) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%time | |
from sklearn.pipeline import Pipeline | |
from sklearn.preprocessing import StandardScaler | |
from sklearn.linear_model import LogisticRegression | |
pl_log_reg_pca = Pipeline(steps=[('scaler',StandardScaler()), | |
('pca', PCA(n_components = 2)), | |
('log_reg', LogisticRegression(multi_class='multinomial', solver='saga', max_iter=200))]) | |
scores = cross_val_score(pl_log_reg_pca, brainwave_df, label_df, cv=10,scoring='accuracy') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%time | |
from sklearn.pipeline import Pipeline | |
from sklearn.preprocessing import StandardScaler | |
from sklearn.linear_model import LogisticRegression | |
pl_log_reg_pca_10 = Pipeline(steps=[('scaler',StandardScaler()), | |
('pca', PCA(n_components = 10)), | |
('log_reg', LogisticRegression(multi_class='multinomial', solver='saga', max_iter=200))]) | |
scores = cross_val_score(pl_log_reg_pca_10, brainwave_df, label_df, cv=10,scoring='accuracy') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%time | |
from sklearn.pipeline import Pipeline | |
from sklearn.preprocessing import StandardScaler | |
from sklearn.neural_network import MLPClassifier | |
pl_mlp = Pipeline(steps=[('scaler',StandardScaler()), | |
('mlp_ann', MLPClassifier(hidden_layer_sizes=(1275, 637)))]) | |
scores = cross_val_score(pl_mlp, brainwave_df, label_df, cv=10,scoring='accuracy') | |
print('Accuracy for ANN : ', scores.mean()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%time | |
from sklearn.pipeline import Pipeline | |
from sklearn.preprocessing import StandardScaler | |
from sklearn.svm import LinearSVC | |
pl_svm = Pipeline(steps=[('scaler',StandardScaler()), | |
('pl_svm', LinearSVC())]) | |
scores = cross_val_score(pl_svm, brainwave_df, label_df, cv=10,scoring='accuracy') | |
print('Accuracy for Linear SVM : ', scores.mean()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%time | |
import xgboost as xgb | |
pl_xgb = Pipeline(steps= | |
[('xgboost', xgb.XGBClassifier(objective='multi:softmax'))]) | |
scores = cross_val_score(pl_xgb, brainwave_df, label_df, cv=10) | |
print('Accuracy for XGBoost Classifier : ', scores.mean()) |
OlderNewer