<jupyter_start><jupyter_text>Simple Regression `y=mx+b`m = weightx = input b = bias<jupyter_code>def simpleRegression(m,x,b):
    y = mx+b
    return y<jupyter_output><empty_output><jupyter_text>Multivariable Regression`f(x,y,z)=w1x+w2y+w3z`w1,w2,w3 = weightsx,y,z = input variables<jupyter_code>def multvariableRegression(x,y,z,w1,w2,w3):
    y = w1*x + w2*y + w3 *z
    return y<jupyter_output><empty_output><jupyter_text>Cost Function`MSE=1N∑i=1n(yi−(mxi+b))2`MSE = Mean squared errorN = total observations1N∑ni=1 = meanyi actual value of observationm = weightx = inputb = bias<jupyter_code>def cost_function(radio, sales, weight, bias):
    companies = len(radio)
    total_error = 0.0
    for i in range(companies):
        total_error += (sales[i] - (weight*radio[i] + bias))**2
    return total_error / companies<jupyter_output><empty_output><jupyter_text>\begin{equation*}f(m,b)   = 1 \sum n p^k (1-p)^{ n-k}\end{equation*}<jupyter_code>def update_weights(radio, sales, weight, bias, learning_rate):
    weight_deriv = 0
    bias_deriv = 0
    companies = len(radio)

    for i in range(companies):
        # Calculate partial derivatives
        # -2x(y - (mx + b))
        weight_deriv += -2*radio[i] * (sales[i] - (weight*radio[i] + bias))

        # -2(y - (mx + b))
        bias_deriv += -2*(sales[i] - (weight*radio[i] + bias))

    # We subtract because the derivatives point in direction of steepest ascent
    weight -= (weight_deriv / companies) * learning_rate
    bias -= (bias_deriv / companies) * learning_rate

    return weight, bias
def train(radio, sales, weight, bias, learning_rate, iters):
    cost_history = []

    for i in range(iters):
        weight,bias = update_weights(radio, sales, weight, bias, learning_rate)

        #Calculate cost for auditing purposes
        cost = cost_function(features, targets, weights)
        cost_history.append(cost)

        # Log Progress
        if i % 10 == 0:
            print "iter: "+str(i) + " cost: "+str(cost)

    return weight, bias, cost_history
normalization
def normalize(features):
    **
    features     -   (200, 3)
    features.T   -   (3, 200)

    We transpose the input matrix, swapping
    cols and rows to make vector math easier
    **

    for feature in features.T:
        fmean = np.mean(feature)
        frange = np.amax(feature) - np.amin(feature)

        #Vector Subtraction
        feature -= fmean

        #Vector Division
        feature /= frange

    return features<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12524930195452733, 'fraction_numerical': 0.015556441962504986, 'mean_word_length': 3.2725724020442932, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '319402', 'license': 'MIT', 'n_tokens_mistral': 904, 'n_tokens_neox': 858, 'n_words': 203, 'path': 'Linear Regression.ipynb', 'repo_name': 'ykpengba/ML-Math-Guide', 'size': '2507'}