amueller/introduction_to_ml_with_python

Problem with invoking mglearn

YellO-Cat opened this issue · 3 comments

I am a novice, and I apologize for my ignorance.

I have an Anaconda install (1.9.7), and I am working page-by-page through your book. My problem is invoking mglearn, for example in the first instance of the Iris application (In[23], cmap=mglearn.cm3)). I tried using the pip command (pip install mglearn), but received an error message and a timeout. (Sry, I did not record the message, and it isn't replicating right now). I have downloaded the mglearn files from your hub, but I am unsure how to proceed. Is there a straight-forward way to install them, or insert the correct code, from my desktop?

I don't mean to waste your time, and I am sorry for my ignorance.

Hi. Can you try pip install mglearn again? If it isn't replicating, that means it's working, right?

Thank you for replying to me!

Windows 10 OS. I just used cmd and it does not recognize pip now. I probably need to be in a specific directory to invoke it, but I am too ignorant to know. I have your mglearn folder copied into my Anaconda 3 scripts folder.

My code from the Iris example:


from sklearn.datasets import load_iris
iris_dataset = load_iris()

print("Keys of iris_dataset:/n", iris_dataset.keys())

print(iris_dataset['DESCR'][:193] + "\n...")

print("Target names:", iris_dataset['target_names'])

print("feature names:\n", iris_dataset['feature_names'])

print("type of data:", type(iris_dataset['data']))

print("shape of data:", iris_dataset['data'].shape)

print("Target:\n", iris_dataset['target'])

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(
iris_dataset['data'], iris_dataset['target'], random_state=0)

print("X_train shape:", X_train.shape)
print("y_train shape:", y_train.shape)

print("X_test shape:", X_test.shape)
print("y_test shape:", y_test.shape)

iris_dateframe = pd.DataFrame(X_train, columns=iris_dataset.feature_names)

pd.plotting.scatter_matrix(iris_dataframe, c=y_train, figsize=(15, 15),
marker='0', hist_kwds={'bins': 20}, s=60, alpha=.8, cmap=mglearn.cm3)


The error message I get:

File "C:/Users/peter/.spyder-py3/IRIS.py", line 35, in
iris_dateframe = pd.DataFrame(X_train, columns=iris_dataset.feature_names)

NameError: name 'pd' is not defined


Perhaps this is progress, but I am unsure. I really don't want to waste any of your time at all, but if you think there is something simple that I just do not see, a heads up would be welcome.

Thank you again!

I invoked the CMD from inside Anaconda and success! :)

Capture mglearn

I still get this error:

Capture Error

from this code:

Capture code

But, that is likely because of my inexperience.

Thank you for taking the time to respond to my questions, and for helping me! :)