Created
February 1, 2018 15:59
-
-
Save saisumit/25998f30768f23a0a46fe6862e067cca to your computer and use it in GitHub Desktop.
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
| # prediction=clf.predict(test_features) | |
| import pandas as pd | |
| import numpy as np | |
| import tensorflow as tf | |
| from sklearn.cross_validation import train_test_split | |
| import matplotlib.pyplot as plt | |
| from sklearn.utils import shuffle | |
| from sklearn.metrics import confusion_matrix | |
| import matplotlib.gridspec as gridspec | |
| from sklearn.preprocessing import StandardScaler | |
| from sklearn.manifold import TSNE | |
| from sklearn.metrics import accuracy_score | |
| from sklearn.metrics import f1_score | |
| from sklearn.metrics import roc_auc_score | |
| import numpy as np | |
| import pandas as pd | |
| import os | |
| import re | |
| from sklearn.utils import shuffle | |
| import tensorflow as tf | |
| import tflearn | |
| from tflearn.layers.conv import conv_2d, max_pool_2d | |
| from tflearn.layers.core import input_data, dropout, fully_connected | |
| from tflearn.layers.estimator import regression | |
| from tflearn.layers.normalization import local_response_normalization | |
| from sklearn.preprocessing import LabelEncoder | |
| from sklearn.preprocessing import LabelEncoder,OneHotEncoder | |
| import random | |
| import pickle | |
| labelencoder = LabelEncoder() | |
| onehot_encoder = OneHotEncoder(sparse=False) | |
| VALIDATION_TEST_SET_FILE_LIST = '../validation_feature_batch/audio_7_1080' # ye path change hoga | |
| TRAINING_FILE_LIST = '../train_audio/' # ye path change hoga | |
| TRAINING_FEATURE_BATCH_PATH = '../train_feature_batch/' # ye path change hoga | |
| TRAIN_PATH = '/output/audio_classifier/train/' | |
| def one_hot_encode(label_batch): | |
| label_batch = np.asarray(label_batch) | |
| integer_encoded = label_batch.reshape(len(label_batch), 1) | |
| onehot_encoded = onehot_encoder.fit_transform(integer_encoded) | |
| label_batch = onehot_encoded | |
| return label_batch | |
| val_feature = [] | |
| val_labels = [] | |
| val_feature = pickle.load( open( VALIDATION_TEST_SET_FILE_LIST+ '_feature_batch', "rb" ) ) | |
| val_labels = pickle.load( open(VALIDATION_TEST_SET_FILE_LIST + '_label_batch', "rb" ) ) | |
| val_labels = one_hot_encode(val_labels) | |
| print("training accuracy: "+str(metrics.r2_score(target,pred))) | |
| def train_sai_net(): | |
| features = [] | |
| target = [] | |
| prev_best = 0 | |
| SUBJECT_LIST = [os.path.splitext(subject)[0] for subject in os.listdir(TRAINING_FILE_LIST)] | |
| # SUBJECT_LIST = ['audio_2_750','audio_3_1368','audio_4_712','audio_5_1020','audio_6_300'] | |
| for subject in SUBJECT_LIST: | |
| print(subject) | |
| feature_batch = pickle.load( open(TRAINING_FEATURE_BATCH_PATH + subject +'_feature_batch' , "rb" ) ) | |
| label_batch = pickle.load( open(TRAINING_FEATURE_BATCH_PATH + subject+ '_label_batch', "rb" ) ) | |
| label_batch = one_hot_encode(label_batch) | |
| features.append(feature_batch) | |
| target.append(label_batch) | |
| features.append(val_feature) | |
| label_batch.append(val_labels) | |
| clf = XGBRegressor(reg_lambda=1,learning_rate=0.03,n_estimators=7500,max_depth=55,min_child_weight=0.7,gamma=0,subsample=0.8,colsample_bytree=0.8, objective= 'binary:logistic' ,scale_pos_weight=1,seed=27) | |
| clf=clf.fit(features,label_batch,eval_metric='auc') | |
| pred=clf.predict(features) | |
| print("training accuracy: "+str(metrics.r2_score(target,pred))) | |
| label_predict = clf.predict_proba(features) | |
| clf.save_model('best_model/0001.model') | |
| train_sai_net() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment