<jupyter_start><jupyter_text>Preprocessing<jupyter_code>data.head()
np.corrcoef(data['Total'], data['gross income'])
data = data.drop(['gross margin percentage','Branch','Tax 5%','gross income','Date','Time'], axis=1)
data.head()
# getting dummies

coded_data = pd.get_dummies(data)
coded_data
x = coded_data.iloc[:,:-1]    
x.head()
y = data.iloc[:,-1]      #y = rating is the target variable
y
import sklearn
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(x,y,test_size=0.3, random_state=42)
X_train, X_test = X_train.values, X_test.values
X_train.shape
def wt_mat_initializer(coeff_mat):
    length = coeff_mat.shape[1]
    x = np.zeros((length,1))
    return x
wt_mat_initializer(X_test).shape
def gradient_descent(coeff_mat, eta, y, n_iter = 10):
    wt = np.matrix(wt_mat_initializer(coeff_mat))
    A_mat = np.matrix(coeff_mat)
    for i in range(n_iter):
        wt = wt - eta*((A_mat.T*A_mat)*wt - A_mat.T*y)
    return wt
X1 = np.matrix(X_train)
w = np.ones((20,1))
y1 = np.matrix(y_train)
X1.T.shape
y1.shape
X1.T*X1*w
y_train, y_test = y_train.values, y_test.values
y_train, y_test = np.matrix(y_train), np.matrix(y_test)
y_train = y_train.reshape(700,1)
X1.T*X1*w - 0.1*X1.T*y_train
def gradient_descent(coeff_mat, eta, y, n_iter = 10):
    wt = np.matrix(wt_mat_initializer(coeff_mat))
    A_mat = np.matrix(coeff_mat)
    for i in range(n_iter):
        wt = wt - eta*((A_mat.T*A_mat)*wt - A_mat.T*y)
    return wt
X_train, X_test = np.matrix(X_train), np.matrix(X_test)
y_test.shape
y_test = y_test.reshape(300,1)
from sklearn.preprocessing import StandardScaler
X_train1, X_test1 = X_train.copy(), X_test.copy()
Y_train1, Y_test1 = y_train.copy(), y_test.copy()
x = coded_data.iloc[:,:-1] 
y = coded_data.iloc[:,-1]
x = np.matrix(x)
y = np.matrix(y)
x.shape
y.shape
y = y.reshape(1000,1)
y.shape
scaler1 = StandardScaler()
scaler2 = StandardScaler()
scaler1.fit(x)
scaler2.fit(y)
X1 = scaler1.transform(x)
Y1 = scaler2.transform(y)
X1_train, X1_test, y1_train, y1_test = train_test_split(X1, Y1, test_size=0.3, random_state=42)
X1_train, X1_test = np.matrix(X1_train), np.matrix(X1_test)
y1_train, y1_test = np.matrix(y1_train), np.matrix(y1_test)
w = gradient_descent(X1_train,000.1,y1_train, n_iter = 15)
X1_test = X1_test.reshape(300,20)
X1_test*w
x = coded_data.iloc[:,:-1] 
y = coded_data.iloc[:,-1]
x = np.matrix(x)
y = np.matrix(y)
coded_data.head()
coded_data.columns
coded_data.columns = ['Unit price', 'Quantity', 'Total', 'cogs', 'City_Mandalay',
       'City_Naypyitaw', 'City_Yangon', 'Customer type_Member',
       'Customer type_Normal', 'Gender_Female', 'Gender_Male',
       'Product line_Electronic accessories',
       'Product line_Fashion accessories', 'Product line_Food and beverages',
       'Product line_Health and beauty', 'Product line_Home and lifestyle',
       'Product line_Sports and travel', 'Payment_Cash', 'Payment_Credit card',
       'Payment_Ewallet' ,'Rating']
coded_data.head()
data.head()
y = data['Rating']
data1 = data.copy()
data1 = data1.drop("Rating", axis = 1)
data1.head()
coded_data = pd.get_dummies(data1)
coded_data.head()
y.shape
y = np.matrix(y)
y = y.reshape(1000,1)
y
x_t, x_te, y_t, y_te = train_test_split(x,y,test_size = 0.3)
y_t.shape
x_t, x_te = np.matrix(x_t), np.matrix(x_te)
x_t.shape
w = np.linalg.inv(x_t.T*x_t)*x_t.T*y_t
w
np.linalg.norm(y_te-x_te*w)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15517241379310345, 'fraction_numerical': 0.030391583869082407, 'mean_word_length': 5.101604278074866, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '182231', 'license': 'Apache-2.0', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1469, 'n_words': 269, 'path': 'market_sales_eda.ipynb', 'repo_name': 'Abhik-Biswas/EDA-Supermarket-Sales-an-attempt-at-linear-regression', 'size': '3422'}