Why I get the ValueErrorCorrelations - Get values in the way we wantHow to get the mu+0.1sigma from a normal distribution?XGBClassifier error! ValueError: feature_names mismatch:Given paper name get the abstractValueError when doing validation with random forestsWhy is the cost increasing in the linear regression method?Why is my U-matrix visually not separating the classes?VAR model ValueError: x already contains a constantValueError: Numpy arrays that you are passing to your model is not the size the model expectedwhy tsne plot can not show all the labels

Animal R'aim of the midrash

Recursively updating the MLE as new observations stream in

Do native speakers use "ultima" and "proxima" frequently in spoken English?

Print last inputted byte

How to test the sharpness of a knife?

What are the consequences of changing the number of hours in a day?

PTIJ: If Haman would have fallen with no one around to hear him fall, would that still have made a sound?

Placing object on uneven surface

Exit shell with shortcut (not typing exit) that closes session properly

Would mining huge amounts of resources on the Moon change its orbit?

Does the Shadow Magic sorcerer's Eyes of the Dark feature work on all Darkness spells or just his/her own?

How do you justify more code being written by following clean code practices?

Unfrosted light bulb

How to read string as hex number in bash?

Why does Surtur say that Thor is Asgard's doom?

Why doesn't the fusion process of the sun speed up?

Error in master's thesis, I do not know what to do

Why is "la Gestapo" feminine?

What is it called when someone votes for an option that's not their first choice?

Can other pieces capture a threatening piece and prevent a checkmate?

Why is the intercept typed in as a 1 in stats packages (R, python)

Determine voltage drop over 10G resistors with cheap multimeter

How to balance a monster modification (zombie)?

What happens when the centripetal force is equal and opposite to the centrifugal force?



Why I get the ValueError


Correlations - Get values in the way we wantHow to get the mu+0.1sigma from a normal distribution?XGBClassifier error! ValueError: feature_names mismatch:Given paper name get the abstractValueError when doing validation with random forestsWhy is the cost increasing in the linear regression method?Why is my U-matrix visually not separating the classes?VAR model ValueError: x already contains a constantValueError: Numpy arrays that you are passing to your model is not the size the model expectedwhy tsne plot can not show all the labels













0












$begingroup$


May I know why I get the error message -



line 49, in _update_weights



self.w_[1:]= self.eta*xi.dot(error)


Error:



ValueError: shapes (1,2) and (1,) not aligned: 2 (dim 1) != 1 (dim 0)


Code:



import numpy as np

class AdalineSGD (object):
def __init__(self, eta=0.01, n_iter=10, shuffle=True, random_state=None, batch=10):
self.batch=100/batch
self.eta=eta
self.n_iter=n_iter
self.w_initialized=False
self.shuffle=shuffle
self.random_state=random_state

def fit (self,X, y):
self._initialize_weights(X.shape[1])
self.cost_=[]
for i in range(self.n_iter):
if self.shuffle:
X, y=self._shuffle(X,y)
cost=[]
mini_X=np.array_split(X,self.batch)
mini_y=np.array_split(y,self.batch)
for xi, target in zip (mini_X, mini_y):
cost.append(self._update_weights(xi,target))
avg_cost=sum(cost)/len(y)
self.cost_.append(avg_cost)
return self
def partial_fit(self, X, y):
if not self.w_initialized:
self._inintialize_weights(X.shape[1])
if y.ravel().shape[0]>1:
for xi, target in zip (X, y):
self._update_weights(X,y)
else:
self._update_weights(X,y)
return self

def _shuffle(self, X,y):
r=self.rgen.permutation(len(y))
return X[r],y[r]

def _initialize_weights(self, m):
self.rgen=np.random.RandomState(self.random_state)
self.w_=self.rgen.normal(loc=0.0,scale=0.01,size=1+m)
self.w_initialized=True

def _update_weights(self,xi,target):
output = self.activation(self.net_input(xi))
error = (target - output)
self.w_[1:]= self.eta*xi.dot(error)
self.w_[0] = self.eta*error
cost = 0.5 * error**2
return cost

def net_input(self,X):
return np.dot(X,self.w_[1:])+self.w_[0]

def activation (self,X):
return X

def predict(self,X):
return np.where(self.activation(self.net_input(X))>=0.0,1,-1)

import pandas as pd
df=pd.read_csv('https://archive.ics.uci.edu/ml/''machine-learning-databases/iris/iris.data',header=None)
df.tail()
import matplotlib.pyplot as plt
y=df.iloc[0:100,4].values
y = np.where(y=='Iris-setosa',-1,1)
X=df.iloc[0:100,[0,2]].values
X_std=np.copy(X)
X_std[:,0]=(X[:,0]-X[:,0].mean())/X[:,0].std()
X_std[:,1]=(X[:,1]-X[:,1].mean())/X[:,1].std()

ada1=AdalineSGD(n_iter=15,eta=0.01, random_state=1, batch=1)
ada2=AdalineSGD(n_iter=15,eta=0.01, random_state=1, batch=2)
ada3=AdalineSGD(n_iter=15,eta=0.01, random_state=1, batch=10)
ada1.fit(X_std,y)
ada2.fit(X_std,y)
ada3.fit(X_std,y)

plt.plot(range(1,len(ada1.cost_)+1), ada1.cost_,marker='0',color='blue',label='batch=1')
plt.plot(range(1,len(ada2.cost_)+1), ada2.cost_,marker='0',color='orange',label='batch=2')
plt.plot(range(1,len(ada3.cost_)+1), ada3.cost_,marker='0',color='green',label='batch=10')

plt.title('Mini-batch learnign')
plt.legend(loc='upper right')
plt.xlabel('Epochs')
plt.ylabel('Avaerage Cost')
plt.show()**


Please see the link -
enter link description here










share|improve this question









New contributor




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







$endgroup$











  • $begingroup$
    Changing self.w_[1:]= self.eta*xi.dot(error) To self.w_[1:]= self.eta*error.dot(xi) works. But still next line self.w_[0] = self.eta*error Tries to put a 1x2 vector error inside a single variable self.w_[0]!
    $endgroup$
    – Esmailian
    2 days ago











  • $begingroup$
    What is a single variable I can put for - self.w_[0] = self.eta*error
    $endgroup$
    – vokoyo
    2 days ago
















0












$begingroup$


May I know why I get the error message -



line 49, in _update_weights



self.w_[1:]= self.eta*xi.dot(error)


Error:



ValueError: shapes (1,2) and (1,) not aligned: 2 (dim 1) != 1 (dim 0)


Code:



import numpy as np

class AdalineSGD (object):
def __init__(self, eta=0.01, n_iter=10, shuffle=True, random_state=None, batch=10):
self.batch=100/batch
self.eta=eta
self.n_iter=n_iter
self.w_initialized=False
self.shuffle=shuffle
self.random_state=random_state

def fit (self,X, y):
self._initialize_weights(X.shape[1])
self.cost_=[]
for i in range(self.n_iter):
if self.shuffle:
X, y=self._shuffle(X,y)
cost=[]
mini_X=np.array_split(X,self.batch)
mini_y=np.array_split(y,self.batch)
for xi, target in zip (mini_X, mini_y):
cost.append(self._update_weights(xi,target))
avg_cost=sum(cost)/len(y)
self.cost_.append(avg_cost)
return self
def partial_fit(self, X, y):
if not self.w_initialized:
self._inintialize_weights(X.shape[1])
if y.ravel().shape[0]>1:
for xi, target in zip (X, y):
self._update_weights(X,y)
else:
self._update_weights(X,y)
return self

def _shuffle(self, X,y):
r=self.rgen.permutation(len(y))
return X[r],y[r]

def _initialize_weights(self, m):
self.rgen=np.random.RandomState(self.random_state)
self.w_=self.rgen.normal(loc=0.0,scale=0.01,size=1+m)
self.w_initialized=True

def _update_weights(self,xi,target):
output = self.activation(self.net_input(xi))
error = (target - output)
self.w_[1:]= self.eta*xi.dot(error)
self.w_[0] = self.eta*error
cost = 0.5 * error**2
return cost

def net_input(self,X):
return np.dot(X,self.w_[1:])+self.w_[0]

def activation (self,X):
return X

def predict(self,X):
return np.where(self.activation(self.net_input(X))>=0.0,1,-1)

import pandas as pd
df=pd.read_csv('https://archive.ics.uci.edu/ml/''machine-learning-databases/iris/iris.data',header=None)
df.tail()
import matplotlib.pyplot as plt
y=df.iloc[0:100,4].values
y = np.where(y=='Iris-setosa',-1,1)
X=df.iloc[0:100,[0,2]].values
X_std=np.copy(X)
X_std[:,0]=(X[:,0]-X[:,0].mean())/X[:,0].std()
X_std[:,1]=(X[:,1]-X[:,1].mean())/X[:,1].std()

ada1=AdalineSGD(n_iter=15,eta=0.01, random_state=1, batch=1)
ada2=AdalineSGD(n_iter=15,eta=0.01, random_state=1, batch=2)
ada3=AdalineSGD(n_iter=15,eta=0.01, random_state=1, batch=10)
ada1.fit(X_std,y)
ada2.fit(X_std,y)
ada3.fit(X_std,y)

plt.plot(range(1,len(ada1.cost_)+1), ada1.cost_,marker='0',color='blue',label='batch=1')
plt.plot(range(1,len(ada2.cost_)+1), ada2.cost_,marker='0',color='orange',label='batch=2')
plt.plot(range(1,len(ada3.cost_)+1), ada3.cost_,marker='0',color='green',label='batch=10')

plt.title('Mini-batch learnign')
plt.legend(loc='upper right')
plt.xlabel('Epochs')
plt.ylabel('Avaerage Cost')
plt.show()**


Please see the link -
enter link description here










share|improve this question









New contributor




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







$endgroup$











  • $begingroup$
    Changing self.w_[1:]= self.eta*xi.dot(error) To self.w_[1:]= self.eta*error.dot(xi) works. But still next line self.w_[0] = self.eta*error Tries to put a 1x2 vector error inside a single variable self.w_[0]!
    $endgroup$
    – Esmailian
    2 days ago











  • $begingroup$
    What is a single variable I can put for - self.w_[0] = self.eta*error
    $endgroup$
    – vokoyo
    2 days ago














0












0








0





$begingroup$


May I know why I get the error message -



line 49, in _update_weights



self.w_[1:]= self.eta*xi.dot(error)


Error:



ValueError: shapes (1,2) and (1,) not aligned: 2 (dim 1) != 1 (dim 0)


Code:



import numpy as np

class AdalineSGD (object):
def __init__(self, eta=0.01, n_iter=10, shuffle=True, random_state=None, batch=10):
self.batch=100/batch
self.eta=eta
self.n_iter=n_iter
self.w_initialized=False
self.shuffle=shuffle
self.random_state=random_state

def fit (self,X, y):
self._initialize_weights(X.shape[1])
self.cost_=[]
for i in range(self.n_iter):
if self.shuffle:
X, y=self._shuffle(X,y)
cost=[]
mini_X=np.array_split(X,self.batch)
mini_y=np.array_split(y,self.batch)
for xi, target in zip (mini_X, mini_y):
cost.append(self._update_weights(xi,target))
avg_cost=sum(cost)/len(y)
self.cost_.append(avg_cost)
return self
def partial_fit(self, X, y):
if not self.w_initialized:
self._inintialize_weights(X.shape[1])
if y.ravel().shape[0]>1:
for xi, target in zip (X, y):
self._update_weights(X,y)
else:
self._update_weights(X,y)
return self

def _shuffle(self, X,y):
r=self.rgen.permutation(len(y))
return X[r],y[r]

def _initialize_weights(self, m):
self.rgen=np.random.RandomState(self.random_state)
self.w_=self.rgen.normal(loc=0.0,scale=0.01,size=1+m)
self.w_initialized=True

def _update_weights(self,xi,target):
output = self.activation(self.net_input(xi))
error = (target - output)
self.w_[1:]= self.eta*xi.dot(error)
self.w_[0] = self.eta*error
cost = 0.5 * error**2
return cost

def net_input(self,X):
return np.dot(X,self.w_[1:])+self.w_[0]

def activation (self,X):
return X

def predict(self,X):
return np.where(self.activation(self.net_input(X))>=0.0,1,-1)

import pandas as pd
df=pd.read_csv('https://archive.ics.uci.edu/ml/''machine-learning-databases/iris/iris.data',header=None)
df.tail()
import matplotlib.pyplot as plt
y=df.iloc[0:100,4].values
y = np.where(y=='Iris-setosa',-1,1)
X=df.iloc[0:100,[0,2]].values
X_std=np.copy(X)
X_std[:,0]=(X[:,0]-X[:,0].mean())/X[:,0].std()
X_std[:,1]=(X[:,1]-X[:,1].mean())/X[:,1].std()

ada1=AdalineSGD(n_iter=15,eta=0.01, random_state=1, batch=1)
ada2=AdalineSGD(n_iter=15,eta=0.01, random_state=1, batch=2)
ada3=AdalineSGD(n_iter=15,eta=0.01, random_state=1, batch=10)
ada1.fit(X_std,y)
ada2.fit(X_std,y)
ada3.fit(X_std,y)

plt.plot(range(1,len(ada1.cost_)+1), ada1.cost_,marker='0',color='blue',label='batch=1')
plt.plot(range(1,len(ada2.cost_)+1), ada2.cost_,marker='0',color='orange',label='batch=2')
plt.plot(range(1,len(ada3.cost_)+1), ada3.cost_,marker='0',color='green',label='batch=10')

plt.title('Mini-batch learnign')
plt.legend(loc='upper right')
plt.xlabel('Epochs')
plt.ylabel('Avaerage Cost')
plt.show()**


Please see the link -
enter link description here










share|improve this question









New contributor




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







$endgroup$




May I know why I get the error message -



line 49, in _update_weights



self.w_[1:]= self.eta*xi.dot(error)


Error:



ValueError: shapes (1,2) and (1,) not aligned: 2 (dim 1) != 1 (dim 0)


Code:



import numpy as np

class AdalineSGD (object):
def __init__(self, eta=0.01, n_iter=10, shuffle=True, random_state=None, batch=10):
self.batch=100/batch
self.eta=eta
self.n_iter=n_iter
self.w_initialized=False
self.shuffle=shuffle
self.random_state=random_state

def fit (self,X, y):
self._initialize_weights(X.shape[1])
self.cost_=[]
for i in range(self.n_iter):
if self.shuffle:
X, y=self._shuffle(X,y)
cost=[]
mini_X=np.array_split(X,self.batch)
mini_y=np.array_split(y,self.batch)
for xi, target in zip (mini_X, mini_y):
cost.append(self._update_weights(xi,target))
avg_cost=sum(cost)/len(y)
self.cost_.append(avg_cost)
return self
def partial_fit(self, X, y):
if not self.w_initialized:
self._inintialize_weights(X.shape[1])
if y.ravel().shape[0]>1:
for xi, target in zip (X, y):
self._update_weights(X,y)
else:
self._update_weights(X,y)
return self

def _shuffle(self, X,y):
r=self.rgen.permutation(len(y))
return X[r],y[r]

def _initialize_weights(self, m):
self.rgen=np.random.RandomState(self.random_state)
self.w_=self.rgen.normal(loc=0.0,scale=0.01,size=1+m)
self.w_initialized=True

def _update_weights(self,xi,target):
output = self.activation(self.net_input(xi))
error = (target - output)
self.w_[1:]= self.eta*xi.dot(error)
self.w_[0] = self.eta*error
cost = 0.5 * error**2
return cost

def net_input(self,X):
return np.dot(X,self.w_[1:])+self.w_[0]

def activation (self,X):
return X

def predict(self,X):
return np.where(self.activation(self.net_input(X))>=0.0,1,-1)

import pandas as pd
df=pd.read_csv('https://archive.ics.uci.edu/ml/''machine-learning-databases/iris/iris.data',header=None)
df.tail()
import matplotlib.pyplot as plt
y=df.iloc[0:100,4].values
y = np.where(y=='Iris-setosa',-1,1)
X=df.iloc[0:100,[0,2]].values
X_std=np.copy(X)
X_std[:,0]=(X[:,0]-X[:,0].mean())/X[:,0].std()
X_std[:,1]=(X[:,1]-X[:,1].mean())/X[:,1].std()

ada1=AdalineSGD(n_iter=15,eta=0.01, random_state=1, batch=1)
ada2=AdalineSGD(n_iter=15,eta=0.01, random_state=1, batch=2)
ada3=AdalineSGD(n_iter=15,eta=0.01, random_state=1, batch=10)
ada1.fit(X_std,y)
ada2.fit(X_std,y)
ada3.fit(X_std,y)

plt.plot(range(1,len(ada1.cost_)+1), ada1.cost_,marker='0',color='blue',label='batch=1')
plt.plot(range(1,len(ada2.cost_)+1), ada2.cost_,marker='0',color='orange',label='batch=2')
plt.plot(range(1,len(ada3.cost_)+1), ada3.cost_,marker='0',color='green',label='batch=10')

plt.title('Mini-batch learnign')
plt.legend(loc='upper right')
plt.xlabel('Epochs')
plt.ylabel('Avaerage Cost')
plt.show()**


Please see the link -
enter link description here







python






share|improve this question









New contributor




vokoyo 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




vokoyo 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 2 days ago









ebrahimi

74621021




74621021






New contributor




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









asked 2 days ago









vokoyovokoyo

43




43




New contributor




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





New contributor





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






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











  • $begingroup$
    Changing self.w_[1:]= self.eta*xi.dot(error) To self.w_[1:]= self.eta*error.dot(xi) works. But still next line self.w_[0] = self.eta*error Tries to put a 1x2 vector error inside a single variable self.w_[0]!
    $endgroup$
    – Esmailian
    2 days ago











  • $begingroup$
    What is a single variable I can put for - self.w_[0] = self.eta*error
    $endgroup$
    – vokoyo
    2 days ago

















  • $begingroup$
    Changing self.w_[1:]= self.eta*xi.dot(error) To self.w_[1:]= self.eta*error.dot(xi) works. But still next line self.w_[0] = self.eta*error Tries to put a 1x2 vector error inside a single variable self.w_[0]!
    $endgroup$
    – Esmailian
    2 days ago











  • $begingroup$
    What is a single variable I can put for - self.w_[0] = self.eta*error
    $endgroup$
    – vokoyo
    2 days ago
















$begingroup$
Changing self.w_[1:]= self.eta*xi.dot(error) To self.w_[1:]= self.eta*error.dot(xi) works. But still next line self.w_[0] = self.eta*error Tries to put a 1x2 vector error inside a single variable self.w_[0]!
$endgroup$
– Esmailian
2 days ago





$begingroup$
Changing self.w_[1:]= self.eta*xi.dot(error) To self.w_[1:]= self.eta*error.dot(xi) works. But still next line self.w_[0] = self.eta*error Tries to put a 1x2 vector error inside a single variable self.w_[0]!
$endgroup$
– Esmailian
2 days ago













$begingroup$
What is a single variable I can put for - self.w_[0] = self.eta*error
$endgroup$
– vokoyo
2 days ago





$begingroup$
What is a single variable I can put for - self.w_[0] = self.eta*error
$endgroup$
– vokoyo
2 days ago











0






active

oldest

votes











Your Answer





StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "557"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






vokoyo is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f47431%2fwhy-i-get-the-valueerror%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes








vokoyo is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















vokoyo is a new contributor. Be nice, and check out our Code of Conduct.












vokoyo is a new contributor. Be nice, and check out our Code of Conduct.











vokoyo is a new contributor. Be nice, and check out our Code of Conduct.














Thanks for contributing an answer to Data Science Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f47431%2fwhy-i-get-the-valueerror%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Adding axes to figuresAdding axes labels to LaTeX figuresLaTeX equivalent of ConTeXt buffersRotate a node but not its content: the case of the ellipse decorationHow to define the default vertical distance between nodes?TikZ scaling graphic and adjust node position and keep font sizeNumerical conditional within tikz keys?adding axes to shapesAlign axes across subfiguresAdding figures with a certain orderLine up nested tikz enviroments or how to get rid of themAdding axes labels to LaTeX figures

Luettelo Yhdysvaltain laivaston lentotukialuksista Lähteet | Navigointivalikko

Gary (muusikko) Sisällysluettelo Historia | Rockin' High | Lähteet | Aiheesta muualla | NavigointivalikkoInfobox OKTuomas "Gary" Keskinen Ancaran kitaristiksiProjekti Rockin' High