Spyder Python “object arrays are currently not supported”

匿名 (未验证) 提交于 2019-12-03 01:49:02

问题:

I have a problem in Anaconda Spyder (Python).

Object type array can not be seen under Windows 10 in the variable explorer. If I click on X or Y, I see an error:

object arrays are currently not supported.

I have Win 10 Home 64bit (i7-4710HQ) and Python 3.5.2 | Anaconda 4.2.0 (64-bit) [MSC v.1900 64 bit (AMD64)]

Screenshot

回答1:

A good example is here

import numpy as np import pandas as pd import matplotlib.pyplot as plt dataset = pd.read_csv('Salary_Data.csv') in your case right name of your file X=dataset.iloc[:,:-1].values   this will convert dataframe to object df = pd.DataFrame(X) 

You can view data in dataframe this converts arrray to dataframe .

And the variable explorer accepts the dataframe. The above is correct and checked code



回答2:

I have analyzed the code until the point that could be failing for you.

It seems that array editor of Spyder doesn't support showing arrays of mixed types (object arrays).

Here you can see the supported formats.

Something was confusing for me the first time that I used it. It was the fact that one thing that you receive the same editor when you click on a Dataset that when you click on an array variable.

In the case of a variable of type array, you receive an ArrayEditor widget. I think that call is made here.

But in the case of a variable of type DataFrame, you receive a DataFrameEditor. I think that call is made here

The problem is that both widgets look more or less the same, so one tend to think that receive the same result in both cases, but the DataFrameEditor allows mixed types and the ArrayEditor not.

I went to the course that you have taken. You can see in the lecture "Importing the Dataset" (Section 2, Lecture 9) (5m:11s) that the instructor takes care of inspecting the array variables in the IPython console although he shows you the Dataframe to compare. Maybe that confuses you when you have advanced more lessions, because once you have all the code together and run it all then the the array variables have been modified by the Imputer and they have a type. In that moment you can click in all of them and you get an editor, and maybe that is what your colleges make because they might have all the code of the lesson.



回答3:

(Spyder developer here) Support for object arrays will be added in Spyder 4, to be released during the summer of 2018.



回答4:

This is because the array has more than one data-type so it can't show an object with more than one datatype because it can't select a single type.. But if it has only one datatype the type is 'float64' so it can be seen.



回答5:

As long as your variables type are not same and in variable explorer you see this as object, it means variable needs to be converted to same type in your case. You can fix it by using fit_transform():

Here is related part of the code for in that tutorial:

from sklearn.preprocessing import LabelEncoder , OneHotEncoder labelencoder_X_1 = LabelEncoder() X[:, 1] = labelencoder_X_1.fit_transform(X[:, 1]) labelencoder_X_2 = LabelEncoder() X[:, 2] = labelencoder_X_1.fit_transform(X[:, 2]) onehotencoder = OneHotEncoder(categorical_features = [1]) X = onehotencoder.fit_transform(X).toarray() 


回答6:

I am registered in the same Machine Learning Course as you are and have the same problem.

In order to allow me to move forward in the course and stay FOCUSED ON THE COURSE MATERIAL AS PRESENTED, there are two things you can do to bypass the variable viewer in Spyder. You can either

A) use "print (X)" to reveal the contents of X, or B) Simple use the IPython console by simply typing X and hit return. That too allow you to quickly reveal if the discussed ML functions are doing their job.



回答7:

Solution: Downgrade the version of spyder to 3.2.0

You can do this by going to anaconda-navigator.

If you are following the Udemy Course on Machine Learning, probably the instructor is using an older version of spyder and it is working for him. In the newer versions like 3.2.8, it is not working but can be incorporated in the coming versions in the future.



回答8:

This is because the data are not encoded. All the categorical data should be "encoded". After looking at the data in variable explorer of your sypder(https://i.stack.imgur.com/uApwt.jpg), it is clear that X contains data about some country (like [France, 44.0, 72000]), so the name of the country should be encoded and similarly y contains "Yes" or "No", so it should also be encoded

Add the following code after line 21, you will be able to see the object array

# Encoding categorical data  from sklearn.preprocessing import LabelEncoder, OneHotEncoder  ''' To prevent the machine learning equations from thinking  (if there are more than one country) that one country is greater than  another, use the concept of dummy variables     '''  labelencoder_X = LabelEncoder() X[:, 0] = labelencoder_X.fit_transform(X[:, 0]) onehotencoder = OneHotEncoder(categorical_features = [0]) X = onehotencoder.fit_transform(X).toarray()  ''' Since y is dependent variable, the machine learning model will know  that its a category, so we are going to use only the LableEncoder() ''' labelencoder_y = LabelEncoder() y = labelencoder_y.fit_transform(y) 


回答9:

I had the same problem. Issue was the line

oneHotEncoder.fit_transform(X).toarray() 

Which does not assign the data back to the X array. Instead, the following line should fix the issue:

X=oneHotEncoder.fit_transform(X).toarray() 


回答10:

With the updated version of spyder you cannot see mixed arrays anymore using variable explorer. You can print the array instead in the console to inspect it.



回答11:

I had a similar problem, because I insisted on using the exact format for the y variable as for x, i.e. x[: , 0] = labelencoder_x.fit_transform(x[:,0]), and I used y[:] = labelencoder_y.fit_transform(y[:]) *(taking into account the syntax for the fit transform for y)*

The above made the dtype for y_test and y_train "object" which can't be viewed on Spyder in the variable explorer.

When I used the exact line used by the instructor: y = labelencoder_y.fit_transform(y). The dtype changed to int64 which can be viewed in the variable explorer.



回答12:

This worked for me :

import pandas as pd labels = pd.read_csv('labels/labels.csv') # object arrays are currently not supported exception breeds = labels.breed.unique() # Supported Version  # working fine breeds = pd.DataFrame(labels.breed.unique()) 


回答13:

It is yet not supported by Spyder but you can use IPyhon Console to print those values by directly typing variable name to it.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!