Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8782915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:41:27+00:00 2026-06-13T20:41:27+00:00

I calculated a model using OLS (multiple linear regression). I divided my data to

  • 0

I calculated a model using OLS (multiple linear regression). I divided my data to train and test (half each), and then I would like to predict values for the 2nd half of the labels.

model = OLS(labels[:half], data[:half])
predictions = model.predict(data[half:])

The problem is that I get and error:
File “/usr/local/lib/python2.7/dist-packages/statsmodels-0.5.0-py2.7-linux-i686.egg/statsmodels/regression/linear_model.py”, line 281, in predict
return np.dot(exog, params)
ValueError: matrices are not aligned

I have the following array shapes:
data.shape: (426, 215)
labels.shape: (426,)

If I transpose the input to model.predict, I do get a result but with a shape of (426,213), so I suppose its wrong as well (I expect one vector of 213 numbers as label predictions):

model.predict(data[half:].T)

Any idea how to get it to work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:41:29+00:00Added an answer on June 13, 2026 at 8:41 pm

    For statsmodels >=0.4, if I remember correctly

    model.predict doesn’t know about the parameters, and requires them in the call
    see http://statsmodels.sourceforge.net/stable/generated/statsmodels.regression.linear_model.OLS.predict.html

    What should work in your case is to fit the model and then use the predict method of the results instance.

    model = OLS(labels[:half], data[:half])
    results = model.fit()
    predictions = results.predict(data[half:])
    

    or shorter

    results = OLS(labels[:half], data[:half]).fit()
    predictions = results.predict(data[half:])
    

    http://statsmodels.sourceforge.net/stable/generated/statsmodels.regression.linear_model.RegressionResults.predict.html with missing docstring

    Note: this has been changed in the development version (backwards compatible), that can take advantage of “formula” information in predict
    http://statsmodels.sourceforge.net/devel/generated/statsmodels.regression.linear_model.RegressionResults.predict.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm setting up a data model in django using multiple-table inheritance (MTI) like this:
I have a model where geocodes are calculated before the model is saved using
I'm using LINQ on a Telerik OpenAccess generated data model, to setup a search
I'm generating invoice PDFs on the fly, and using my model to calculate the
I want to have a model with calculated fields that I can apply sorting
I'm working with EF5 using the model-first approach. I've designed the model and executed
My model has a def on it which returns a calculated field. In my
My code below for replication purposes. I've created a two parameter model using the
I am using JPQL for the model queries from Play Framework. I wonder if
I have been trying to implement a factorial function using the actor model with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.