how to resolve this ValueError: only 2 non-keyword arguments accepted sklearn python

dondeveto picture dondeveto · Jan 19, 2018 · Viewed 39.1k times · Source

hello i am new to sklearn in python and iam trying to learn it and use this module to predict some numbers based on two features here is the error i am getting:

ValueError: only 2 non-keyword arguments accepted

and here is my code:

    from sklearn.linear_model import LinearRegression
    import numpy as np

    trainingData = np.array([[861, 16012018], [860, 12012018], [859, 9012018], [858, 5012018], [857, 2012018], [856, 29122017], [855, 26122017], [854, 22122017], [853, 19122017]])
    trainingScores = np.array([11,18,23,33,34,6],[10,19,21,33,34,1], [14,18,22,23,31,6],[16,22,29,31,33,10],[21,24,27,30,31,6],[1,14,15,20,27,7],[1,9,10,11,15,8],[2,9,27,31,35,1],[7,13,18,22,33,2])

    clf = LinearRegression(fit_intercept=True)
    clf.fit(trainingScores,trainingData)

   predictionData = np.array([862, 19012018 ])
   x=clf.predict(predictionData)
   print(x)

Answer

Vivek Kumar picture Vivek Kumar · Jan 19, 2018

I am not sure what you are trying to do here, but change this line:

trainingScores = np.array([11,18,23,33,34,6],[10,19,21,33,34,1], [14,18,22,23,31,6],[16,22,29,31,33,10],[21,24,27,30,31,6],[1,14,15,20,27,7],[1,9,10,11,15,8],[2,9,27,31,35,1],[7,13,18,22,33,2])

to this (Notice the extra square brackets around your data):

trainingScores = np.array([[11,18,23,33,34,6],[10,19,21,33,34,1], [14,18,22,23,31,6],[16,22,29,31,33,10],[21,24,27,30,31,6],[1,14,15,20,27,7],[1,9,10,11,15,8],[2,9,27,31,35,1],[7,13,18,22,33,2]])

Then change the order of params in fit() like this:

clf.fit(trainingData,trainingScores)

And finally change prediction data like this (again look at the extra square brackets):

predictionData = np.array([[862, 19012018]])

After that your code will run.