TransWikia.com

Combine results from multiple models

Data Science Asked by dinesh patro on March 13, 2021

I am using chunks of 100000 rows at a time from the CSV file to train the a simple LASSO model.

How do i combine all of these models trained from these different chunks? I would like to use all these trained models for prediction

I am familiar with DASK and other alternatives but i would like to use Pandas.

pipelines = {
    'lasso' : make_pipeline(StandardScaler(), Lasso(random_state=123))
}

for key, value in pipelines.items():
    print( key, type(value) )

# Lasso hyperparameters
lasso_hyperparameters = { 
    'lasso__alpha' : [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5, 10] 
}

hyperparameters = {
'lasso' : lasso_hyperparameters
}

# Create empty dictionary called fitted_models
fitted_models = {}

# Create cross-validation object from pipeline and hyperparameters
model = GridSearchCV(pipeline, hyperparameters[name], cv=10, n_jobs=-1)

def train(X_train, y_train):  
    # Fit model on X_train, y_train
    model.fit(X_train, y_train)

    # Store model in fitted_models[name] 
    fitted_models[name] = model

    # Print '{name} has been fitted'
    print(name, 'has been fitted.')
    print ("__________________________________")
    print (model.cv_results_)


for df in pd.read_csv('train_V2.csv', chunksize=100000):
    df = df.dropna()
    df = pd.get_dummies(df, columns=['matchType'])
    df_train = df.drop(['Id', 'groupId', 'matchId'], axis = 1)
    y = df_train.winPlacePerc       
    X = df_train.drop('winPlacePerc', axis=1)
    X_train, X_test, y_train, y_test = train_test_split(X, y, 
                                                    test_size=0.2, 
                                                    random_state=1234)
    X_train = np.asarray(X_train)
    X_test = np.asarray(X_test)
    y_train = np.asarray(y_train)
    y_test = np.asarray(y_test)

    train(X_train, y_train)

One Answer

What you are looking for is called "stochastic optimization". You don't need to fit separate models and then combine them.

Answered by anymous.asker on March 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP