Classification algorithm [on hold]











up vote
-1
down vote

favorite












I just wrote a classification algorithm and would like to get some feedback if possible. Is this the right way to implement this code or it should be done any other way?



import numpy as np
import math
import matplotlib.pyplot as plt

data = np.array([[1,0],[2,0],[3,0],[4,1],[5,1],[6,1],[7,1]])

#Adding a column of ones to our x matrix
ones = np.ones((len(data),1))
x = np.concatenate((ones, data[:,0].reshape(-1,1)), axis=1)

#Making our y vector
y = data[:,1].reshape(-1,1)

#choosing random Theta
theta = np.zeros((2,1))

#Sigmoid Function

def g(n):
return 1 / ((1 + (math.e**(-n))) + 0.000000001)
#Settings
m = 1/(len(x))
alpha = 2
iteration = 1000
while iteration > 0:
iteration -= 1
z = x @ theta
#cost function
h = g(z).reshape((-1,1))
part1 = -y.T @ np.log(h)
part2 = ((1 - y).T) @ (np.log(1-h))
j = m * (part1 - part2)
print(j)
#Gradient descent
inner = h - y
outer = x.T @ inner
dj = (alpha/m) * outer
theta = theta - dj
print(theta)









share|improve this question









New contributor




wassim khadim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as unclear what you're asking by Graipher, Toby Speight, Sᴀᴍ Onᴇᴌᴀ, t3chb0t, Edward 5 hours ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.











  • 1




    Could you tell us something more about your code? It could be an interesting question but without any description it's likely to get closed.
    – t3chb0t
    11 hours ago

















up vote
-1
down vote

favorite












I just wrote a classification algorithm and would like to get some feedback if possible. Is this the right way to implement this code or it should be done any other way?



import numpy as np
import math
import matplotlib.pyplot as plt

data = np.array([[1,0],[2,0],[3,0],[4,1],[5,1],[6,1],[7,1]])

#Adding a column of ones to our x matrix
ones = np.ones((len(data),1))
x = np.concatenate((ones, data[:,0].reshape(-1,1)), axis=1)

#Making our y vector
y = data[:,1].reshape(-1,1)

#choosing random Theta
theta = np.zeros((2,1))

#Sigmoid Function

def g(n):
return 1 / ((1 + (math.e**(-n))) + 0.000000001)
#Settings
m = 1/(len(x))
alpha = 2
iteration = 1000
while iteration > 0:
iteration -= 1
z = x @ theta
#cost function
h = g(z).reshape((-1,1))
part1 = -y.T @ np.log(h)
part2 = ((1 - y).T) @ (np.log(1-h))
j = m * (part1 - part2)
print(j)
#Gradient descent
inner = h - y
outer = x.T @ inner
dj = (alpha/m) * outer
theta = theta - dj
print(theta)









share|improve this question









New contributor




wassim khadim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as unclear what you're asking by Graipher, Toby Speight, Sᴀᴍ Onᴇᴌᴀ, t3chb0t, Edward 5 hours ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.











  • 1




    Could you tell us something more about your code? It could be an interesting question but without any description it's likely to get closed.
    – t3chb0t
    11 hours ago















up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I just wrote a classification algorithm and would like to get some feedback if possible. Is this the right way to implement this code or it should be done any other way?



import numpy as np
import math
import matplotlib.pyplot as plt

data = np.array([[1,0],[2,0],[3,0],[4,1],[5,1],[6,1],[7,1]])

#Adding a column of ones to our x matrix
ones = np.ones((len(data),1))
x = np.concatenate((ones, data[:,0].reshape(-1,1)), axis=1)

#Making our y vector
y = data[:,1].reshape(-1,1)

#choosing random Theta
theta = np.zeros((2,1))

#Sigmoid Function

def g(n):
return 1 / ((1 + (math.e**(-n))) + 0.000000001)
#Settings
m = 1/(len(x))
alpha = 2
iteration = 1000
while iteration > 0:
iteration -= 1
z = x @ theta
#cost function
h = g(z).reshape((-1,1))
part1 = -y.T @ np.log(h)
part2 = ((1 - y).T) @ (np.log(1-h))
j = m * (part1 - part2)
print(j)
#Gradient descent
inner = h - y
outer = x.T @ inner
dj = (alpha/m) * outer
theta = theta - dj
print(theta)









share|improve this question









New contributor




wassim khadim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I just wrote a classification algorithm and would like to get some feedback if possible. Is this the right way to implement this code or it should be done any other way?



import numpy as np
import math
import matplotlib.pyplot as plt

data = np.array([[1,0],[2,0],[3,0],[4,1],[5,1],[6,1],[7,1]])

#Adding a column of ones to our x matrix
ones = np.ones((len(data),1))
x = np.concatenate((ones, data[:,0].reshape(-1,1)), axis=1)

#Making our y vector
y = data[:,1].reshape(-1,1)

#choosing random Theta
theta = np.zeros((2,1))

#Sigmoid Function

def g(n):
return 1 / ((1 + (math.e**(-n))) + 0.000000001)
#Settings
m = 1/(len(x))
alpha = 2
iteration = 1000
while iteration > 0:
iteration -= 1
z = x @ theta
#cost function
h = g(z).reshape((-1,1))
part1 = -y.T @ np.log(h)
part2 = ((1 - y).T) @ (np.log(1-h))
j = m * (part1 - part2)
print(j)
#Gradient descent
inner = h - y
outer = x.T @ inner
dj = (alpha/m) * outer
theta = theta - dj
print(theta)






python python-3.x machine-learning






share|improve this question









New contributor




wassim khadim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




wassim khadim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited yesterday









Jamal

30.2k11115226




30.2k11115226






New contributor




wassim khadim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









wassim khadim

1




1




New contributor




wassim khadim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





wassim khadim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






wassim khadim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as unclear what you're asking by Graipher, Toby Speight, Sᴀᴍ Onᴇᴌᴀ, t3chb0t, Edward 5 hours ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






put on hold as unclear what you're asking by Graipher, Toby Speight, Sᴀᴍ Onᴇᴌᴀ, t3chb0t, Edward 5 hours ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 1




    Could you tell us something more about your code? It could be an interesting question but without any description it's likely to get closed.
    – t3chb0t
    11 hours ago
















  • 1




    Could you tell us something more about your code? It could be an interesting question but without any description it's likely to get closed.
    – t3chb0t
    11 hours ago










1




1




Could you tell us something more about your code? It could be an interesting question but without any description it's likely to get closed.
– t3chb0t
11 hours ago






Could you tell us something more about your code? It could be an interesting question but without any description it's likely to get closed.
– t3chb0t
11 hours ago

















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Список кардиналов, возведённых папой римским Каликстом III

Deduzione

Mysql.sock missing - “Can't connect to local MySQL server through socket”