import numpy as np import pandas as pd #from Output import * import pickle #import xgboost as xgb print('loading data') #Load data x_traindata = pd.read_csv('HOG_features_train_8_16_1.csv', sep=',', header=None).values x_testdata = pd.read_csv('HOG_features_test_8_16_1.csv', sep=',', header=None).values #load classification y_traindata = np.asarray(Input.load_traindata_labels()) print('training classifier') #Train classifier clf = OneVsRestClassifier(SVC(kernel='poly', probability=True)) clf.fit(x_traindata, y_traindata) # now you can save it to a file with open('classifierpolytraindata_HOG_8_16_1.pkl', 'wb') as f: pickle.dump(clf, f) ## and later you can load it with open('classifierpolytraindata_HOG_8_16_1.pkl', 'rb') as f: clf = pickle.load(f) #Make predictions
import pandas as pd import time from sklearn.ensemble import RandomForestClassifier from IO import Input from IO import Output start_time = time.time() # load train data df_traindata_caf = Input.load_traindata_caffefeatures() df_traindata_lab = Input.load_traindata_labels() # Load test data df_testdata_caf = Input.load_testdata_caffefeatures() print("--- load data: %s seconds ---" % round((time.time() - start_time), 2)) start_time = time.time() x_train = df_traindata_caf y_train = df_traindata_lab x_test = df_testdata_caf # Train model rf = RandomForestClassifier(n_estimators=500) rf.fit(x_train, y_train) print("--- train model: %s seconds ---" % round((time.time() - start_time), 2)) start_time = time.time() # Predict