<jupyter_start><jupyter_text>Adding 1's column in the end<jupyter_code>x_train_with_1s = np.column_stack((x_train,np.ones(x_train.shape[0])))
x_train_norma_with_1s = np.column_stack((x_train_norma,np.ones(x_train_norma.shape[0])))
def sigmoid(z):
    return 1/(1+np.exp(-z))
def fit(x,y,lr,epochs):
    m_and_c = np.zeros(x.shape[1])
    for _ in range(epochs):
        m_and_c = train(x,y,m_and_c,lr)
        if _% 50 == 0:
            print(_,": ",cost(x,y,m_and_c))
    return m_and_c
def train(x,y,m_and_c,lr):
    N = y.shape[0]
    diff = np.zeros(x.shape[1])
    for i in range(N):
        h = sigmoid(np.dot(x[i],m_and_c))
        diff += (-1/N)*(y[i] - h)*x[i]
    m_and_c -= lr*diff
    return m_and_c
def cost(x,y,m_and_c):
    N = y.shape[0]
    cost = 0
    for i in range(N):
        h = sigmoid(np.dot(x[i],m_and_c))
        cost += -y[i]*np.log(h) - (1-y[i])*np.log(1- h)
    return cost
m_and_c = fit(x_train_norma_with_1s,y_train,0.01,5000)
def predict(x,m_and_c):
    N = x.shape[0]
    arr =[]
    for i in range(N):
        h = sigmoid(np.dot(x[i],m_and_c))
        if h>= 0.5:
            arr.append(1)
        else:
            arr.append(0)
    return np.array(arr)
y_pred = predict(x_train_norma_with_1s,m_and_c)
def accuracy(y,y_pred):
    N = y.shape[0]
    return (y == y_pred).sum()/N
accuracy(y_pred,y_train)
x_test_norma =  scaler.transform(x_test)<jupyter_output><empty_output><jupyter_text>Adding 1's column in the end<jupyter_code>x_test_norma_with_1s = np.column_stack((x_test_norma,np.ones(x_test_norma.shape[0])))
y_test_pred = predict(x_test_norma_with_1s,m_and_c)
accuracy(y_test_pred,y_test)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1649608669476219, 'fraction_numerical': 0.022275737507525588, 'mean_word_length': 3.591160220994475, 'pattern_counts': {'":': 1, '<': 9, '<?xml version=': 0, '>': 10, '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': '193176', 'license': 'MIT', 'n_tokens_mistral': 795, 'n_tokens_neox': 777, 'n_words': 108, 'path': 'Machine Learning Algorithms/Breast Cancer.ipynb', 'repo_name': 'rohansaini886/100daysofDSA', 'size': '1661'}