Trading with Machine Learning: Regression

Section 4 Unit 18

InvalidParameterError                     Traceback (most recent call last)
Cell In[20], line 2
      1 # Fit the model to predict 'Upwards' movement
----> 2 reg.fit(X_train, yU_train)
      4 # Predict the upward deviation
      5 yU_predict = reg.predict(X_test)
InvalidParameterError: The 'fit_intercept' parameter of LinearRegression must be an instance of 'bool' or an instance of 'numpy.bool_'. Got {'linear__fit_intercept': True} instead.

Checked following …

Code did not specify value (,) for LinearRegression(,fit_intercept = best_fit)

class 
sklearn.linear_model.LinearRegression(*fit_intercept=Truecopy_X=Truen_jobs=Nonepositive=False)

Hi Anil,



The error states that:

InvalidParameterError: The 'fit_intercept' parameter of LinearRegression must be an instance of 'bool' or an instance of 'numpy.bool_'. Got {'linear__fit_intercept': True} instead.
So basically, the parameter expected the input to be an instance of "bool", but it got {'linear__fit_intercept': True}, which is basically a dictionary. What we need to do here is pass the value of the key: "linear__fit_intercept" as the parameter, and that would solve the issue. (Hint: In the key-value pair {'linear__fit_intercept': True}, the value is True. You need to access this value programmatically and pass it as the parameter).

Hope this helps!

Hi Akshay

I am new to Python and find it hard to pinpoint the issue as well as write a new code.

In this case somehow I was able to trace the problem, but could not code as how to access value programmatically.

I request to help me on programming for some time until I pick it up. I have been working on MQL5 for long time, and adding Python to my skills will take some time to learn.

Hello Anil,



It is natural to face issues when you are learning a new language. The Quantra courses are primarily language-agnostic where the concepts explained can be implemented in any language. However, backtesting any strategy is demonstrated in Python as it is relatively easier to understand and implement among other programming languages. You can always ask your queries here if there is any issue and we will give our best effort in solving any python related issue. In the meantime, you can always go through the Python for trading: basic course as well as the Python handbook which has benefitted a lot of users…



Thanks.