<jupyter_start><jupyter_text>Gradient descent<jupyter_code>def sigmoid(X,W):
    z=np.dot(X,W)
    return 1/(1+ np.exp(-z))
def loss(h,y):
    return -(y+np.log(h)+(1-y)+np.log(1-h)).mean
def grad_des(X,h,y):
    return np.dot(X.T,(h-y))/y.shape[0]
def update_weightloss(W,lr,grad):
    return W-lr*grad
data=pd.read_csv("Churn_data.csv")
data.head(5)

print(data.shape)

print(data.dtypes)
df=data.copy()
churns=["Yes","No"]
fig ={
    'data':[ {'x': df.loc[(df['Churn']==churn),'MonthlyCharges'],'y': df.loc[(df['Churn']==churn),'tenure'], 'name':churn,'mode':'markers',}for churn in churns]
}
py.offline.iplot(fig)
figs=[]
for churn in churns:
    figs.append(go.Box(y=df.loc[(df["Churn"]==churn),'tenure'],name=churn))
py.offline.iplot(figs)    
df["class"]=df["Churn"].apply(lambda x:1 if x=="Yes" else 0)
X =df[['tenure','MonthlyCharges','SeniorCitizen']].copy()
y=df['class'].copy()
start=time.time()<jupyter_output><empty_output><jupyter_text>iter=10000<jupyter_code>itera=100
print(X[1:10])

theta = np.ones(X.shape[1])

for i in range(itera):
    h=sigmoid(X,theta)
    gradi= grad_des(X,h,y)
    theta = update_weightloss(theta,0.1,gradi)
result = sigmoid(X, theta)
f = pd.DataFrame(np.around(result, decimals=6)).join(y)
f['pred'] = f[0].apply(lambda x : 0 if x < 0.5 else 1)
print("Accuracy (Loss minimization):")
f.loc[f['pred']==f['class']].shape[0] / f.shape[0] * 100

print(theta)<jupyter_output>[-3.19351014  0.43676876  1.14605105]
{'fraction_non_alphanumeric': 0.23379310344827586, 'fraction_numerical': 0.041379310344827586, 'mean_word_length': 6.218905472636816, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '201392', 'license': 'Apache-2.0', 'n_tokens_mistral': 702, 'n_tokens_neox': 653, 'n_words': 88, 'path': 'Logistic Regression/Logistic.ipynb', 'repo_name': 'AJIISc/Machine-Learning', 'size': '1450'}