Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import pandas as pd
- def calculate_w(x,y):
- col_ones = np.ones((11800,1))
- x_modified = np.hstack((x,col_ones))
- x_pseudo_inversed = np.linalg.pinv(x_modified)
- w = np.matmul(x_pseudo_inversed, y)
- return w
- def predict(w,new_x):
- predicted_value = np.matmul(w,new_x)
- if predicted_value > 0:
- print ("c1")
- else:
- print ("c2")
- def main():
- y = []
- x = []
- dataset = pd.read_csv('mnist_train.csv')
- dataset = dataset.as_matrix()
- for i in range(len(dataset)):
- if dataset[i][0] == 8 or dataset[i][0] == 9:
- y.append(dataset[i][0])
- x.append(dataset[i][1:].tolist())
- x = np.array(x)
- y = np.array(y)
- w = calculate_w(x,y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement