How to Resolve This Valueerror: Only 2 Non-Keyword Arguments Accepted Sklearn Python

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)
4

2 Answers

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.

4

You are doing a linear regression code in ML and try to change this line with

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]
)
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest