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
| X_train, X_test, y_train, y_test,indices_train, indices_test = train_test_split(df_final, df_final_labels,reviews.index, test_size=0.2, random_state=42) | |
| from sklearn.model_selection import cross_val_score | |
| #Classifier 1 - Linear SVM with OnevsRest | |
| from sklearn.svm import LinearSVC | |
| svc = LinearSVC(dual=False, multi_class='ovr', class_weight='balanced') | |
| scores = cross_val_score(svc, X_train, y_train, scoring='f1_weighted', n_jobs=-1, cv=10) | |
| print('Cross-validation f1 score {0:.2f}, std {1:.2f}.'.format(np.mean(scores), np.std(scores) * 100)) | |
| svc.fit(X_train, y_train) | |
| pred = svc.predict(X_test) |
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 | |
| import bokeh | |
| from bokeh.plotting import figure | |
| from bokeh.io import output_file, show, save | |
| from bokeh.models import ColumnDataSource | |
| reviews = pd.read_csv("/home/dipen/Downloads/All_Labelled_Reviews.csv") | |
| reviews['category_id'] = reviews['Category'].factorize()[0] | |
| reviews = reviews[reviews.category_id != 3] | |
| reviews.reset_index(drop = True, inplace = True) |