0
$\begingroup$

In my university I got an assignment: I need to predict the stock price using two of machine learning methods with imported data. (I've chosen Linear regression and Decision tree).
I tried to make a program myself but encountered errors and since I'm a rookie in machine learning I don't quite understand what I'm doing wrong.
I added a screenshot how the data in imported file looks like just in case.
So here's my code:
a = Rest[Import["Test.xlsx", {"Data"}][[1]]][[;; - 2, {2, 3, 4, 5, 6, 7}]];
b = Rest[Import["Test.xlsx", {"Data"}][[1]]][[;; - 2, {8}]];
trainingset = {a -> b};
prediction1 = Predict[trainingset, Method -> "LinearRegression"];
prediction2 = Predict[trainingset, Method -> "DecisionTree"];
At lines where I use Predict[] I got this error:
"Predict: Incompatible variable type (Numerical) and variable value ({{243.73},{242.65},{240.82},{240.87},{239.1},{236.1},{234.5},{238.18},{237.6},{238.91},<<991>>})."
So can someone explain me what's going on here?
UPD: Solved.

enter image description here

$\endgroup$
6
  • $\begingroup$ Maybe pasting your data into pastebin or some other service would allow us to help you quickly. Welcome to stackxc ;) $\endgroup$ Commented Apr 26, 2021 at 22:48
  • 1
    $\begingroup$ The problem is your input to Predict is like {x},{x},{x},. and trainingset = {a -> b} is wrong too - it should be of the form {a[[1]]->b[[1]], a[[2]]->b[[2]], ...} by doing Thread[a->b] $\endgroup$
    – flinty
    Commented Apr 26, 2021 at 23:35
  • $\begingroup$ @flinty I get what you mean but it's not working:( If use Thread[a->b] then my training set example will be like {x1, x2, x3, x4, x5, x6} -> {y}. So y is a vector but it supposed to be a scalar. Now I have this error: "Incompatible variable type ("Numerical") and variable value". $\endgroup$
    – Yamobura
    Commented Apr 27, 2021 at 0:15
  • 1
    $\begingroup$ How does an instructor expect you to "...predict the stock price..." from fat tailed deeply random data, which has no standard deviation? Have they supplied you with fabricated data rather than, you know, actual data? This seems on the face, a misuse of or perhaps more politely, not a use case for machine learning. One might predict that an increased level of volatility will, eventually, result in yet higher volatility, but that tells one nothing about "stock price". Could you post the entire assignment? I think it would prove useful to better understand the instructor's intentions. $\endgroup$
    – Jagra
    Commented Apr 27, 2021 at 0:37
  • $\begingroup$ @Jagra oh, yes, it's just fabricated data, like, itself it doesn't really matter. Sorry for the misconception. I have another student in my study group who's working with this data but using neural network. So our assignment is to compare the results of predictions that we got with help of neural network and machine learning methods (in my case). $\endgroup$
    – Yamobura
    Commented Apr 27, 2021 at 2:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.