application_vnd.jupyter.stderr_output_3.png text_plain_output_2.png text_plain_output_1.png
from numpy import linspace

from pandas import read_csv

from sklearn.compose import make_column_transformer

from sklearn.impute import SimpleImputer

from sklearn.linear_model import LogisticRegression, SGDClassifier

from sklearn.metrics import accuracy_score

from sklearn.model_selection import train_test_split, RandomizedSearchCV

from sklearn.pipeline import make_pipeline, make_union

from sklearn.preprocessing import FunctionTransformer, OneHotEncoder, StandardScaler

from pandas import read_csv
train = read_csv('/kaggle/input/telecom-churn-case-study-hackathon-gc1/train.csv')
train = train.drop(['id', 'circle_id'], axis=1)
test = read_csv('/kaggle/input/telecom-churn-case-study-hackathon-gc1/test.csv')
sample = read_csv('/kaggle/input/telecom-churn-case-study-hackathon-gc1/sample.csv')
metadata = read_csv('/kaggle/input/telecom-churn-case-study-hackathon-gc1/data_dictionary.csv')

mask = train.isna().sum() / len(train) > 0.5
train = train.loc[:, ~mask]

from sklearn.impute import SimpleImputer
from sklearn.compose import make_column_transformer
from sklearn.pipeline import make_pipeline, make_union
from sklearn.preprocessing import FunctionTransformer, OneHotEncoder, StandardScaler
from sklearn.model_selection import train_test_split, RandomizedSearchCV
from sklearn.linear_model import LogisticRegression, SGDClassifier
from sklearn.ensemble import BaggingClassifier
from sklearn.metrics import accuracy_score
from numpy import linspace
X_train, y_train = (train.drop('churn_probability', axis=1), train['churn_probability'])
X_train, X_test, y_train, y_test = train_test_split(X_train, y_train, test_size=0.1, stratify=y_train)
impute_onehot = make_column_transformer((SimpleImputer(), X_train.select_dtypes(include='number').columns), (OneHotEncoder(handle_unknown='ignore'), X_train.select_dtypes(include='object').columns))
base = make_pipeline(impute_onehot, StandardScaler(), SGDClassifier(n_jobs=-1))
base.fit(X_train, y_train)
accuracy_score(y_test, base.predict(X_test))
model = make_pipeline(impute_onehot, StandardScaler(), SGDClassifier(class_weight='balanced'))
model = RandomizedSearchCV(model, {'sgdclassifier__alpha': linspace(0.0001, 2), 'sgdclassifier__loss': ['hinge', 'log', 'modified_huber', 'squared_hinge', 'perceptron']}, cv=10, n_iter=30, verbose=True, scoting='accuracy', n_jobs=-1)
model.fit(X_train, y_train)
accuracy_score(y_test, model.predict(X_test))