(instruction,
              dataset=None,
              test_size=0.2,
              kernel='linear',
              text=[],
              preprocess=True,
              ca_threshold=None,
              drop=None,
              cross_val_size=0.3,
              degree=3,
              gamma='scale',
              coef0=0.0,
              max_iter=-1,
              random_state=49)
return {
        'id': generate_id(),
        "model": clf,
        'num_classes': num_classes,
        "accuracy": {
            'cross_val_score': cross_val_score(
                clf,
                X_train,
                y_train),
            'accuracy_score': score},
        "target": target,
        "preprocessor": full_pipeline,
        "interpreter": label_mappings,
        'test_data': {
            'X': X_test,
            'y': y_test}}
function to train a support vector machine clustering algorithm
    :param many params: used to hyperparametrize the function.
    :return a dictionary object with all of the information for the algorithm.
function to train a support vector machine clustering algorithm
    :param many params: used to hyperparametrize the function.
    :return a dictionary object with all of the information for the algorithm.
function to train a support vector machine clustering algorithm : param many params : used to hyperparametrize the function . : return a dictionary object with all of the information for the algorithm .
def train_svm(instruction,
              dataset=None,
              test_size=0.2,
              kernel='linear',
              text=[],
              preprocess=True,
              ca_threshold=None,
              drop=None,
              cross_val_size=0.3,
              degree=3,
              gamma='scale',
              coef0=0.0,
              max_iter=-1,
              random_state=49):
    '''
    function to train a support vector machine clustering algorithm
    :param many params: used to hyperparametrize the function.
    :return a dictionary object with all of the information for the algorithm.
    '''

    logger("Reading in dataset")

    dataReader = DataReader(dataset)
    data = dataReader.data_generator()

    if drop is not None:
        data.drop(drop, axis=1, inplace=True)

    logger("Preprocessing data")
    data, y, target, full_pipeline = initial_preprocessor(
        data, instruction, preprocess, ca_threshold, text, test_size=test_size, random_state=random_state)
    logger("->", "Target column found: {}".format(target))

    X_train = data['train']
    y_train = y['train']
    X_test = data['test']
    y_test = y['test']

    # classification_column = get_similar_column(getLabelwithInstruction(instruction), data)
    num_classes = len(np.unique(y))

    # Needed to make a custom label encoder due to train test split changes
    # Can still be inverse transformed, just a bit of extra work
    y_vals = np.unique(pd.concat([y['train'], y['test']], axis=0))
    label_mappings = sklearn.preprocessing.LabelEncoder()
    label_mappings.fit(y_vals)

    y_train = label_mappings.transform(y_train)
    y_test = label_mappings.transform(y_test)

    # Fitting to SVM and storing in the model dictionary
    logger("Fitting Support Vector Machine")
    clf = svm.SVC(
        kernel=kernel,
        degree=degree,
        gamma=gamma,
        coef0=coef0,
        max_iter=max_iter)
    clf.fit(X_train, y_train)

    score = accuracy_score(
        clf.predict(X_test),
        y_test)

    logger("->", "Accuracy found on testing set: {}".format(score))

    logger('->', "Stored model under 'svm' key")
    clearLog()
    return {
        'id': generate_id(),
        "model": clf,
        'num_classes': num_classes,
        "accuracy": {
            'cross_val_score': cross_val_score(
                clf,
                X_train,
                y_train),
            'accuracy_score': score},
        "target": target,
        "preprocessor": full_pipeline,
        "interpreter": label_mappings,
        'test_data': {
            'X': X_test,
            'y': y_test}}
    clearLog()
def train_svm ( instruction , dataset = None , test_size = 0.2 , kernel = 'linear' , text = [ ] , preprocess = True , ca_threshold = None , drop = None , cross_val_size = 0.3 , degree = 3 , gamma = 'scale' , coef0 = 0.0 , max_iter = - 1 , random_state = 49 ) : logger ( "Reading in dataset" ) dataReader = DataReader ( dataset ) data = dataReader . data_generator ( ) if drop is not None : data . drop ( drop , axis = 1 , inplace = True ) logger ( "Preprocessing data" ) data , y , target , full_pipeline = initial_preprocessor ( data , instruction , preprocess , ca_threshold , text , test_size = test_size , random_state = random_state ) logger ( "->" , "Target column found: {}" . format ( target ) ) X_train = data [ 'train' ] y_train = y [ 'train' ] X_test = data [ 'test' ] y_test = y [ 'test' ] # classification_column = get_similar_column(getLabelwithInstruction(instruction), data) num_classes = len ( np . unique ( y ) ) # Needed to make a custom label encoder due to train test split changes # Can still be inverse transformed, just a bit of extra work y_vals = np . unique ( pd . concat ( [ y [ 'train' ] , y [ 'test' ] ] , axis = 0 ) ) label_mappings = sklearn . preprocessing . LabelEncoder ( ) label_mappings . fit ( y_vals ) y_train = label_mappings . transform ( y_train ) y_test = label_mappings . transform ( y_test ) # Fitting to SVM and storing in the model dictionary logger ( "Fitting Support Vector Machine" ) clf = svm . SVC ( kernel = kernel , degree = degree , gamma = gamma , coef0 = coef0 , max_iter = max_iter ) clf . fit ( X_train , y_train ) score = accuracy_score ( clf . predict ( X_test ) , y_test ) logger ( "->" , "Accuracy found on testing set: {}" . format ( score ) ) logger ( '->' , "Stored model under 'svm' key" ) clearLog ( ) return { 'id' : generate_id ( ) , "model" : clf , 'num_classes' : num_classes , "accuracy" : { 'cross_val_score' : cross_val_score ( clf , X_train , y_train ) , 'accuracy_score' : score } , "target" : target , "preprocessor" : full_pipeline , "interpreter" : label_mappings , 'test_data' : { 'X' : X_test , 'y' : y_test } } clearLog ( )