<jupyter_start><jupyter_text>Linear regression with multiple variables using ex1data2.txt  1.1 Feature Normalization  Standardization $X\sim(0,1)$:$X_{new}=\frac{X-mean(X)}{std(X)}$Normalization $X\in{(0,1)}$:$X_{new}=\frac{X-min(X)}{max(X)-min(X)}$<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

%matplotlib inline
%config InlineBackend.figure_format='svg'
data=pd.read_csv("ex1data2.txt",names=["size of the house","number of the bedrooms","price"])
print(data.shape)
data.head()
X=data.iloc[:,:2]
y=data.iloc[:,-1:]
print("shape of X: {}".format(X.shape))
print("shape of y: {}".format(y.shape))

def feature_Standardization(X):
    return (X-np.mean(X))/np.std(X)
X=feature_Standardization(X)
y=feature_Standardization(y)<jupyter_output>shape of X: (47, 2)
shape of y: (47, 1)<jupyter_text>1.2 Gradient descent<jupyter_code>#Add intercept term
X.insert(0,"Ones",1)
def compute_cost(theta,X,y):
    m=X.shape[0]
    inner=np.sum(np.power(X*theta.T-y,2))
    
    return (1/(2*m))*inner
def batch_gradient_descent(theta,X,y,iterations,alpha):
    """
    :param X: matrix
    :param y: matrix
    :param theta: matrix
    """
    parameters=int(theta.ravel().shape[1])
    temp=np.mat(np.zeros(theta.shape))
    cost=np.zeros(iterations)
    m=X.shape[0]
    
    for i in range(iterations):
        error=X*theta.T-y
        for j in range(parameters):
            term=np.multiply(error,X[:,j])
            temp[0,j]=temp[0,j]-(alpha/m)*np.sum(term)
            
        theta=temp
        cost[i]=compute_cost(theta,X,y)
    return theta,cost
X=np.mat(X.values)
y=np.mat(y.values)
theta=np.mat(np.zeros(X.shape[1]))
alpha=0.01
iterations=1500
g,cost=batch_gradient_descent(theta,X,y,iterations,alpha)
print("cost value :{}".format(compute_cost(g,X,theta)))
plt.figure(figsize=(12,8))

iterations=np.linspace(0,1500,1500)
plt.plot(iterations,cost)
plt.xlabel("iteraions")
plt.ylabel("epoch")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1823739174732552, 'fraction_numerical': 0.02547121752419766, 'mean_word_length': 5.061728395061729, 'pattern_counts': {'":': 0, '<': 8, '<?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': '58904', 'license': 'MIT', 'n_tokens_mistral': 805, 'n_tokens_neox': 774, 'n_words': 117, 'path': 'ML/ML_by_Standford_AndrewNg/Labs/W1-assignment-Linear Regression/ex2-Linear Regression With Multiple Variables.ipynb', 'repo_name': 'Bingogogo8/skills', 'size': '1963'}