-1

I try to test a first example using sklearn:

from sklearn.preprocessing import PolynomialFeatures
from sklearn import linear_model

X = [[0.44, 0.68], [0.99, 0.23]]
vector = [109.85, 155.72]
predict= [0.49, 0.18]

poly = PolynomialFeatures(degree=2)
X_ = poly.fit_transform(X)
predict_ = poly.fit_transform(predict)

clf = linear_model.LinearRegression()
clf.fit(X_, vector)
print clf.predict(predict_)   

But i have these errors:

/usr/lib/python2.7/dist-packages/scipy/sparse/csgraph/__init__.py:148:
 RuntimeWarning: numpy.dtype size changed, may indicate binary
 incompatibility
  from ._shortest_path import shortest_path, floyd_warshall, dijkstra,\
  /usr/lib/python2.7/dist-packages/scipy/sparse/csgraph/_validation.py:5:
  RuntimeWarning: numpy.dtype size changed, may indicate binary
  incompatibility
  File "hi.py", line 1, in <module>
  from sklearn.preprocessing import PolynomialFeatures
  ImportError: cannot import name PolynomialFeatures
   python -V --> 2.7.6 

Please, how can I deal with these errors? Bests.

ascripter
  • 5,665
  • 12
  • 45
  • 68
user1543915
  • 1,025
  • 1
  • 10
  • 16
  • The version of your scikit learn seems to be old. You can find your answer here: https://stackoverflow.com/questions/22914458/not-able-to-import-polynomialfeatures-make-pipeline-in-scikit-learn – Sheldore Aug 01 '18 at 12:01

1 Answers1

1

You can check your sklearn version, use:

import sklearn
print('Version {}.'.format(sklearn.__version__))

For me it shows:

Version 0.17.1.

Then check (from help of PolynomialFeatures) which version offers PolynomialFeatures and make an update. If your version is 0.14.1 or below, you will get this error. Check this page for more details on how to upgrade it: Not able to import PolynomialFeatures, make_pipeline in Scikit-learn (Official: http://scikit-learn.org/stable/install.html)

Sheldore
  • 37,862
  • 7
  • 57
  • 71
  • root@graphene-119:~# sudo python Python 2.7.6 (default, Nov 23 2017, 15:49:48) [GCC 4.8.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sklearn Traceback (most recent call last): File "", line 1, in ImportError: No module named sklearn >>> print('Version {}.'.format(sklearn.__version__)) Traceback (most recent call last): File "", line 1, in NameError: name 'sklearn' is not defined >>> – user1543915 Aug 01 '18 at 12:27
  • Ok, it seems you don't even have `sklearn` installed, hence the error `ImportError: No module named sklearn`. Just visit the **scikit-learn** website and read more on how to install it. – Sheldore Aug 01 '18 at 12:29
  • Both `sklearn` and `tensorflow` are different libraries. Installing one doesn't install the other by default. You will need to install both. By the way, I am still confused why you wrote in the first sentence of your question "using tensorflow:". You are not using `tensorflow` in your code at all. It's just all `sklearn`. – Sheldore Aug 01 '18 at 12:36
  • is there a polynomial regression with tensorflow ? – user1543915 Aug 01 '18 at 12:39
  • 1
    A simple Google search for keywords **polynomial regression with tensorflow** will give you answers to your questions. The answer to your question is "yes" btw. – Sheldore Aug 01 '18 at 12:40