Skip to content

Instantly share code, notes, and snippets.

View DipenChawla's full-sized avatar

Dipen Chawla DipenChawla

View GitHub Profile
@DipenChawla
DipenChawla / classifiers.py
Created June 4, 2019 17:47
ML Classifiers for DrugNeuroAnalytics
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)
@DipenChawla
DipenChawla / bokehapp.py
Created June 4, 2019 10:40
Bokeh App Visualisation for DrugNeuroAnalytics
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)