Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
master_project/model.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
32 lines (23 sloc)
927 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Importing the libraries | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import pandas as pd | |
import pickle | |
from sklearn.model_selection import train_test_split | |
from sklearn import ensemble | |
from imblearn.over_sampling import SMOTE | |
dataset = pd.read_csv('train_df.csv') | |
X = dataset.iloc[:, :7] | |
y = dataset.iloc[:, -1] | |
smote = SMOTE(sampling_strategy = 'not majority') | |
x_sm, y_sm = smote.fit_resample(X, y) | |
X_train, X_test, y_train, y_test = train_test_split(x_sm, y_sm, test_size=0.2, random_state=0) | |
# Fit or Train the Model | |
params = {'n_estimators': 1000, 'max_depth': 4, "min_samples_split": 5, 'learning_rate':0.01} | |
lr_model = ensemble.GradientBoostingClassifier(**params) | |
lr_model.fit(X_train,y_train.values.ravel()) | |
# Saving model to disk | |
pickle.dump(lr_model, open('model.pkl','wb')) | |
# Loading model to compare the results | |
model = pickle.load(open('model.pkl','rb')) | |
print(model.predict([[33,3, 3,1,3,3,3]])) |