Given bank marketing data I trained a model using decision tree and random forest classifiers, now trying to predict the target variable of Y but am unsure how to do it. Do I load both trained data and test data in the trained model, and implement?
train_data = pd.read_csv('train_cleaned1.csv')
test_data = pd.read_csv('test_cleaned1.csv')
X = train_data.drop('Final_Y_1', axis=1)
y = train_data.Final_Y_1
X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size=0.3, random_state=42)
pipelines = {'rf' : make_pipeline(StandardScaler(),
RandomForestClassifier(random_state=42, class_weight='balanced'))}
rf_hyperparameters = {'randomforestclassifier__n_estimators': [100,
200],
'randomforestclassifier__max_features': ['auto',
'sqrt', 0.33] }
hyperparameters = {'rf' : rf_hyperparameters}
fitted_rf_model = {}
for name, pipeline in pipelines.items():
rf_model = GridSearchCV(pipeline, hyperparameters[name], cv=10,
n_jobs=-1)
rf_model.fit(X_train, y_train)
fitted_rf_model[name] = rf_model
print(name, 'has been fitted.')
for name, model in fitted_rf_model.items():
print(name, model.best_score_ )
I still get a good score but Im not sure if the test data has been implemenented and if so how do i do it? rf has been fitted. rf 0.9004104109304379
Aucun commentaire:
Enregistrer un commentaire