Python Forum

Full Version: Possible Scikit-Learn Import Issue?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I keep getting an error when I run this code. I'm thinking it may be because my packages (scikit-learn) are not current enough. I hope this isn't the case, because I've tried everything to update them, and can't.

import numpy
import pandas
from keras.models import Sequential
from keras.layers import Dense
from keras.wrappers.scikit_learn import KerasRegressor
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import KFold
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline

# load dataset
dataframe = pandas.read_csv("housing.csv", delim_whitespace=True, header=None)
dataset = dataframe.values
# split into input (X) and output (Y) variables
X = dataset[:,0:13]
Y = dataset[:,13]

# define base model
def baseline_model():
	# create model
	model = Sequential()
	model.add(Dense(13, input_dim=13, kernel_initializer='normal', activation='relu'))
	model.add(Dense(1, kernel_initializer='normal'))
	# Compile model
	model.compile(loss='mean_squared_error', optimizer='adam')
	return model

# fix random seed for reproducibility
seed = 7
numpy.random.seed(seed)

# evaluate model with standardized dataset
numpy.random.seed(seed)
estimators = []
estimators.append(('standardize', StandardScaler()))
estimators.append(('mlp', KerasRegressor(build_fn=baseline_model, epochs=50, batch_size=5, verbose=0)))
pipeline = Pipeline(estimators)
kfold = KFold(n_splits=10, random_state=seed)
results = cross_val_score(pipeline, X, Y, cv=kfold)
print("Standardized: %.2f (%.2f) MSE" % (results.mean(), results.std()))
Here is the error message:

/usr/bin/python2.7 /home/b/pycharm-community-2017.2.3/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 34137 --file /home/b/PycharmProjects/ANN1a/ANN2-Keras1a
Connected to pydev debugger (build 172.3968.37)
pydev debugger: process 13628 is connecting

Using TensorFlow backend.
Traceback (most recent call last):
  File "/home/b/pycharm-community-2017.2.3/helpers/pydev/pydevd.py", line 1599, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/home/b/pycharm-community-2017.2.3/helpers/pydev/pydevd.py", line 1026, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/home/b/PycharmProjects/ANN1a/ANN2-Keras1a", line 6, in <module>
    from sklearn.model_selection import cross_val_score
ImportError: No module named model_selection
Backend TkAgg is interactive backend. Turning interactive mode on.

Sorry guys... I figured it out. It was that my Scikit-learn was not the current version.

I ran this command in my terminal and got it to update:

sudo pip install --update scikit-learn
Thanks for taking the time to update your thread.
Quote:
ImportError: No module named model_selection
 
see: https://github.com/alvarouc/mlp/issues/4