0

When running:

scaler = StandardScaler().fit(train)

I am getting this error:

enter image description here

After that I tried:

train = train.array.reshape(-1, 1)

And I got:

AttributeError: 'list' object has no attribute 'array'

How can I reshape by data to fix the value error?

jkdev
  • 11,360
  • 15
  • 54
  • 77
Mr.X
  • 11
  • 3

1 Answers1

0

Try train = np.array(train).reshape(-1, 1).

It appears train is originally a list. So you must convert it into an array using np.array(). Then, you can use the .reshape() method to change the dimensions. .reshape(-1, 1) asks numpy to create a 2-dimensional matrix with a single column. numpy can infer the number of rows in this matrix since you only want one column. the -1 parameter asks numpy to infer the length of the first dimension. Please see this answer for a more complete understanding.

skurp
  • 389
  • 3
  • 13
  • the commands runs. However, I am still getting the error when I run `scaler = StandardScaler().fit(train)` – Mr.X Jul 24 '19 at 00:21
  • what about train = np.array(train).reshape(-1,2) -> this makes it a 2d array – Derek Eden Jul 24 '19 at 01:52
  • 1
    I think this does provide an answer to the question. – jkdev Jul 24 '19 at 06:02
  • This answer has been flagged as potentially low-quality. Please elaborate on your answer so that new and future developers understand how your answer solves the OP's question. – App Dev Guy Jul 24 '19 at 07:08
  • I tried`train = np.array(train).reshape(-1,1)` and now when I run`scaler = StandardScaler().fit(train)`, I get **DataConversionWarning: Data with input dtype – Mr.X Jul 24 '19 at 13:27
  • This means that you have integers in your array but `StandardScaler()` requires floats to perform the computation. This should not affect your output but you should clarify for your self the difference between ints and floats in python numerical representation. – skurp Jul 24 '19 at 18:14