Python Forum
Possible Scikit-Learn Import Issue?
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Possible Scikit-Learn Import Issue?
#1
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
Reply
#2
Thanks for taking the time to update your thread.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#3
Quote:
ImportError: No module named model_selection
 
see: https://github.com/alvarouc/mlp/issues/4
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  scikit-tensor package Lamine 1 2,529 Feb-27-2022, 01:16 PM
Last Post: jefsummers
  SciKit vs Dynamo vs Grasshopper/Dodo for A.I. Planner Project Julian 1 2,862 Jun-10-2019, 02:41 AM
Last Post: Larz60+
  Cannot run scikit-image in Python 3.6 newmanf 6 9,636 Feb-22-2018, 05:30 AM
Last Post: AjManoj
  csv import issue by newbee giladbi 0 2,071 Dec-12-2017, 08:21 PM
Last Post: giladbi

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020