<jupyter_start><jupyter_text>Locally Weighted Regression1) Read and Normalise the Dataset 2) Generate W for every query point!3) No training is involved, directly make predictions using closed form solution we dervied!`(X′WX)inv * X′WY` where X' is X_Transpose4) Find the best value of Tau(Bandwidth Parameter) [Cross Validation]  1. Loading Data<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
%matplotlib inline
dfx = pd.read_csv('../../Datasets/Locally Weighted Regression/weightedX.csv')
dfy = pd.read_csv('../../Datasets/Locally Weighted Regression/weightedY.csv')

X = dfx.values
Y = dfy.values
print(X.shape)
print(Y.shape)
plt.style.use("seaborn")
#Normalisze the Data

u = X.mean()
std = X.std()
X = (X-u)/std

plt.title("Normalized Data")
plt.scatter(X,Y)
plt.show()<jupyter_output><empty_output><jupyter_text>2. Find out W (mxm) diagonal matrix<jupyter_code>#print(type(np.mat(np.eye(5))))

#a*b ==> a,b -->matrices -->Matrix Multicplication
#a*b ==>? a,b -->arrays --->Element Wise 
def getW(query_point,X,tau):
    M = X.shape[0]
    W = np.mat(np.eye(M))
    
    for i in range(M):
        xi = X[i]
        x  = query_point
        W[i,i] =  np.exp(np.dot((xi-x),(xi-x).T)/(-2*tau*tau))
    return W
X = np.mat(X)
Y = np.mat(Y)
M = X.shape[0]

W = getW(-1,X,100)
print(W.shape)
print(W)<jupyter_output>(99, 99)
[[0.99997933 0.         0.         ... 0.         0.         0.        ]
 [0.         0.99999834 0.         ... 0.         0.         0.        ]
 [0.         0.         0.99997917 ... 0.         0.         0.        ]
 ...
 [0.         0.         0.         ... 0.99994881 0.         0.        ]
 [0.         0.         0.         ... 0.         0.99987121 0.        ]
 [0.         0.         0.         ... 0.         0.         0.99975348]]
{'fraction_non_alphanumeric': 0.16279069767441862, 'fraction_numerical': 0.05647840531561462, 'mean_word_length': 1.9526143790849673, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '637401', 'license': 'MIT', 'n_tokens_mistral': 747, 'n_tokens_neox': 687, 'n_words': 167, 'path': '9. Linear Regression/Locally Weighted Regression/.ipynb_checkpoints/LOWESS Implementation-checkpoint.ipynb', 'repo_name': 'sgeek28/Data-Science', 'size': '1806'}