Ejemplo n.º 1
0
def process_by_ml_name(ml):
    from dataset_loader import DataSetLoader
    from sklearn import cross_validation
    print 'start ', ml
    loader = DataSetLoader()
    x, y = loader.loadData()[DataSetLoader.dataset_name[0]]
    score_lst = []    
    for ml in ml:
        print 'start cross val'
        scores = cross_validation.cross_val_score(ml, x, y, cv=5)
        print 'end cross val'
        score_lst.append(scores.mean())
    return score_lst      
Ejemplo n.º 2
0
 def load_dataset(self):
     loader = DataSetLoader()
     lst = loader.loadData()
     return lst
Ejemplo n.º 3
0
        y_pred = self.predict(X)
        average_score = (accuracy_score(y, y_pred) + f1_score(y, y_pred)) / 2.0
        return average_score
    
    def predict(self, x):
        f_result = open(self.path_test_data, 'w')
        self.__write_data_file(f_result, x, [0] * len(x))
        f_result.close()
        create_predict = libsvm_path + '/svm-predict' + ' {} {} {}'.format(self.path_test_data,
                                                                    self.path_model_result,
                                                                    self.path_result)
        print create_predict
        os.system(create_predict)
        return self.__read_result()

    def get_params(self, deep=True):
        return {"kernel": self.kernel}

    def set_params(self, **parameters):
        for parameter, value in parameters.items():
            setattr(self, parameter, value)
            
if __name__ == '__main__':
    from dataset_loader import DataSetLoader
    from sklearn.cross_validation import train_test_split
    loader = DataSetLoader()
    x, y = loader.loadData()['heart']
    x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.75, random_state=42)
    ml = LibSVMWrapper(kernel=0)
    ml.fit(x_train, y_train)